public void Modules() { // modules: { MultiModule.dll, mod2.netmodule, mod3.netmodule } var dir = Temp.CreateDirectory(); string path0 = dir.CreateFile("MultiModule.dll").WriteAllBytes(TestResources.SymbolsTests.MultiModule.MultiModuleDll).Path; string path1 = dir.CreateFile("mod2.netmodule").WriteAllBytes(TestResources.SymbolsTests.MultiModule.mod2).Path; string path2 = dir.CreateFile("mod3.netmodule").WriteAllBytes(TestResources.SymbolsTests.MultiModule.mod3).Path; var metadata1 = _provider.GetMetadata(path0, MetadataImageKind.Assembly) as AssemblyMetadata; Assert.NotNull(metadata1); Assert.Equal(3, metadata1.GetModules().Length); var scDir = Directory.GetFileSystemEntries(_provider.ShadowCopyDirectory).Single(); Assert.True(Directory.Exists(scDir)); var scFiles = Directory.GetFileSystemEntries(scDir); AssertEx.SetEqual(new[] { "MultiModule.dll", "mod2.netmodule", "mod3.netmodule" }, scFiles.Select(p => Path.GetFileName(p))); foreach (var sc in scFiles) { Assert.True(_provider.IsShadowCopy(sc)); if (!IsRunningOnMono) { // files should be locked: Assert.Throws <IOException>(() => File.Delete(sc)); } } // should get the same metadata: var metadata2 = _provider.GetMetadata(path0, MetadataImageKind.Assembly) as AssemblyMetadata; Assert.Same(metadata1, metadata2); // modify the file: File.SetLastWriteTimeUtc(path0, DateTime.Now + TimeSpan.FromHours(1)); // we get an updated image if we ask again: var modifiedMetadata3 = _provider.GetMetadata(path0, MetadataImageKind.Assembly) as AssemblyMetadata; Assert.NotSame(modifiedMetadata3, metadata2); // the file has been modified - we get new metadata: for (int i = 0; i < metadata2.GetModules().Length; i++) { Assert.NotSame(metadata2.GetModules()[i], modifiedMetadata3.GetModules()[i]); } }
public bool IsShadowCopy(string path) { return(_metadataFileProvider.IsShadowCopy(path)); }
public void Modules() { // modules: { MultiModule.dll, mod2.netmodule, mod3.netmodule } var dir = Temp.CreateDirectory(); string path0 = dir.CreateFile("MultiModule.dll").WriteAllBytes(TestResources.SymbolsTests.MultiModule.MultiModule).Path; string path1 = dir.CreateFile("mod2.netmodule").WriteAllBytes(TestResources.SymbolsTests.MultiModule.mod2).Path; string path2 = dir.CreateFile("mod3.netmodule").WriteAllBytes(TestResources.SymbolsTests.MultiModule.mod3).Path; var reference1 = _provider.GetReference(path0); Assert.NotNull(reference1); Assert.Equal(0, _provider.CacheSize); Assert.Equal(path0, reference1.FilePath); var metadata1 = reference1.GetMetadata() as AssemblyMetadata; Assert.NotNull(metadata1); Assert.Equal(3, metadata1.GetModules().Length); var scDir = Directory.GetFileSystemEntries(_provider.ShadowCopyDirectory).Single(); Assert.True(Directory.Exists(scDir)); var scFiles = Directory.GetFileSystemEntries(scDir); AssertEx.SetEqual(new[] { "MultiModule.dll", "mod2.netmodule", "mod3.netmodule" }, scFiles.Select(p => Path.GetFileName(p))); foreach (var sc in scFiles) { Assert.True(_provider.IsShadowCopy(sc)); // files should be locked: Assert.Throws <IOException>(() => File.Delete(sc)); } // should get the same metadata: var metadata2 = reference1.GetMetadata() as AssemblyMetadata; Assert.Same(metadata1, metadata2); // a new reference is created: var reference2 = _provider.GetReference(path0); Assert.NotNull(reference2); Assert.Equal(path0, reference2.FilePath); Assert.NotSame(reference1, reference2); // the original file wasn't modified so we still get the same metadata: var metadata3 = reference2.GetMetadata() as AssemblyMetadata; Assert.Same(metadata3, metadata2); // modify the file: File.SetLastWriteTimeUtc(path0, DateTime.Now + TimeSpan.FromHours(1)); // the reference doesn't own the metadata, so we get an updated image if we ask again: var modifiedMetadata3 = reference2.GetMetadata() as AssemblyMetadata; Assert.NotSame(modifiedMetadata3, metadata2); // a new reference is created, again we get the modified image (which is copied to the shadow copy driectory): var reference4 = _provider.GetReference(path0); Assert.NotNull(reference4); Assert.Equal(path0, reference4.FilePath); Assert.NotSame(reference2, reference4); // the file has been modified - we get new metadata: var metadata4 = reference4.GetMetadata() as AssemblyMetadata; Assert.NotSame(metadata4, metadata3); for (int i = 0; i < metadata4.GetModules().Length; i++) { Assert.NotSame(metadata4.GetModules()[i], metadata3.GetModules()[i]); } }