public void IsRunningInVisualStudioIsSetForResolverContext() { bool isRunningInVisualStudio = false; var service = new CachingSdkResolverService(); service.InitializeForTests( resolvers: new List <SdkResolver> { new SdkUtilities.ConfigurableMockSdkResolver((sdkRference, resolverContext, factory) => { isRunningInVisualStudio = resolverContext.IsRunningInVisualStudio; return(null); }) }); var result = service.ResolveSdk( BuildEventContext.InvalidSubmissionId, new SdkReference("foo", "1.0.0", null), _loggingContext, new MockElementLocation("file"), "sln", "projectPath", false, // Pass along isRunningInVisualStudio and expect it to be received in the SdkResolverContext isRunningInVisualStudio: true); isRunningInVisualStudio.ShouldBeTrue(); }
public void InteractiveIsSetForResolverContext() { // Start with interactive false bool interactive = false; var service = new CachingSdkResolverService(); service.InitializeForTests( resolvers: new List <SdkResolver> { new SdkUtilities.ConfigurableMockSdkResolver((sdkRference, resolverContext, factory) => { interactive = resolverContext.Interactive; return(null); }) }); service.ResolveSdk( BuildEventContext.InvalidSubmissionId, new SdkReference("foo", "1.0.0", null), _loggingContext, new MockElementLocation("file"), "sln", "projectPath", // Pass along interactive and expect it to be received in the SdkResolverContext interactive: true, false); interactive.ShouldBeTrue(); }
public void CachingWrapperShouldOnlyResolveOnce() { var sdk = new SdkReference("foo", "1.0.0", null); var resolver = new SdkUtilities.ConfigurableMockSdkResolver( new SdkResultImpl( sdk, "path", "1.0.0", Enumerable.Empty <string>() )); var service = new CachingSdkResolverService(); service.InitializeForTests( null, new List <SdkResolver> { resolver }); // Resolve the SDK 10 times in parallel Parallel.For( 0, 10, _ => service.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false)); var result = resolver.ResolvedCalls.ShouldHaveSingleItem(); result.Key.ShouldBe(sdk.Name); // The SDK resolver keeps track of the number of times it was called which should be 1 result.Value.ShouldBe(1, $"The SDK resolver should have only been called once but was called {result.Value} times"); }
internal EvaluationContext(SharingPolicy policy) { Policy = policy; SdkResolverService = new CachingSdkResolverService(); FileEntryExpansionCache = new ConcurrentDictionary <string, ImmutableArray <string> >(); FileSystem = new CachingFileSystemWrapper(FileSystems.Default); EngineFileUtilities = new EngineFileUtilities(new FileMatcher(FileSystem, FileEntryExpansionCache)); }
private EvaluationContext(SharingPolicy policy, IFileSystem fileSystem) { // Unsupported case: isolated context with non null file system. // Isolated means caches aren't reused, but the given file system might cache. ErrorUtilities.VerifyThrowArgument( policy == SharingPolicy.Shared || fileSystem == null, "IsolatedContextDoesNotSupportFileSystem"); Policy = policy; SdkResolverService = new CachingSdkResolverService(); FileEntryExpansionCache = new ConcurrentDictionary <string, IReadOnlyList <string> >(); FileSystem = fileSystem ?? new CachingFileSystemWrapper(FileSystems.Default); EngineFileUtilities = new EngineFileUtilities(new FileMatcher(FileSystem, FileEntryExpansionCache)); }
public void CachingWrapperShouldWarnWhenMultipleVersionsAreReferenced() { var sdk = new SdkReference("foo", "1.0.0", null); var resolver = new SdkUtilities.ConfigurableMockSdkResolver( new SdkResultImpl( sdk, "path", "1.0.0", Enumerable.Empty <string>() )); var service = new CachingSdkResolverService(); service.InitializeForTests( null, new List <SdkResolver> { resolver }); var result = service.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false); resolver.ResolvedCalls.Count.ShouldBe(1); result.Path.ShouldBe("path"); result.Version.ShouldBe("1.0.0"); _logger.WarningCount.ShouldBe(0); result = service.ResolveSdk(BuildEventContext.InvalidSubmissionId, new SdkReference("foo", "2.0.0", null), _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false); resolver.ResolvedCalls.Count.ShouldBe(1); result.Path.ShouldBe("path"); result.Version.ShouldBe("1.0.0"); _logger.WarningCount.ShouldBe(1); _logger.Warnings.First().Code.ShouldBe("MSB4240"); resolver.ResolvedCalls.First().Key.ShouldBe("foo"); resolver.ResolvedCalls.Count.ShouldBe(1); }