public void PrepareForImagesTest() { using (var tempDirectory = new TempDirectory(true)) { var manager = new ResultImageManager(); manager.DirectoryName = tempDirectory.Name; // ファイルがない場合 manager.PrepareForImages(); { Assert.Null(manager.GetImage("A")); Assert.Null(manager.GetImage("A")); } // ファイルがある場合 tempDirectory.AddFile(@"A\a.bmp", new Bitmap(10, 10)); tempDirectory.AddFile(@"B\b.bmp", new Bitmap(11, 10)); tempDirectory.AddFile(@"cdef.bmp", new Bitmap(12, 10)); Assert.True(File.Exists(tempDirectory.FullPath(@"A\a.bmp"))); Assert.True(File.Exists(tempDirectory.FullPath(@"B\b.bmp"))); Assert.True(File.Exists(tempDirectory.FullPath(@"cdef.bmp"))); Assert.Null(manager.PeekCache_TESTONLY("A")); Assert.Null(manager.PeekCache_TESTONLY("B")); Assert.Null(manager.PeekCache_TESTONLY("C")); { manager.PrepareForImages(); // var task = manager.GetTask_TESTONLY(); // task.Wait(); } var imageA0 = manager.PeekCache_TESTONLY("A"); Assert.AreEqual(10, imageA0.Width); Assert.AreEqual(11, manager.PeekCache_TESTONLY("B").Width); Assert.AreEqual(12, manager.PeekCache_TESTONLY("C").Width); Assert.AreEqual(12, manager.PeekCache_TESTONLY("D").Width); Assert.AreEqual(12, manager.PeekCache_TESTONLY("F").Width); var imageA1 = manager.GetImage("A"); Assert.AreSame(imageA0, imageA1); Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), imageA0.Tag); Assert.Null(manager.PeekCache_TESTONLY("A")); { manager.PrepareForImages(); // var task = manager.GetTask_TESTONLY(); // task.Wait(); } Assert.AreEqual(10, manager.PeekCache_TESTONLY("A").Width); { var image0 = manager.GetImage("A"); var image1 = manager.GetImage("A"); Assert.AreNotSame(image0, image1); Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image0.Tag); Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image1.Tag); } } }
public void ファイルが消されていた場合の処理() { using (var tempDirectory = new TempDirectory(true)) { var manager = new ResultImageManager(); tempDirectory.AddFile(@"A\a0.bmp", new Bitmap(10, 10)); tempDirectory.AddFile(@"A\a1.bmp", new Bitmap(11, 10)); tempDirectory.AddFile(@"A\a2.bmp", new Bitmap(12, 10)); manager.DirectoryName = tempDirectory.Name; { manager.PrepareForImages(); // var task = manager.GetTask_TESTONLY(); // task.Wait(); } tempDirectory.DeleteFile(@"A\a0.bmp"); tempDirectory.DeleteFile(@"A\a1.bmp"); tempDirectory.DeleteFile(@"A\a2.bmp"); { manager.PrepareForImages(); // var task = manager.GetTask_TESTONLY(); // task.Wait(); } Assert.NotNull(manager.GetImage("A")); Assert.Null(manager.GetImage("A")); } }