public void DependenciesSubTreeProviderBase_ProcessDependenciesChanges_WhenAnyChangesFalse_ShouldSkip() { var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""rulenameResolved"": { ""After"": { ""Items"": { ""item21"": { ""OriginalItemSpec"":""item1"" }, ""item22"": { ""OriginalItemSpec"":""item2"" }, ""itemWithoutOriginalItemSpec"": { } }, ""RuleName"":""rulenameResolved"" }, ""Before"": { ""Items"": { ""resolvedItemTobeRemoved"": { ""OriginalItemSpec"":""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"" } }, ""RuleName"":""rulenameResolved"" }, ""Difference"": { ""AddedItems"": [ ""item21"", ""item22"", ""itemWithoutOriginalItemSpec"", ""itemWithoutPropertiesInAfter"" ], ""ChangedItems"": [ ], ""RemovedItems"": [ ""resolvedItemTobeRemoved"" ], ""AnyChanges"": ""false"" }, }, ""rulenameUnresolved"": { ""After"": { ""Items"": { ""item1"": { }, ""item2"": { }, ""item3"": { }, ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"": { } }, ""RuleName"":""rulenameUnresolved"" }, ""Difference"": { ""AddedItems"": [ ""item1"", ""item2"", ""item3"" ], ""ChangedItems"": [ ], ""RemovedItems"": [ ""item4"", ""itemNotInRootNode"", ""itemWithoutPropertiesInAfter"" ], ""AnyChanges"": ""false"" }, } } }"); var rootNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""MyRootNode"" } }"); var item4Node = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""item4"", ""ItemType"": ""myUnresolvedItemType"" } }"); var resolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""resolvedItemTobeRemoved"", ""ItemType"": ""myUnresolvedItemType"" } }"); rootNode.AddChild(item4Node); rootNode.AddChild(resolvedItemTobeRemovedNode); var catalogs = IProjectCatalogSnapshotFactory.ImplementRulesWithItemTypes( new Dictionary <string, string> { { "rulenameResolved", "myResolvedItemType" }, { "rulenameUnresolved", "myUnresolvedItemType" } }); var provider = new TestableDependenciesSubTreeProviderBase(); // set itemTypes to process provider.SetResolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameResolved")); provider.SetUnresolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameUnresolved")); provider.SetRootNode(rootNode); // Act var resultChanges = provider.TestProcessDependenciesChanges(projectSubscriptionUpdate, catalogs); // Assert Assert.NotNull(resultChanges); Assert.Equal(0, resultChanges.AddedNodes.Count); Assert.Equal(0, resultChanges.RemovedNodes.Count); }
public void DependenciesSubTreeProviderBase_ProcessDependenciesChanges() { var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{ ""ProjectChanges"": { ""rulenameResolved"": { ""After"": { ""Items"": { ""item21"": { ""OriginalItemSpec"":""item1"" }, ""item22"": { ""OriginalItemSpec"":""item2"" }, ""itemWithoutOriginalItemSpec"": { }, ""unresolvedItemTobeRemoved"": { ""OriginalItemSpec"":""unresolvedItemTobeRemoved"" }, }, ""RuleName"":""rulenameResolved"" }, ""Before"": { ""Items"": { ""resolvedItemTobeRemoved"": { ""OriginalItemSpec"":""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"" }, ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"": { ""OriginalItemSpec"":""nonExistentUnresolvedOriginalItemSpec"" }, }, ""RuleName"":""rulenameResolved"" }, ""Difference"": { ""AddedItems"": [ ""item21"", ""item22"", ""itemWithoutOriginalItemSpec"", ""itemWithoutPropertiesInAfter"", ""unresolvedItemTobeRemoved"" ], ""ChangedItems"": [ ], ""RemovedItems"": [ ""resolvedItemTobeRemoved"", ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"" ], ""AnyChanges"": ""true"" }, }, ""rulenameUnresolved"": { ""After"": { ""Items"": { ""item1"": { }, ""item2"": { }, ""item3"": { }, ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"": { }, ""unresolvedItemTobeRemoved"": { } }, ""RuleName"":""rulenameUnresolved"" }, ""Difference"": { ""AddedItems"": [ ""item1"", ""item2"", ""item3"" ], ""ChangedItems"": [ ], ""RemovedItems"": [ ""item4"", ""itemNotInRootNode"", ""itemWithoutPropertiesInAfter"" ], ""AnyChanges"": ""true"" }, }, ""rulenameUnknown"": { ""After"": { ""Items"": { ""shouldNotApper"": { } }, ""RuleName"":""rulenameUnknown"" }, ""Difference"": { ""AddedItems"": [ ""shouldNotApper"" ], ""ChangedItems"": [ ], ""RemovedItems"": [ ], ""AnyChanges"": ""true"" }, } } }"); var rootNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""MyRootNode"" } }"); var item4Node = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""item4"", ""ItemType"": ""myUnresolvedItemType"" } }"); var resolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"", ""ItemType"": ""myUnresolvedItemType"" } }"); var unresolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""unresolvedItemTobeRemoved"", ""ItemType"": ""myUnresolvedItemType"" } }"); var unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode = IDependencyNodeFactory.FromJson(@" { ""Id"": { ""ProviderType"": ""MyProvider"", ""ItemSpec"": ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"", ""ItemType"": ""myUnresolvedItemType"" } }"); rootNode.AddChild(item4Node); rootNode.AddChild(resolvedItemTobeRemovedNode); rootNode.AddChild(unresolvedItemTobeRemovedNode); rootNode.AddChild(unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode); var catalogs = IProjectCatalogSnapshotFactory.ImplementRulesWithItemTypes( new Dictionary <string, string> { { "rulenameResolved", "myResolvedItemType" }, { "rulenameUnresolved", "myUnresolvedItemType" }, { "unresolvedItemTobeRemoved", "myUnresolvedItemType" }, { "unresolvedItemTobeAddedInsteadOfRemovedResolvedItem", "myUnresolvedItemType" } }); var provider = new TestableDependenciesSubTreeProviderBase(); // set itemTypes to process provider.SetResolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameResolved")); provider.SetUnresolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameUnresolved")); provider.SetRootNode(rootNode); // Act var resultChanges = provider.TestProcessDependenciesChanges(projectSubscriptionUpdate, catalogs); // Assert Assert.NotNull(resultChanges); Assert.Equal(5, resultChanges.AddedNodes.Count); var addedNodesArray = resultChanges.AddedNodes.ToArray(); // unresolved items added first Assert.False(addedNodesArray[0].Properties.ContainsKey("OriginalItemSpec")); Assert.False(addedNodesArray[0].Resolved); Assert.Equal("item3", addedNodesArray[0].Caption); Assert.False(addedNodesArray[1].Properties.ContainsKey("OriginalItemSpec")); Assert.False(addedNodesArray[1].Resolved); Assert.Equal("unresolvedItemTobeAddedInsteadOfRemovedResolvedItem", addedNodesArray[1].Caption); Assert.True(addedNodesArray[2].Properties.ContainsKey("OriginalItemSpec")); Assert.True(addedNodesArray[2].Resolved); Assert.Equal("item1", addedNodesArray[2].Caption); Assert.True(addedNodesArray[3].Properties.ContainsKey("OriginalItemSpec")); Assert.True(addedNodesArray[3].Resolved); Assert.Equal("item2", addedNodesArray[3].Caption); Assert.True(addedNodesArray[4].Properties.ContainsKey("OriginalItemSpec")); Assert.True(addedNodesArray[4].Resolved); Assert.Equal("unresolvedItemTobeRemoved", addedNodesArray[4].Caption); Assert.Equal(4, resultChanges.RemovedNodes.Count); var removedNodesArray = resultChanges.RemovedNodes.ToArray(); Assert.Equal(item4Node.Id, removedNodesArray[0].Id); Assert.Equal(resolvedItemTobeRemovedNode.Id, removedNodesArray[1].Id); Assert.Equal(unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode.Id, removedNodesArray[2].Id); Assert.Equal(unresolvedItemTobeRemovedNode.Id, removedNodesArray[3].Id); }