public void TFromChanges_Empty() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = TargetedDependenciesSnapshot.CreateEmpty(projectPath, targetFramework, catalogs); var changes = new DependenciesChanges(); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes, catalogs, Array.Empty <IDependenciesSnapshotFilter>(), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.Same(previousSnapshot, snapshot); }
private IDependenciesSnapshot GetSnapshot(Dictionary <ITargetFramework, List <IDependency> > testData) { var catalogs = IProjectCatalogSnapshotFactory.Create(); var targets = new Dictionary <ITargetFramework, ITargetedDependenciesSnapshot>(); foreach (var kvp in testData) { var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement( catalogs: catalogs, topLevelDependencies: kvp.Value, checkForUnresolvedDependencies: false, targetFramework: kvp.Key); targets.Add(kvp.Key, targetedSnapshot); } return(IDependenciesSnapshotFactory.Implement( targets: targets, hasUnresolvedDependency: false, activeTarget: testData.First().Key)); }
public void FromChanges_Empty_ProjectPathAndTargetChange() { const string previousProjectPath = @"c:\somefolder\someproject\a.csproj"; const string newProjectPath = @"c:\somefolder\someproject\b.csproj"; var catalogs = IProjectCatalogSnapshotFactory.Create(); var activeTarget = new TargetFramework("tfm1"); var previousSnapshot = new DependenciesSnapshot( previousProjectPath, activeTarget, ImmutableDictionary <ITargetFramework, ITargetedDependenciesSnapshot> .Empty); var targetChanges = new DependenciesChangesBuilder(); var model = new TestDependencyModel { ProviderType = "Xxx", Id = "dependency1" }; targetChanges.Added(model); var changes = new Dictionary <ITargetFramework, IDependenciesChanges> { [activeTarget] = targetChanges.Build() }; var snapshot = DependenciesSnapshot.FromChanges( newProjectPath, previousSnapshot, changes.ToImmutableDictionary(), catalogs, activeTarget, ImmutableArray <IDependenciesSnapshotFilter> .Empty, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(newProjectPath, snapshot.ProjectPath); Assert.Same(activeTarget, snapshot.ActiveTarget); Assert.NotSame(previousSnapshot.Targets, snapshot.Targets); Assert.Equal(@"tfm1\Xxx\dependency1", snapshot.Targets[activeTarget].DependenciesWorld.First().Value.Id); }
public void FromChanges_DifferentModelIdCapitalisation() { var targetFramework = new TargetFramework("tfm1"); var dependencyPrevious = new TestDependency { ProviderType = "Xxx", Id = "dependency1", Resolved = false }; var dependencyModelUpdated = new TestDependencyModel { ProviderType = "XXX", // changed case Id = "DEPENDENCY1", // changed case Resolved = true }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( targetFramework, catalogs, ImmutableArray.Create <IDependency>(dependencyPrevious)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelUpdated); var snapshot = TargetedDependenciesSnapshot.FromChanges( previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray <IDependenciesSnapshotFilter> .Empty); Assert.NotSame(previousSnapshot, snapshot); var dependency = Assert.Single(snapshot.Dependencies); Assert.Equal("DEPENDENCY1", dependency.Id); Assert.Equal("XXX", dependency.ProviderType); Assert.True(dependency.Resolved); }
public void FromChanges_WithDependenciesChanges() { var catalogs = IProjectCatalogSnapshotFactory.Create(); var targetFramework = new TargetFramework("tfm1"); var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(catalogs, targetFramework); var previousSnapshot = new DependenciesSnapshot( activeTargetFramework: targetFramework, dependenciesByTargetFramework); var targetChanges = new DependenciesChangesBuilder(); var model = new TestDependencyModel { ProviderType = "Xxx", Id = "dependency1" }; targetChanges.Added(model); var snapshot = DependenciesSnapshot.FromChanges( previousSnapshot, targetFramework, targetChanges.TryBuildChanges() !, catalogs, targetFrameworks: ImmutableArray.Create <TargetFramework>(targetFramework), activeTargetFramework: targetFramework, ImmutableArray <IDependenciesSnapshotFilter> .Empty, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(targetFramework, snapshot.ActiveTargetFramework); Assert.NotSame(previousSnapshot.DependenciesByTargetFramework, snapshot.DependenciesByTargetFramework); var(actualTfm, targetedSnapshot) = Assert.Single(snapshot.DependenciesByTargetFramework); Assert.Same(targetFramework, actualTfm); var dependency = Assert.Single(targetedSnapshot.Dependencies); Assert.Equal("dependency1", dependency.Id); Assert.Equal("Xxx", dependency.ProviderType); }
public void FromChanges_ProjectPathAndTargetChange() { const string previousProjectPath = @"c:\somefolder\someproject\a.csproj"; const string newProjectPath = @"c:\somefolder\someproject\b.csproj"; var catalogs = IProjectCatalogSnapshotFactory.Create(); var targetFramework = new TargetFramework("tfm1"); var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(previousProjectPath, catalogs, targetFramework); var previousSnapshot = new DependenciesSnapshot( previousProjectPath, activeTargetFramework: targetFramework, dependenciesByTargetFramework); var targetChanges = new DependenciesChangesBuilder(); var model = new TestDependencyModel { ProviderType = "Xxx", Id = "dependency1" }; targetChanges.Added(model); var snapshot = DependenciesSnapshot.FromChanges( newProjectPath, previousSnapshot, targetFramework, targetChanges.TryBuildChanges() !, catalogs, targetFrameworks: ImmutableArray.Create <ITargetFramework>(targetFramework), activeTargetFramework: targetFramework, ImmutableArray <IDependenciesSnapshotFilter> .Empty, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(newProjectPath, snapshot.ProjectPath); Assert.Same(targetFramework, snapshot.ActiveTargetFramework); Assert.NotSame(previousSnapshot.DependenciesByTargetFramework, snapshot.DependenciesByTargetFramework); Assert.Equal(@"tfm1\Xxx\dependency1", snapshot.DependenciesByTargetFramework[targetFramework].DependenciesWorld.First().Value.Id); }
public void Constructor() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = new TargetedDependenciesSnapshot( projectPath, targetFramework, catalogs, ImmutableStringDictionary <IDependency> .EmptyOrdinalIgnoreCase); Assert.Same(projectPath, snapshot.ProjectPath); Assert.Same(targetFramework, snapshot.TargetFramework); Assert.Same(catalogs, snapshot.Catalogs); Assert.False(snapshot.HasReachableVisibleUnresolvedDependency); Assert.Empty(snapshot.TopLevelDependencies); Assert.Empty(snapshot.DependenciesWorld); Assert.False(snapshot.CheckForUnresolvedDependencies("foo")); Assert.Empty(snapshot.GetDependencyChildren(new TestDependency())); }
public void FromChanges_NoChanges() { var catalogs = IProjectCatalogSnapshotFactory.Create(); var targetFramework = new TargetFramework("tfm1"); var targetFrameworks = ImmutableArray <TargetFramework> .Empty.Add(targetFramework); var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(catalogs, targetFramework); var previousSnapshot = new DependenciesSnapshot( activeTargetFramework: targetFramework, dependenciesByTargetFramework); var snapshot = DependenciesSnapshot.FromChanges( previousSnapshot, targetFramework, changes: null, catalogs, targetFrameworks, activeTargetFramework: targetFramework); Assert.Same(previousSnapshot, snapshot); }
public void TConstructor() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( dependenciesWorld: new Dictionary <string, IDependency>(), topLevelDependencies: new List <IDependency>()); var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = new TestableTargetedDependenciesSnapshot( projectPath, targetFramework, previousSnapshot, catalogs); Assert.NotNull(snapshot.TargetFramework); Assert.Equal("tfm1", snapshot.TargetFramework.FullName); Assert.Equal(projectPath, snapshot.ProjectPath); Assert.Equal(catalogs, snapshot.Catalogs); Assert.Equal(previousSnapshot.TopLevelDependencies, snapshot.TopLevelDependencies); Assert.Equal(previousSnapshot.DependenciesWorld, snapshot.DependenciesWorld); }
public void FromChanges_CatalogChanged() { var targetFramework = new TargetFramework("tfm1"); var previousCatalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = TargetedDependenciesSnapshot.CreateEmpty(targetFramework, previousCatalogs); var updatedCatalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = TargetedDependenciesSnapshot.FromChanges( previousSnapshot, changes: null, updatedCatalogs, ImmutableArray <IDependenciesSnapshotFilter> .Empty); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(updatedCatalogs, snapshot.Catalogs); Assert.Equal(previousSnapshot.Dependencies.Length, snapshot.Dependencies.Length); for (int i = 0; i < previousSnapshot.Dependencies.Length; i++) { Assert.Same(previousSnapshot.Dependencies[i], snapshot.Dependencies[i]); } Assert.Equal(DiagnosticLevel.None, snapshot.MaximumVisibleDiagnosticLevel); Assert.Empty(snapshot.Dependencies); }
public void FromChanges_Empty_ProjectPathAndActiveTargetChange() { const string previousProjectPath = @"c:\somefolder\someproject\a.csproj"; const string newProjectPath = @"c:\somefolder\someproject\b.csproj"; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousActiveTarget = new TargetFramework("tfm1"); var newActiveTarget = new TargetFramework("tfm2"); var previousSnapshot = new DependenciesSnapshot( previousProjectPath, previousActiveTarget, ImmutableDictionary <ITargetFramework, ITargetedDependenciesSnapshot> .Empty); var targetChanges = new DependenciesChangesBuilder(); var changes = new Dictionary <ITargetFramework, IDependenciesChanges> { [previousActiveTarget] = targetChanges.Build(), [newActiveTarget] = targetChanges.Build() }; var snapshot = DependenciesSnapshot.FromChanges( newProjectPath, previousSnapshot, changes.ToImmutableDictionary(), catalogs, newActiveTarget, ImmutableArray <IDependenciesSnapshotFilter> .Empty, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(newProjectPath, snapshot.ProjectPath); Assert.Same(newActiveTarget, snapshot.ActiveTarget); Assert.Same(previousSnapshot.Targets, snapshot.Targets); }
public void TFromChanges_NoChanges() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyModelTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( dependenciesWorld: new Dictionary <string, IDependency>() { { dependencyModelTop1.Id, dependencyModelTop1 }, { dependencyModelChild1.Id, dependencyModelChild1 }, }, topLevelDependencies: new List <IDependency>() { dependencyModelTop1 }); var addedNodes = new List <IDependencyModel>(); var removedNodes = new List <IDependencyModel>(); var changes = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes); IEnumerable <IDependenciesSnapshotFilter> snapshotFilters = null; var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, targetFramework, previousSnapshot, changes, catalogs, snapshotFilters, null, null, out bool anyChanges); Assert.NotNull(snapshot.TargetFramework); Assert.Equal("tfm1", snapshot.TargetFramework.FullName); Assert.Equal(projectPath, snapshot.ProjectPath); Assert.Equal(catalogs, snapshot.Catalogs); Assert.False(anyChanges); Assert.Single(snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 2); }
public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""true"" }"); var dependencyChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }"); var dependencyModelNew1 = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""newdependency1"", ""Name"":""NewDependency1"", ""Caption"":""NewDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new [] { dependencyTop1, dependencyChild1 }, topLevelDependencies: new [] { dependencyTop1 }); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelNew1); var filterAddedDependency = new TestDependency { Id = "unexpected", TopLevel = true }; var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject(@"tfm1\xxx\newdependency1", addOrUpdate: filterAddedDependency); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.Build(), catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(previousSnapshot.ProjectPath, snapshot.ProjectPath); Assert.Same(previousSnapshot.Catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2); Assert.Contains(dependencyTop1, snapshot.TopLevelDependencies); Assert.Contains(filterAddedDependency, snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 3); Assert.Contains(dependencyTop1, snapshot.DependenciesWorld.Values); Assert.Contains(dependencyChild1, snapshot.DependenciesWorld.Values); Assert.Contains(filterAddedDependency, snapshot.DependenciesWorld.Values); }
public void TFromChanges_RemovedAndAddedChanges() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyModelTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelAdded1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency1"", ""Name"":""AddedDependency1"", ""Caption"":""AddedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelAdded2 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency2"", ""Name"":""AddedDependency2"", ""Caption"":""AddedDependency2"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelAdded3 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency3"", ""Name"":""AddedDependency3"", ""Caption"":""AddedDependency3"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyAdded2Changed = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\addeddependency2"", ""Name"":""AddedDependency2Changed"", ""Caption"":""AddedDependency2Changed"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyRemoved1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\Removeddependency1"", ""Name"":""RemovedDependency1"", ""Caption"":""RemovedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelRemoved1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""Removeddependency1"", ""Name"":""RemovedDependency1"", ""Caption"":""RemovedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyInsteadRemoved1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\InsteadRemoveddependency1"", ""Name"":""InsteadRemovedDependency1"", ""Caption"":""InsteadRemovedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( dependenciesWorld: new Dictionary <string, IDependency>() { { @"tfm1\xxx\topdependency1", dependencyModelTop1 }, { @"tfm1\xxx\childdependency1", dependencyModelChild1 }, { @"tfm1\xxx\Removeddependency1", dependencyRemoved1 }, }, topLevelDependencies: new List <IDependency>() { dependencyModelTop1 }); var addedNodes = new List <IDependencyModel> { dependencyModelAdded1, dependencyModelAdded2, dependencyModelAdded3 }; var removedNodes = new List <IDependencyModel> { dependencyModelRemoved1 }; var changes = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes); var snapshotFilter = new TestDependenciesSnapshotFilter() .ImplementBeforeAddResult(FilterAction.Cancel, @"tfm1\xxx\addeddependency1", null) .ImplementBeforeAddResult(FilterAction.ShouldBeAdded, @"tfm1\xxx\addeddependency2", dependencyAdded2Changed) .ImplementBeforeRemoveResult(FilterAction.ShouldBeAdded, @"tfm1\xxx\Removeddependency1", dependencyInsteadRemoved1); var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, targetFramework, previousSnapshot, changes, catalogs, new[] { snapshotFilter }, null, null, out bool anyChanges); Assert.NotNull(snapshot.TargetFramework); Assert.Equal("tfm1", snapshot.TargetFramework.FullName); Assert.Equal(projectPath, snapshot.ProjectPath); Assert.Equal(catalogs, snapshot.Catalogs); Assert.True(anyChanges); AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"topdependency1")); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\addeddependency2") && x.Caption.Equals("AddedDependency2Changed")); AssertEx.CollectionLength(snapshot.DependenciesWorld, 5); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\topdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\childdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency2")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\InsteadRemoveddependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency3")); }
public void FromChanges_RemovedAndAddedChanges() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""true"" }"); var dependencyChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }"); var dependencyModelAdded1 = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency1"", ""Name"":""AddedDependency1"", ""Caption"":""AddedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelAdded2 = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency2"", ""Name"":""AddedDependency2"", ""Caption"":""AddedDependency2"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelAdded3 = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""addeddependency3"", ""Name"":""AddedDependency3"", ""Caption"":""AddedDependency3"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyAdded2Changed = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\addeddependency2"", ""Name"":""AddedDependency2Changed"", ""Caption"":""AddedDependency2Changed"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""true"" }"); var dependencyRemoved1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\Removeddependency1"", ""Name"":""RemovedDependency1"", ""Caption"":""RemovedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }"); var dependencyInsteadRemoved1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\InsteadRemoveddependency1"", ""Name"":""InsteadRemovedDependency1"", ""Caption"":""InsteadRemovedDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }"); Assert.True(dependencyTop1.TopLevel); Assert.False(dependencyChild1.TopLevel); Assert.False(dependencyRemoved1.TopLevel); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new [] { dependencyTop1, dependencyChild1, dependencyRemoved1 }, topLevelDependencies: new [] { dependencyTop1 }); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelAdded1); changes.Added(dependencyModelAdded2); changes.Added(dependencyModelAdded3); changes.Removed("Xxx", "Removeddependency1"); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject(@"tfm1\xxx\addeddependency1") .BeforeAddAccept(@"tfm1\xxx\addeddependency2", dependencyAdded2Changed) .BeforeAddAccept(@"tfm1\xxx\addeddependency3") .BeforeRemoveAccept(@"tfm1\xxx\Removeddependency1", dependencyInsteadRemoved1); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.Build(), catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(projectPath, snapshot.ProjectPath); Assert.Same(catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\topdependency1")); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\addeddependency2") && x.Caption.Equals("AddedDependency2Changed")); AssertEx.CollectionLength(snapshot.DependenciesWorld, 5); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\topdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\childdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency2")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\InsteadRemoveddependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency3")); }
public void TFromChanges_ReportedChangesAfterBeforeRemoveFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyModelTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelTop1Removed = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( dependenciesWorld: new Dictionary <string, IDependency>(StringComparer.OrdinalIgnoreCase) { { dependencyModelTop1.Id, dependencyModelTop1 }, { dependencyModelChild1.Id, dependencyModelChild1 }, }, topLevelDependencies: new List <IDependency>() { dependencyModelTop1 }); var addedNodes = new List <IDependencyModel>(); var removedNodes = new List <IDependencyModel> { dependencyModelTop1Removed }; var changes = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes); var snapshotFilter = new TestDependenciesSnapshotFilter() .ImplementBeforeRemoveResult(FilterAction.Cancel, @"tfm1\xxx\topdependency1", null) .ImplementFilterAnyChanges(true); var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, targetFramework, previousSnapshot, changes, catalogs, new[] { snapshotFilter }, null, null, out bool anyChanges); Assert.NotNull(snapshot.TargetFramework); Assert.Equal("tfm1", snapshot.TargetFramework.FullName); Assert.Equal(projectPath, snapshot.ProjectPath); Assert.Equal(catalogs, snapshot.Catalogs); Assert.True(anyChanges); Assert.Single(snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 2); }
public void FromChanges_RemovedAndAddedChanges() { var targetFramework = new TargetFramework("tfm1"); var dependency1 = new TestDependency { ProviderType = "Xxx", Id = "dependency1", OriginalItemSpec = "Dependency1", Caption = "Dependency1", SchemaItemType = "Xxx", Resolved = true }; var dependency2 = new TestDependency { ProviderType = "Xxx", Id = "dependency2", OriginalItemSpec = "Dependency2", Caption = "Dependency2", SchemaItemType = "Xxx", Resolved = true }; var dependencyModelAdded1 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency1", OriginalItemSpec = "AddedDependency1", Caption = "AddedDependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyModelAdded2 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency2", OriginalItemSpec = "AddedDependency2", Caption = "AddedDependency2", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyModelAdded3 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency3", OriginalItemSpec = "AddedDependency3", Caption = "AddedDependency3", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyAdded2Changed = new TestDependency { ProviderType = "Xxx", Id = "addeddependency2", OriginalItemSpec = "AddedDependency2Changed", Caption = "AddedDependency2Changed", SchemaItemType = "Xxx", Resolved = true }; var dependencyRemoved1 = new TestDependency { ProviderType = "Xxx", Id = "Removeddependency1", OriginalItemSpec = "RemovedDependency1", Caption = "RemovedDependency1", SchemaItemType = "Xxx", Resolved = true }; var dependencyInsteadRemoved1 = new TestDependency { ProviderType = "Xxx", Id = "InsteadRemoveddependency1", OriginalItemSpec = "InsteadRemovedDependency1", Caption = "InsteadRemovedDependency1", SchemaItemType = "Xxx", Resolved = true }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( targetFramework, catalogs, ImmutableArray.Create <IDependency>(dependency1, dependency2, dependencyRemoved1)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelAdded1); changes.Added(dependencyModelAdded2); changes.Added(dependencyModelAdded3); changes.Removed("Xxx", "Removeddependency1"); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject("Xxx", "addeddependency1") .BeforeAddAccept("Xxx", "addeddependency2", dependencyAdded2Changed) .BeforeAddAccept("Xxx", "addeddependency3") .BeforeRemoveAccept("Xxx", "Removeddependency1", dependencyInsteadRemoved1); var snapshot = TargetedDependenciesSnapshot.FromChanges( previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.Dependencies, 5); Assert.Contains(snapshot.Dependencies, dep => dep.Id == "dependency1"); Assert.Contains(snapshot.Dependencies, dep => dep.Id == "dependency2"); Assert.Contains(snapshot.Dependencies, dep => dep.Id == "addeddependency2"); Assert.Contains(snapshot.Dependencies, dep => dep.Id == "InsteadRemoveddependency1"); Assert.Contains(snapshot.Dependencies, dep => dep.Id == "addeddependency3"); }
public void FromChanges_UpdatesLevelDependencies() { var targetFramework = new TargetFramework("tfm1"); var dependencyPrevious = new TestDependency { ProviderType = "Xxx", Id = "dependency1", OriginalItemSpec = "Dependency1", Caption = "Dependency1", SchemaItemType = "Xxx", Resolved = true }; var dependencyModelAdded = new TestDependencyModel { ProviderType = "Xxx", Id = "dependency1", OriginalItemSpec = "Dependency1", Caption = "Dependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyUpdated = new TestDependency { ProviderType = "Xxx", Id = "dependency1", OriginalItemSpec = "Dependency1", Caption = "Dependency1", SchemaItemType = "Xxx", Resolved = true }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( targetFramework, catalogs, ImmutableArray.Create <IDependency>(dependencyPrevious)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelAdded); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddAccept("Xxx", "dependency1", dependencyUpdated); var snapshot = TargetedDependenciesSnapshot.FromChanges( previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(dependencyUpdated, snapshot.Dependencies.Single()); }
public void TargetedDependenciesSnapshot_FromChanges_NoChangesAfterBeforeAddFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyModelTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelNew1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""newdependency1"", ""Name"":""NewDependency1"", ""Caption"":""NewDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( dependenciesWorld: new Dictionary <string, IDependency>() { { dependencyModelTop1.Id, dependencyModelTop1 }, { dependencyModelChild1.Id, dependencyModelChild1 }, }, topLevelDependencies: new List <IDependency>() { dependencyModelTop1 }); var addedNodes = new List <IDependencyModel> { dependencyModelNew1 }; var removedNodes = new List <IDependencyModel>(); var changes = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes); var snapshotFilter = new TestDependenciesSnapshotFilter() .ImplementBeforeAddResult(FilterAction.Cancel, @"tfm1\xxx\newdependency1", null); var catalogs = IProjectCatalogSnapshotFactory.Create(); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, targetFramework, previousSnapshot, changes, catalogs, new[] { snapshotFilter }, out bool anyChanges); Assert.NotNull(snapshot.TargetFramework); Assert.Equal("tfm1", snapshot.TargetFramework.Moniker); Assert.Equal(projectPath, snapshot.ProjectPath); Assert.Equal(catalogs, snapshot.Catalogs); Assert.False(anyChanges); Assert.Equal(1, snapshot.TopLevelDependencies.Count); Assert.Equal(2, snapshot.DependenciesWorld.Count); }
public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange() { var targetFramework = new TargetFramework("tfm1"); var dependency1 = new TestDependency { ProviderType = "Xxx", Id = "dependency1", OriginalItemSpec = "Dependency1", Caption = "Dependency1", SchemaItemType = "Xxx", Resolved = true }; var dependency2 = new TestDependency { ProviderType = "Xxx", Id = "dependency2", OriginalItemSpec = "Dependency2", Caption = "Dependency2", SchemaItemType = "Xxx", Resolved = true }; var dependencyModelNew1 = new TestDependencyModel { ProviderType = "Xxx", Id = "newdependency1", OriginalItemSpec = "NewDependency1", Caption = "NewDependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( targetFramework, catalogs, ImmutableArray.Create <IDependency>(dependency1, dependency2)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelNew1); var filterAddedDependency = new TestDependency { Id = "unexpected" }; var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject("Xxx", "newdependency1", addOrUpdate: filterAddedDependency); var snapshot = TargetedDependenciesSnapshot.FromChanges( previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(previousSnapshot.Catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.Dependencies, 3); Assert.Contains(dependency1, snapshot.Dependencies); Assert.Contains(dependency2, snapshot.Dependencies); Assert.Contains(filterAddedDependency, snapshot.Dependencies); }
public void FromChanges_RemovedAndAddedChanges() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = true }; var dependencyChild1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\childdependency1", Name = "ChildDependency1", Caption = "ChildDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; var dependencyModelAdded1 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency1", Name = "AddedDependency1", Caption = "AddedDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyModelAdded2 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency2", Name = "AddedDependency2", Caption = "AddedDependency2", SchemaItemType = "Xxx", Resolved = true, TopLevel = false, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyModelAdded3 = new TestDependencyModel { ProviderType = "Xxx", Id = "addeddependency3", Name = "AddedDependency3", Caption = "AddedDependency3", SchemaItemType = "Xxx", Resolved = true, TopLevel = false, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyAdded2Changed = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\addeddependency2", Name = "AddedDependency2Changed", Caption = "AddedDependency2Changed", SchemaItemType = "Xxx", Resolved = true, TopLevel = true }; var dependencyRemoved1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\Removeddependency1", Name = "RemovedDependency1", Caption = "RemovedDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; var dependencyInsteadRemoved1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\InsteadRemoveddependency1", Name = "InsteadRemovedDependency1", Caption = "InsteadRemovedDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; Assert.True(dependencyTop1.TopLevel); Assert.False(dependencyChild1.TopLevel); Assert.False(dependencyRemoved1.TopLevel); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( projectPath, targetFramework, catalogs, new IDependency[] { dependencyTop1, dependencyChild1, dependencyRemoved1 }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelAdded1); changes.Added(dependencyModelAdded2); changes.Added(dependencyModelAdded3); changes.Removed("Xxx", "Removeddependency1"); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject(@"tfm1\xxx\addeddependency1") .BeforeAddAccept(@"tfm1\xxx\addeddependency2", dependencyAdded2Changed) .BeforeAddAccept(@"tfm1\xxx\addeddependency3") .BeforeRemoveAccept(@"tfm1\xxx\Removeddependency1", dependencyInsteadRemoved1); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(projectPath, snapshot.ProjectPath); Assert.Same(catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\topdependency1")); Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\addeddependency2") && x.Caption.Equals("AddedDependency2Changed")); AssertEx.CollectionLength(snapshot.DependenciesWorld, 5); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\topdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\childdependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency2")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\InsteadRemoveddependency1")); Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency3")); }
public void FromChanges_UpdatesTopLevelDependencies() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTopPrevious = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true }; var dependencyModelTopAdded = new TestDependencyModel { ProviderType = "Xxx", Id = "topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var dependencyTopUpdated = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( projectPath, targetFramework, catalogs, new IDependency[] { dependencyTopPrevious }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelTopAdded); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddAccept(@"tfm1\xxx\topdependency1", dependencyTopUpdated); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(dependencyTopUpdated, snapshot.TopLevelDependencies.Single()); }
public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = true }; var dependencyChild1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\childdependency1", Name = "ChildDependency1", Caption = "ChildDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; var dependencyModelNew1 = new TestDependencyModel { ProviderType = "Xxx", Id = "newdependency1", Name = "NewDependency1", Caption = "NewDependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = new TargetedDependenciesSnapshot( projectPath, targetFramework, catalogs, new IDependency[] { dependencyTop1, dependencyChild1 }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase)); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelNew1); var filterAddedDependency = new TestDependency { Id = "unexpected", TopLevel = true }; var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject(@"tfm1\xxx\newdependency1", addOrUpdate: filterAddedDependency); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.TryBuildChanges() !, catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.True(snapshotFilter.Completed); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(previousSnapshot.ProjectPath, snapshot.ProjectPath); Assert.Same(previousSnapshot.Catalogs, snapshot.Catalogs); AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2); Assert.Contains(dependencyTop1, snapshot.TopLevelDependencies); Assert.Contains(filterAddedDependency, snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 3); Assert.Contains(dependencyTop1, snapshot.DependenciesWorld.Values); Assert.Contains(dependencyChild1, snapshot.DependenciesWorld.Values); Assert.Contains(filterAddedDependency, snapshot.DependenciesWorld.Values); }
public void TFromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyTop1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"":""TopDependency1"", ""Caption"":""TopDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyChild1 = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\childdependency1"", ""Name"":""ChildDependency1"", ""Caption"":""ChildDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"", ""TopLevel"":""false"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelNew1 = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""newdependency1"", ""Name"":""NewDependency1"", ""Caption"":""NewDependency1"", ""SchemaItemType"":""Xxx"", ""Resolved"":""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new [] { dependencyTop1, dependencyChild1 }, topLevelDependencies: new [] { dependencyTop1 }); var changes = new DependenciesChanges(); changes.IncludeAddedChange(dependencyModelNew1); var snapshotFilter = new TestDependenciesSnapshotFilter() .ImplementBeforeAddResult(FilterAction.Cancel, @"tfm1\xxx\newdependency1", null) .ImplementFilterAnyChanges(true); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes, catalogs, new[] { snapshotFilter }, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(projectPath, snapshot.ProjectPath); Assert.Same(catalogs, snapshot.Catalogs); Assert.Single(snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 2); }
public void TFromChanges_UpdatesTopLevelDependencies() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = ITargetFrameworkFactory.Implement("tfm1"); var dependencyTopPrevious = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"": ""TopDependency1"", ""Caption"": ""TopDependency1"", ""SchemaItemType"": ""Xxx"", ""Resolved"": ""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyModelTopAdded = IDependencyModelFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""topdependency1"", ""Name"": ""TopDependency1"", ""Caption"": ""TopDependency1"", ""SchemaItemType"": ""Xxx"", ""Resolved"": ""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var dependencyTopUpdated = IDependencyFactory.FromJson(@" { ""ProviderType"": ""Xxx"", ""Id"": ""tfm1\\xxx\\topdependency1"", ""Name"": ""TopDependency1"", ""Caption"": ""TopDependency1"", ""SchemaItemType"": ""Xxx"", ""Resolved"": ""true"" }", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall); var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new[] { dependencyTopPrevious }, topLevelDependencies: new[] { dependencyTopPrevious }); var changes = new DependenciesChanges(); changes.IncludeAddedChange(dependencyModelTopAdded); var snapshotFilter = new TestDependenciesSnapshotFilter() .ImplementBeforeAddResult(FilterAction.ShouldBeAdded, @"tfm1\xxx\topdependency1", dependencyTopUpdated); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes, catalogs, new[] { snapshotFilter }, new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(dependencyTopUpdated, snapshot.TopLevelDependencies.Single()); }
public void FromChanges_ReportedChangesAfterBeforeRemoveFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\topdependency1", Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = true }; var dependencyChild1 = new TestDependency { ProviderType = "Xxx", Id = "tfm1\\xxx\\childdependency1", Name = "ChildDependency1", Caption = "ChildDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new [] { dependencyTop1, dependencyChild1 }, topLevelDependencies: new [] { dependencyTop1 }); var changes = new DependenciesChangesBuilder(); changes.Removed("Xxx", "topdependency1"); var addedOnRemove = new TestDependency { Id = "SomethingElse", TopLevel = false }; var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeRemoveReject(@"tfm1\xxx\topdependency1", addOrUpdate: addedOnRemove); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.Build(), catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.NotSame(previousSnapshot, snapshot); Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework); Assert.Same(projectPath, snapshot.ProjectPath); Assert.Same(catalogs, snapshot.Catalogs); Assert.Single(snapshot.TopLevelDependencies); AssertEx.CollectionLength(snapshot.DependenciesWorld, 3); Assert.Contains(addedOnRemove, snapshot.DependenciesWorld.Values); }
public void FromChanges_NoChangesAfterBeforeAddFilterDeclinedChange() { const string projectPath = @"c:\somefolder\someproject\a.csproj"; var targetFramework = new TargetFramework("tfm1"); var dependencyTop1 = new TestDependency { ProviderType = "Xxx", Id = Dependency.GetID(targetFramework, "Xxx", "topdependency1"), Name = "TopDependency1", Caption = "TopDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = true }; var dependencyChild1 = new TestDependency { ProviderType = "Xxx", Id = Dependency.GetID(targetFramework, "Xxx", "childdependency1"), Name = "ChildDependency1", Caption = "ChildDependency1", SchemaItemType = "Xxx", Resolved = true, TopLevel = false }; var dependencyModelNew1 = new TestDependencyModel { ProviderType = "Xxx", Id = "newdependency1", Name = "NewDependency1", Caption = "NewDependency1", SchemaItemType = "Xxx", Resolved = true, Icon = KnownMonikers.Uninstall, ExpandedIcon = KnownMonikers.Uninstall }; var catalogs = IProjectCatalogSnapshotFactory.Create(); var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement( projectPath: projectPath, targetFramework: targetFramework, catalogs: catalogs, dependenciesWorld: new [] { dependencyTop1, dependencyChild1 }, topLevelDependencies: new [] { dependencyTop1 }); var changes = new DependenciesChangesBuilder(); changes.Added(dependencyModelNew1); var snapshotFilter = new TestDependenciesSnapshotFilter() .BeforeAddReject(@"tfm1\xxx\newdependency1"); var snapshot = TargetedDependenciesSnapshot.FromChanges( projectPath, previousSnapshot, changes.Build(), catalogs, ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter), new Dictionary <string, IProjectDependenciesSubTreeProvider>(), null); Assert.Same(previousSnapshot, snapshot); }