public async Task GetCacheFilePathAsync_SwitchesToMainThread_Succeeds() { // Arrange using (var testDirectory = TestDirectory.Create()) { var testProj = "project.csproj"; var testMSBuildProjectExtensionsPath = Path.Combine(testDirectory, "obj"); Directory.CreateDirectory(testMSBuildProjectExtensionsPath); var projectAdapter = Mock.Of <IVsProjectAdapter>(); Mock.Get(projectAdapter) .SetupGet(x => x.MSBuildProjectExtensionsPath) .Returns(testMSBuildProjectExtensionsPath); Mock.Get(projectAdapter) .SetupGet(x => x.FullProjectPath) .Returns(Path.Combine(testDirectory, testProj)); var testProject = new LegacyPackageReferenceProject( projectAdapter, Guid.NewGuid().ToString(), new TestProjectSystemServices(), _threadingService); // Act var assetsPath = await testProject.GetCacheFilePathAsync(); // Assert Assert.Equal(Path.Combine(testMSBuildProjectExtensionsPath, $"{testProj}.nuget.cache"), assetsPath); // Verify Mock.Get(projectAdapter) .VerifyGet(x => x.MSBuildProjectExtensionsPath, Times.AtLeastOnce); } }
public async Task GetCacheFilePathAsync_WithNoMSBuildProjectExtensionsPath_Throws() { // Arrange using (TestDirectory.Create()) { var testProject = new LegacyPackageReferenceProject( Mock.Of <IVsProjectAdapter>(), Guid.NewGuid().ToString(), new TestProjectSystemServices(), _threadingService); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); // Act & Assert await Assert.ThrowsAsync <InvalidDataException>( () => testProject.GetCacheFilePathAsync()); } }
public async Task GetCacheFilePathAsync_WithValidBaseIntermediateOutputPath_Succeeds() { // Arrange using (var testDirectory = TestDirectory.Create()) { var testProj = "project.csproj"; var testBaseIntermediateOutputPath = Path.Combine(testDirectory, "obj"); Directory.CreateDirectory(testBaseIntermediateOutputPath); var projectAdapter = Mock.Of <IVsProjectAdapter>(); Mock.Get(projectAdapter) .SetupGet(x => x.BaseIntermediateOutputPath) .Returns(testBaseIntermediateOutputPath); Mock.Get(projectAdapter) .SetupGet(x => x.FullProjectPath) .Returns(Path.Combine(testDirectory, testProj)); var testProject = new LegacyPackageReferenceProject( projectAdapter, Guid.NewGuid().ToString(), new TestProjectSystemServices(), _threadingService); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); // Act var cachePath = await testProject.GetCacheFilePathAsync(); // Assert Assert.Equal(Path.Combine(testBaseIntermediateOutputPath, $"{testProj}.nuget.cache"), cachePath); // Verify Mock.Get(projectAdapter) .VerifyGet(x => x.BaseIntermediateOutputPath, Times.AtLeastOnce); } }