public void TestAssembly() { string assemblyDependencyPath = CreateMockAssembly("AssemblyDependency.dll"); IntPtr previousWriter = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate( (HostPolicyMock.ErrorWriterDelegate)((string _) => { Assert.True(false, "Should never get here"); })); using (HostPolicyMock.MockValues_corehost_set_error_writer errorWriterMock = HostPolicyMock.Mock_corehost_set_error_writer(previousWriter)) { using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, assemblyDependencyPath, "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Equal( assemblyDependencyPath, resolver.ResolveAssemblyToPath(new AssemblyName("AssemblyDependency"))); // After everything is done, the error writer should be reset to the original value. Assert.Equal(previousWriter, errorWriterMock.LastSetErrorWriterPtr); } } }
public void TestMutipleResourcesWithDifferentBasePath() { string enResourcePath = CreateMockAssembly($"en{Path.DirectorySeparatorChar}TestComponent.resources.dll"); string frResourcePath = CreateMockAssembly($"SubComponent{Path.DirectorySeparatorChar}fr{Path.DirectorySeparatorChar}TestComponent.resources.dll"); using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, "", "", $"{_componentDirectory}{Path.PathSeparator}{Path.GetDirectoryName(Path.GetDirectoryName(frResourcePath))}")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Equal( enResourcePath, resolver.ResolveAssemblyToPath(new AssemblyName("TestComponent.resources, Culture=en"))); Assert.Equal( frResourcePath, resolver.ResolveAssemblyToPath(new AssemblyName("TestComponent.resources, Culture=fr"))); } }
public void TestMutipleResourcesWithSameBasePath() { string enResourcePath = CreateMockAssembly($"en{Path.DirectorySeparatorChar}TestComponent.resources.dll"); string csResourcePath = CreateMockAssembly($"cs{Path.DirectorySeparatorChar}TestComponent.resources.dll"); using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, "", "", _componentDirectory)) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Equal( enResourcePath, resolver.ResolveAssemblyToPath(new AssemblyName("TestComponent.resources, Culture=en"))); Assert.Equal( csResourcePath, resolver.ResolveAssemblyToPath(new AssemblyName("TestComponent.resources, Culture=cs"))); } }
public void TestAssemblyWithMissingFile() { // Even if the .deps.json can resolve the request, if the file is not present // the resolution should still return null. using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, Path.Combine(_componentDirectory, "NonExistingAssembly.dll"), "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Null(resolver.ResolveAssemblyToPath(new AssemblyName("NonExistingAssembly"))); } }
public void TestAssemblyWithNoRecord() { // If the reqest is for assembly which is not listed in .deps.json // the resolver should return null. using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, "", "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Null(resolver.ResolveAssemblyToPath(new AssemblyName("AssemblyWithNoRecord"))); } }
public void TestAssemblyWithNeutralCulture() { string neutralAssemblyPath = CreateMockAssembly("NeutralAssembly.dll"); using (HostPolicyMock.Mock_corehost_resolve_componet_dependencies( 0, neutralAssemblyPath, "", "")) { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); Assert.Equal( neutralAssemblyPath, resolver.ResolveAssemblyToPath(new AssemblyName("NeutralAssembly, Culture=neutral"))); } }