public void VerifyThrowsWhenResolverFailsToLoad() { SdkResolverLoader sdkResolverLoader = new MockSdkResolverLoader { LoadResolverAssemblyFunc = (resolverPath, loggingContext, location) => typeof(SdkResolverLoader_Tests).GetTypeInfo().Assembly, FindPotentialSdkResolversFunc = rootFolder => new List <string> { "myresolver.dll" }, GetResolverTypesFunc = assembly => new[] { typeof(MockSdkResolverThatDoesNotLoad) } }; InvalidProjectFileException exception = Should.Throw <InvalidProjectFileException>(() => { sdkResolverLoader.LoadResolvers(_loggingContext, ElementLocation.EmptyLocation); }); exception.Message.ShouldBe($"The SDK resolver type \"{nameof(MockSdkResolverThatDoesNotLoad)}\" failed to load. A8BB8B3131D3475D881ACD3AF8D75BD6"); Exception innerException = exception.InnerException.ShouldBeOfType <Exception>(); innerException.Message.ShouldBe(MockSdkResolverThatDoesNotLoad.ExpectedMessage); _logger.WarningCount.ShouldBe(0); _logger.ErrorCount.ShouldBe(0); }
public void VerifyWarningLoggedWhenResolverAssemblyCannotBeLoaded() { const string assemblyPath = @"C:\foo\bar\myresolver.dll"; const string expectedMessage = "91BF077D4E9646819DE7AB2CBA2637B6"; SdkResolverLoader sdkResolverLoader = new MockSdkResolverLoader { LoadResolverAssemblyFunc = (resolverPath, loggingContext, location) => { throw new Exception(expectedMessage); }, FindPotentialSdkResolversFunc = rootFolder => new List <string> { assemblyPath, } }; InvalidProjectFileException exception = Should.Throw <InvalidProjectFileException>(() => { sdkResolverLoader.LoadResolvers(_loggingContext, ElementLocation.EmptyLocation); }); exception.Message.ShouldBe($"The SDK resolver assembly \"{assemblyPath}\" could not be loaded. {expectedMessage}"); Exception innerException = exception.InnerException.ShouldBeOfType <Exception>(); innerException.Message.ShouldBe(expectedMessage); _logger.WarningCount.ShouldBe(0); _logger.ErrorCount.ShouldBe(0); }
public void SdkResolverLoaderHonorsIncludeDefaultEnvVar() { using (var env = TestEnvironment.Create(_output)) { var origIncludeDefault = Environment.GetEnvironmentVariable("MSBUILDINCLUDEDEFAULTSDKRESOLVER"); try { var testRoot = env.CreateFolder().Path; Environment.SetEnvironmentVariable("MSBUILDINCLUDEDEFAULTSDKRESOLVER", "false"); SdkResolverLoader loader = new MockSdkResolverLoader() { LoadResolversAction = (resolverPath, loggingContext, location, resolvers) => { resolvers.Add(new MockSdkResolverWithAssemblyPath(resolverPath)); } }; IList <SdkResolverBase> resolvers = loader.LoadResolvers(_loggingContext, new MockElementLocation("file")); resolvers.Count.ShouldBe(0); } finally { Environment.SetEnvironmentVariable("MSBUILDINCLUDEDEFAULTSDKRESOLVER", origIncludeDefault); } } }
public void VerifyThrowsWhenResolverHasNoPublicConstructor() { SdkResolverLoader sdkResolverLoader = new MockSdkResolverLoader { LoadResolverAssemblyFunc = (resolverPath, loggingContext, location) => typeof(SdkResolverLoader_Tests).GetTypeInfo().Assembly, FindPotentialSdkResolversFunc = rootFolder => new List <string> { "myresolver.dll" }, GetResolverTypesFunc = assembly => new[] { typeof(MockSdkResolverNoPublicConstructor) } }; InvalidProjectFileException exception = Should.Throw <InvalidProjectFileException>(() => { sdkResolverLoader.LoadResolvers(_loggingContext, ElementLocation.EmptyLocation); }); exception.Message.ShouldStartWith($"The SDK resolver type \"{nameof(MockSdkResolverNoPublicConstructor)}\" failed to load."); exception.InnerException.ShouldBeOfType <MissingMethodException>(); _logger.WarningCount.ShouldBe(0); _logger.ErrorCount.ShouldBe(0); }