Exemplo n.º 1
0
        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)));
                }
            }
        }
Exemplo n.º 2
0
        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)));
                }
            }
        }
Exemplo n.º 3
0
        public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_AddDependency()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var snapshotJson = @"
{
    ""NodesCache"": [ ],
    ""DependenciesWorld"": [
        {
            ""ItemSpec"": ""tfm1/Package2/1.0.0"",
            ""Properties"": {
                ""Name"": ""Package2"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Package"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": ""Package3/2.0.0;NotExistentPackage/2.0.0;Assembly1/1.0.0;FrameworkAssembly1/4.0.0;SomeUnknown/1.0.0""
            }
        },
        {
            ""ItemSpec"": ""tfm1/Package3/2.0.0"",
            ""Properties"": {
                ""Name"": ""Package3"",
                ""Version"": ""2.0.0"",
                ""Type"": ""Package"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/Assembly1/1.0.0"",
            ""Properties"": {
                ""Name"": ""Assembly1"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Assembly"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/FrameworkAssembly1/4.0.0"",
            ""Properties"": {
                ""Name"": ""FrameworkAssembly1"",
                ""Version"": ""4.0.0"",
                ""Type"": ""FrameworkAssembly"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/SomeUnknown/1.0.0"",
            ""Properties"": {
                ""Name"": ""SomeUnknown"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Xxxx"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        }
    ]
}";

            provider.LoadSnapshotFromJson(snapshotJson);

            // Add a dependency
            var sampleDependencyProperties = new Dictionary <string, string>
            {
                { "Name", "Package2" },
                { "Version", "3.0.0" }
            }.ToImmutableDictionary();

            provider.AddDependencyToSnapshot("tfm1/Package4/1.0.0", sampleDependencyProperties);

            var currentSnapshotDependencies = provider.GetCurrentSnapshotDependenciesWorld();

            Assert.True(currentSnapshotDependencies.Contains("tfm1/Package4/1.0.0"));

            // Add a target
            provider.AddDependencyToSnapshot("tfm1", sampleDependencyProperties);

            var currentSnapshotTargets = provider.GetCurrentSnapshotTargets();

            Assert.True(currentSnapshotTargets.Contains("tfm1"));
        }