示例#1
0
        public async Task NuGetDependenciesSubTreeProvider_SearchAsync()
        {
            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);

            var rootNodeNode  = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/Package2/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}");
            var searchResults = await provider.SearchAsync(rootNodeNode, "ass");

            Assert.NotNull(searchResults);
            Assert.Equal(2, searchResults.Count());

            var searchResultsArray = searchResults.ToArray();

            Assert.True(searchResultsArray[0] is PackageAssemblyDependencyNode);
            Assert.Equal("Assembly1", searchResultsArray[0].Caption);
            Assert.False(string.IsNullOrEmpty(searchResultsArray[0].Id.UniqueToken));

            Assert.True(searchResultsArray[1] is PackageAssemblyDependencyNode);
            Assert.Equal("FrameworkAssembly1", searchResultsArray[1].Caption);
            Assert.False(string.IsNullOrEmpty(searchResultsArray[1].Id.UniqueToken));
        }