Ejemplo n.º 1
0
        public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_RemoveDependency()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

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

            var childNodeInCache = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/PackageChild1/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}");

            var itemSpec = "tfm1/Package2/1.0.0";

            provider.LoadSnapshotFromJson(snapshotJson);
            provider.AddChildToNodeInCache(itemSpec, childNodeInCache);

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

            // Act
            provider.RemoveDependencyFromSnapshot(itemSpec);

            // Assert
            // check node and it's children were removed form cache
            var cacheNodes = provider.GetCurrentSnapshotNodesCache();

            Assert.Equal(1, cacheNodes.Count());
            Assert.Equal("tfm1/PackageToStayInCache/1.0.0", cacheNodes.First());
        }