public void NuGetDependenciesSubTreeProvider_ProcessDependenciesChanges_EmptyTreeAndBothResolvedAndUnresolvedAreProvided( string projectSubscriptionUpdateJson, string existingTopLevelNodesJson, string existingDependenciesChanges) { // Arrange var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(projectSubscriptionUpdateJson); var mockRootNode = IDependencyNodeFactory.Implement(existingTopLevelNodesJson); var provider = new TestableNuGetDependenciesSubTreeProvider(); provider.SetRootNode(mockRootNode); // Act var resultDependenciesChange = provider.TestDependenciesChanged(projectSubscriptionUpdate, catalogs: null); // Assert // check that DependenciesChange returned is as expected var expectedResult = DependenciesChangeFactory.FromJson(existingDependenciesChanges); Assert.True(DependenciesChangeFactory.AreEqual(expectedResult, resultDependenciesChange)); // Check if all added items were added to Snapshot var currentSnapshot = provider.GetCurrentSnapshotDependenciesWorld(); foreach (var addedNode in expectedResult.AddedNodes) { if (addedNode.Id.ItemSpec.Contains("/")) { // if it is a resolved package Assert.True(currentSnapshot.Any(x => x.Equals(addedNode.Id.ItemSpec, StringComparison.OrdinalIgnoreCase))); } } }
public void NuGetDependenciesSubTreeProvider_ProcessDependenciesChanges( string projectSubscriptionUpdateJson, string existingTopLevelNodesJson, string packageToTestVersionUpdate, string existingDependenciesChanges) { // Arrange var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(projectSubscriptionUpdateJson); var mockRootNode = IDependencyNodeFactory.Implement(existingTopLevelNodesJson); var provider = new TestableNuGetDependenciesSubTreeProvider(); provider.SetRootNode(mockRootNode); // Act var resultDependenciesChange = provider.TestDependenciesChanged(projectSubscriptionUpdate, catalogs: null); // Assert // Check that for updated/changed nodes, properties were updated var propertyToCheck = "Version"; var itemsProperties = projectSubscriptionUpdate.ProjectChanges.Values .Where(y => y.Difference.AnyChanges && y.Difference.ChangedItems.Any(x => x.Equals(packageToTestVersionUpdate))) .Select(x => x.After.Items) .FirstOrDefault(); var expectedPropertyValue = itemsProperties[packageToTestVersionUpdate][propertyToCheck]; var properties = provider.GetDependencyProperties(packageToTestVersionUpdate); Assert.Equal(expectedPropertyValue, properties[propertyToCheck]); // check that DependenciesChange returned is as expected var expectedResult = DependenciesChangeFactory.FromJson(existingDependenciesChanges); Assert.True(DependenciesChangeFactory.AreEqual(expectedResult, resultDependenciesChange)); // Check if all added items were added to Snapshot var currentSnapshot = provider.GetCurrentSnapshotDependenciesWorld(); foreach (var addedNode in expectedResult.AddedNodes) { if (addedNode.Id.ItemSpec.Contains("/")) { // if it is a resolved package Assert.True(currentSnapshot.Any(x => x.Equals(addedNode.Id.ItemSpec, StringComparison.OrdinalIgnoreCase))); } } }