So after getting the cache file in place with my automated test, I will invoke the optimize command. You can do this yourself by clicking File | Options | Save and Backup | Optimize All Files Now.
This will cause OneNote to examine the cache to see if it can be shrunk and do so. It also optimizes each section file you have to ensure they are compacted. This code also runs when OneNote goes idle, and you can see the settings you can tweak here if you want it to run more often. I don’t want to put the machine to sleep for 20 minutes since that holds the machine in use – I’ll just manually invoke the optimization for now. The down side to it as that OneNote will "go modal" while optimizing the files - you can imagine the problems if you start inbounding content, which changes the file, while the file is being optimized.
So for my first level of verifications, I want to ensure the file size of the cache file is shrunk. Since I am trying to make my life easy by using a cache file in a known state, I know that since my file starts at 60MB when optimize is done it should be 20MB. So that verification is just checking a file size on disk.
A second verification will be to ensure OneNote creates the registry key for the last time the file was successfully optimized. It is (appropriately) named LastCacheOptimizeSuccessTime and is stored in the OneNote\General branch of the registry.
More in depth verifications can be that the expected data gets removed and the state of the section files when this is done. I can also check to see if we lock the files while this is happening, and even force content into a file so that OneNote can detect this and prompt the user that the file changed and could not be verified. Oh, and check that the file not only "got smaller," but did not get corrupted.
And that would be about it for the basic verifications. Then I can go back and verify the idle routine and the Percentage threshold for optimization, and add more detailed metrics (performance springs to mind) as needed.
Questions, comments, concerns and criticisms always welcome, John