Example #1
0
        public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_UpdateDependency()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var snapshotJson = @"
{
    ""NodesCache"": [ 
        {
            ""Id"": {
                ""ProviderType"": ""NuGetDependency"",
                ""ItemSpec"": ""tfm1/Package2/1.0.0"",
                ""ItemType"": ""PackageReference""
            }
        }
    ],
    ""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""
            }
        }
    ]
}";

            provider.LoadSnapshotFromJson(snapshotJson);

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

            var itemsSpec = "tfm1/Package2/1.0.0";

            // Act
            provider.UpdateDependencyInSnapshot(itemsSpec, sampleDependencyProperties);

            // Assert
            // check node was updated
            var resultVersion = provider.GetCurrentSnapshotDependencyProperty(
                itemsSpec, "Version");

            Assert.Equal("3.0.0", resultVersion);

            // check node was removed form cache
            Assert.False(provider.GetCurrentSnapshotNodesCache().Any(x => x.Equals(itemsSpec)));
        }
        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"": """",
                ""IsImplicitlyDefined"":""true""
            }
        },
        {
            ""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"));

            Assert.Equal("True", provider.GetCurrentSnapshotDependencyProperty("tfm1/Package3/2.0.0", "IsImplicitlyDefined"));
        }