public void CreateGroupNodeViewModel()
        {
            var project = UnconfiguredProjectFactory.Create();

            var dependencyModel = new TestDependencyModel
            {
                ProviderType     = "MyProvider1",
                Id               = "ZzzDependencyRoot",
                OriginalItemSpec = "ZzzDependencyRoot",
                Caption          = "ZzzDependencyRoot",
                Icon             = KnownMonikers.AboutBox
            };

            var subTreeProvider1 = IProjectDependenciesSubTreeProviderFactory.Implement(
                providerType: "MyProvider1",
                createRootDependencyNode: dependencyModel);
            var subTreeProvider2 = IProjectDependenciesSubTreeProviderFactory.Implement(
                providerType: "MyProvider2");

            var factory = new TestableDependenciesViewModelFactory(project, new[] { subTreeProvider1, subTreeProvider2 });

            var result = factory.CreateGroupNodeViewModel("MyProvider1", maximumDiagnosticLevel: DiagnosticLevel.None);

            Assert.NotNull(result);
            Assert.Equal("ZzzDependencyRoot", result !.Caption);
            Assert.Equal(KnownMonikers.AboutBox, result.Icon);
        }
Beispiel #2
0
        public void FromChanges_UpdatesLevelDependencies()
        {
            var targetFramework = new TargetFramework("tfm1");

            var dependencyPrevious = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "Dependency1",
                Caption          = "Dependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var dependencyModelAdded = new TestDependencyModel
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "Dependency1",
                Caption          = "Dependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true,
                Icon             = KnownMonikers.Uninstall,
                ExpandedIcon     = KnownMonikers.Uninstall
            };

            var dependencyUpdated = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "Dependency1",
                Caption          = "Dependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                targetFramework,
                catalogs,
                ImmutableArray.Create <IDependency>(dependencyPrevious));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelAdded);

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddAccept("Xxx", "dependency1", dependencyUpdated);

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                previousSnapshot,
                changes.TryBuildChanges() !,
                catalogs,
                ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter));

            Assert.True(snapshotFilter.Completed);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(dependencyUpdated, snapshot.Dependencies.Single());
        }
        public void FromChanges_AddingToEmpty()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = TargetedDependenciesSnapshot.CreateEmpty(projectPath, targetFramework, catalogs);

            var resolvedTop = new TestDependencyModel
            {
                ProviderType = "Xxx",
                Id           = "dependency1",
                Name         = "Dependency1",
                Caption      = "Dependency1",
                Resolved     = true,
                TopLevel     = true,
                Flags        = DependencyTreeFlags.Resolved,
                Icon         = KnownMonikers.Uninstall,
                ExpandedIcon = KnownMonikers.Uninstall
            };

            var unresolved = new TestDependencyModel
            {
                ProviderType = "Xxx",
                Id           = "dependency2",
                Name         = "Dependency2",
                Caption      = "Dependency2",
                Resolved     = false,
                TopLevel     = false,
                Flags        = DependencyTreeFlags.Unresolved,
                Icon         = KnownMonikers.Uninstall,
                ExpandedIcon = KnownMonikers.Uninstall
            };

            var changes = new DependenciesChangesBuilder();

            changes.Added(resolvedTop);
            changes.Added(unresolved);

            const string updatedProjectPath = "updatedProjectPath";

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                updatedProjectPath,
                previousSnapshot,
                changes.TryBuildChanges() !,
                catalogs,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(updatedProjectPath, snapshot.ProjectPath);
            Assert.Same(catalogs, snapshot.Catalogs);
            Assert.False(snapshot.HasReachableVisibleUnresolvedDependency);
            AssertEx.CollectionLength(snapshot.DependenciesWorld, 2);
            AssertEx.CollectionLength(snapshot.TopLevelDependencies, 1);
            Assert.True(resolvedTop.Matches(snapshot.TopLevelDependencies.Single(), targetFramework));
            Assert.True(resolvedTop.Matches(snapshot.DependenciesWorld["tfm1\\Xxx\\dependency1"], targetFramework));
            Assert.True(unresolved.Matches(snapshot.DependenciesWorld["tfm1\\Xxx\\dependency2"], targetFramework));
        }
        public void WhenCreatingUnrelatedDependenciesWithSameIcons_BothUseSameIconSet()
        {
            var model1 = new TestDependencyModel
            {
                ProviderType           = "alpha",
                Id                     = "modelOne",
                Icon                   = KnownMonikers.Path,
                ExpandedIcon           = KnownMonikers.PathIcon,
                UnresolvedIcon         = KnownMonikers.PathListBox,
                UnresolvedExpandedIcon = KnownMonikers.PathListBoxItem
            };

            var model2 = new TestDependencyModel
            {
                ProviderType           = "beta",
                Id                     = "modelTwo",
                Icon                   = KnownMonikers.Path,
                ExpandedIcon           = KnownMonikers.PathIcon,
                UnresolvedIcon         = KnownMonikers.PathListBox,
                UnresolvedExpandedIcon = KnownMonikers.PathListBoxItem
            };

            var targetFramework = new TargetFramework("Tfm1");

            var dependency1 = new Dependency(model1, targetFramework, @"C:\Foo\Project.csproj");
            var dependency2 = new Dependency(model2, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Same(dependency1.IconSet, dependency2.IconSet);
        }
        public async Task WhenOneTargetSnapshotAndDependencySupportsHierarchyAndIsUnresolved_ShouldRead()
        {
            var dependencyModelRootYyy = new TestDependencyModel
            {
                ProviderType = "Yyy",
                Id           = "YyyDependencyRoot",
                Name         = "YyyDependencyRoot",
                Caption      = "YyyDependencyRoot",
                Resolved     = true
            };

            var dependencyYyyExisting = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyExisting",
                Name           = "dependencyExisting",
                Caption        = "DependencyExisting",
                SchemaItemType = "Yyy",
                Resolved       = false,
                Flags          = DependencyTreeFlags.SupportsHierarchy
            };

            var dependenciesRoot = new TestProjectTree
            {
                Caption  = "MyDependencies",
                Children =
                {
                    new TestProjectTree
                    {
                        Caption  = "YyyDependencyRoot",
                        FilePath = "YyyDependencyRoot",
                        Children =
                        {
                            new TestProjectTree
                            {
                                Caption   = "DependencyExisting",
                                FilePath  = "tfm1\\yyy\\dependencyExisting",
                                CustomTag = "ShouldBeCleanedSinceNodeWillBeRecreated",
                                Flags     = DependencyTreeFlags.Resolved
                            }
                        }
                    }
                }
            };

            var provider = CreateProvider(rootModels: new[] { dependencyModelRootYyy });

            var snapshot = GetSnapshot((_tfm1, new[] { dependencyYyyExisting }));

            // Act
            var resultTree = await provider.BuildTreeAsync(dependenciesRoot, snapshot);

            // Assert
            var expectedFlatHierarchy =
                @"Caption=MyDependencies, FilePath=, IconHash=325248080, ExpandedIconHash=325248080, Rule=, IsProjectItem=False, CustomTag=
    Caption=YyyDependencyRoot, FilePath=YyyDependencyRoot, IconHash=0, ExpandedIconHash=0, Rule=, IsProjectItem=False, CustomTag=
        Caption=DependencyExisting, FilePath=tfm1\yyy\dependencyExisting, IconHash=325248665, ExpandedIconHash=325248817, Rule=, IsProjectItem=True, CustomTag=";

            Assert.Equal(expectedFlatHierarchy, ToTestDataString((TestProjectTree)resultTree));
        }
Beispiel #6
0
        public void CreateRootViewModel()
        {
            var project = UnconfiguredProjectFactory.Create();

            var dependencyModel = new TestDependencyModel
            {
                ProviderType = "MyProvider1",
                Id           = "ZzzDependencyRoot",
                Name         = "ZzzDependencyRoot",
                Caption      = "ZzzDependencyRoot",
                Icon         = KnownMonikers.AboutBox
            };

            var subTreeProvider1 = IProjectDependenciesSubTreeProviderFactory.Implement(
                providerType: "MyProvider1",
                createRootDependencyNode: dependencyModel);
            var subTreeProvider2 = IProjectDependenciesSubTreeProviderFactory.Implement(
                providerType: "MyProvider2");

            var factory = new TestableDependenciesViewModelFactory(project, new[] { subTreeProvider1, subTreeProvider2 });

            var result = factory.CreateRootViewModel("MyProvider1", hasUnresolvedDependency: false);

            Assert.NotNull(result);
            Assert.Equal("ZzzDependencyRoot", result.Caption);
            Assert.Equal(KnownMonikers.AboutBox, result.Icon);
        }
Beispiel #7
0
        public void EqualsAndGetHashCode()
        {
            var comparer = DependencyIdComparer.Instance;

            var dependencyModel1 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1"
            };
            var dependencyModel2 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1"
            };
            var dependencyModel3 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId_other"
            };

            var targetFramework = new TargetFramework("tfm1");
            var dependency1     = new Dependency(dependencyModel1, targetFramework, @"C:\Foo\Project.csproj");
            var dependency2     = new Dependency(dependencyModel2, targetFramework, @"C:\Foo\Project.csproj");
            var dependency3     = new Dependency(dependencyModel3, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Equal(dependency1, dependency2, comparer);
            Assert.NotEqual(dependency1, dependency3, comparer);
            Assert.False(comparer.Equals(dependency1, null !));
            Assert.False(comparer.Equals(null !, dependency1 !));
            Assert.Equal(comparer.GetHashCode(dependency1 !), comparer.GetHashCode(dependency2));
            Assert.NotEqual(comparer.GetHashCode(dependency1 !), comparer.GetHashCode(dependency3));
        }
Beispiel #8
0
        public void EqualsAndGetHashCode()
        {
            var model1 = new TestDependencyModel
            {
                Id           = "id1",
                ProviderType = "provider1"
            };

            var model2 = new TestDependencyModel
            {
                Id           = "id1",
                ProviderType = "provider1"
            };

            var model3 = new TestDependencyModel
            {
                Id           = "DIFFERENT",
                ProviderType = "provider1"
            };

            var model4 = new TestDependencyModel
            {
                Id           = "id1",
                ProviderType = "DIFFERENT"
            };

            Assert.True(IDependencyModelEqualityComparer.Instance.Equals(model1, model2));
            Assert.True(IDependencyModelEqualityComparer.Instance.Equals(model2, model1));

            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model1, model3));
            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model3, model1));

            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model1, model4));
            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model4, model1));

            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model3, model4));
            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model4, model3));

            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(model1, null));
            Assert.False(IDependencyModelEqualityComparer.Instance.Equals(null, model1));

            Assert.True(IDependencyModelEqualityComparer.Instance.Equals(null, null));

            Assert.Equal(
                IDependencyModelEqualityComparer.Instance.GetHashCode(model1 !),
                IDependencyModelEqualityComparer.Instance.GetHashCode(model2));

            Assert.NotEqual(
                IDependencyModelEqualityComparer.Instance.GetHashCode(model1 !),
                IDependencyModelEqualityComparer.Instance.GetHashCode(model3));

            Assert.NotEqual(
                IDependencyModelEqualityComparer.Instance.GetHashCode(model1 !),
                IDependencyModelEqualityComparer.Instance.GetHashCode(model4));

            Assert.NotEqual(
                IDependencyModelEqualityComparer.Instance.GetHashCode(model3),
                IDependencyModelEqualityComparer.Instance.GetHashCode(model4));
        }
        public async Task WhenOneTargetSnapshotAndDependencyIsResolved_ShouldRead()
        {
            var dependencyModelRootYyy = new TestDependencyModel
            {
                ProviderType     = "Yyy",
                Id               = "YyyDependencyRoot",
                OriginalItemSpec = "YyyDependencyRoot",
                Caption          = "YyyDependencyRoot",
                Resolved         = true
            };

            var dependencyYyyExisting = new TestDependency
            {
                ProviderType     = "Yyy",
                Id               = "dependencyExisting",
                OriginalItemSpec = "dependencyExisting",
                FilePath         = "dependencyExistingpath",
                Caption          = "DependencyExisting",
                SchemaItemType   = "Yyy",
                Resolved         = true
            };

            var dependenciesRoot = new TestProjectTree
            {
                Caption  = "MyDependencies",
                Children =
                {
                    new TestProjectTree
                    {
                        Caption  = "YyyDependencyRoot",
                        Children =
                        {
                            new TestProjectTree
                            {
                                Caption   = "DependencyExisting",
                                CustomTag = "Untouched",
                                Flags     = ProjectTreeFlags.BrokenReference
                            }
                        }
                    }
                }
            };

            var provider = CreateProvider(rootModels: new[] { dependencyModelRootYyy });

            var snapshot = GetSnapshot((_tfm1, new[] { dependencyYyyExisting }));

            // Act
            var resultTree = await provider.BuildTreeAsync(dependenciesRoot, snapshot);

            // Assert
            var expectedFlatHierarchy =
                @"Caption=MyDependencies, IconHash=325248080, ExpandedIconHash=325248080, Rule=, IsProjectItem=False, CustomTag=
    Caption=YyyDependencyRoot, IconHash=0, ExpandedIconHash=0, Rule=, IsProjectItem=False, CustomTag=
        Caption=DependencyExisting, IconHash=325248088, ExpandedIconHash=325248260, Rule=, IsProjectItem=False, CustomTag=Untouched";

            AssertTestData(expectedFlatHierarchy, resultTree);
        }
        public void Dependency_Id_NoSnapshotTargetFramework(string modelId, string expectedId)
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "xxx", Id = modelId
            };

            var dependency = new Dependency(dependencyModel, new TargetFramework("tfm1"), @"C:\Foo\Project.cspoj");

            Assert.Equal(dependencyModel.ProviderType, dependency.ProviderType);
            Assert.Equal(expectedId, dependency.Id);
        }
        public void Dependency_Id(string modelId, string expectedId)
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = modelId
            };
            var targetFramework = new TargetFramework("tfm");

            var dependency = new Dependency(dependencyModel, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Equal(dependencyModel.ProviderType, dependency.ProviderType);
            Assert.Equal(expectedId, dependency.Id);
        }
        public void FromChanges_AddingToEmpty()
        {
            var targetFramework = new TargetFramework("tfm1");

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = TargetedDependenciesSnapshot.CreateEmpty(targetFramework, catalogs);

            var resolved = new TestDependencyModel
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "Dependency1",
                Caption          = "Dependency1",
                Resolved         = true,
                Flags            = DependencyTreeFlags.Resolved,
                Icon             = KnownMonikers.Uninstall,
                ExpandedIcon     = KnownMonikers.Uninstall
            };

            var unresolved = new TestDependencyModel
            {
                ProviderType     = "Xxx",
                Id               = "dependency2",
                OriginalItemSpec = "Dependency2",
                Caption          = "Dependency2",
                Resolved         = false,
                Flags            = DependencyTreeFlags.Unresolved,
                Icon             = KnownMonikers.Uninstall,
                ExpandedIcon     = KnownMonikers.Uninstall
            };

            var changes = new DependenciesChangesBuilder();

            changes.Added(resolved);
            changes.Added(unresolved);


            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                previousSnapshot,
                changes.TryBuildChanges() !,
                catalogs,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(catalogs, snapshot.Catalogs);
            Assert.True(snapshot.HasVisibleUnresolvedDependency);
            AssertEx.CollectionLength(snapshot.Dependencies, 2);
            Assert.Contains(snapshot.Dependencies, resolved.Matches);
            Assert.Contains(snapshot.Dependencies, unresolved.Matches);
        }
        public void WhenSettingProperties_ExistingIconSetInstanceIsReused()
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId"
            };

            var dependency = (new Dependency(dependencyModel, new TargetFramework("tfm1"), @"C:\Foo\Project.csproj"))
                             .SetProperties(iconSet: new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference));

            var dependencyWithUpdatedIconSet = dependency.SetProperties(iconSet: new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference));

            Assert.Same(dependency.IconSet, dependencyWithUpdatedIconSet.IconSet);
        }
        public void Dependency_HasUnresolvedDependency()
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1", Resolved = true
            };

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency(@"tfm1\providerType\someid1", hasUnresolvedDependency: true);

            var dependency = new Dependency(dependencyModel, new TargetFramework("tfm1"), @"C:\Foo\Project.csproj");

            Assert.True(dependency.HasUnresolvedDependency(mockSnapshot));
            Assert.True(dependency.IsOrHasUnresolvedDependency(mockSnapshot));
        }
        public void Dependency_Constructor_WhenValidModelProvided_ShouldSetAllProperties()
        {
            var mockModel = new TestDependencyModel
            {
                ProviderType           = "xxx",
                Id                     = "mymodelid",
                Name                   = "mymodelname",
                Caption                = "mymodel",
                OriginalItemSpec       = "mymodeloriginal",
                Path                   = "mymodelpath",
                SchemaName             = "MySchema",
                SchemaItemType         = "MySchemaItemType",
                Resolved               = true,
                TopLevel               = true,
                Implicit               = true,
                Visible                = true,
                Priority               = 3,
                Flags                  = DependencyTreeFlags.DependencyFlags.Union(DependencyTreeFlags.GenericDependency),
                Icon                   = KnownMonikers.Path,
                ExpandedIcon           = KnownMonikers.PathIcon,
                UnresolvedIcon         = KnownMonikers.PathListBox,
                UnresolvedExpandedIcon = KnownMonikers.PathListBoxItem,
                Properties             = new Dictionary <string, string> {
                    { "prop1", "val1" }
                }.ToImmutableDictionary(),
                DependencyIDs = new[] { "otherid" }.ToImmutableArray()
            };

            var targetFramework = new TargetFramework("Tfm1");

            var dependency = new Dependency(mockModel, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(mockModel.Name, dependency.Name);
            Assert.Equal(mockModel.Caption, dependency.Caption);
            Assert.Equal(mockModel.OriginalItemSpec, dependency.OriginalItemSpec);
            Assert.Equal(mockModel.Path, dependency.Path);
            Assert.Equal(mockModel.SchemaName, dependency.SchemaName);
            Assert.Equal(mockModel.SchemaItemType, dependency.SchemaItemType);
            Assert.Equal(mockModel.Resolved, dependency.Resolved);
            Assert.Equal(mockModel.TopLevel, dependency.TopLevel);
            Assert.Equal(mockModel.Implicit, dependency.Implicit);
            Assert.Equal(mockModel.Visible, dependency.Visible);
            Assert.Equal(mockModel.Priority, dependency.Priority);
            Assert.Single(dependency.Properties);
            Assert.True(dependency.Properties.ContainsKey("prop1"));
            Assert.Single(dependency.DependencyIDs);
            Assert.Equal("Tfm1\\xxx\\otherid", dependency.DependencyIDs[0]);
            Assert.True(dependency.Flags.Contains(DependencyTreeFlags.Resolved));
            Assert.True(dependency.Flags.Contains(DependencyTreeFlags.DependencyFlags));
        }
        public void FromChanges_NoChangesAfterBeforeAddFilterDeclinedChange()
        {
            var targetFramework = new TargetFramework("tfm1");

            var dependency1 = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "Dependency1",
                Caption          = "Dependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var dependencyModelNew1 = new TestDependencyModel
            {
                ProviderType     = "Xxx",
                Id               = "newdependency1",
                OriginalItemSpec = "NewDependency1",
                Caption          = "NewDependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true,
                Icon             = KnownMonikers.Uninstall,
                ExpandedIcon     = KnownMonikers.Uninstall
            };

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                targetFramework,
                catalogs,
                ImmutableArray.Create <IDependency>(dependency1));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelNew1);

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddReject("Xxx", "newdependency1");

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                previousSnapshot,
                changes.TryBuildChanges() !,
                catalogs,
                ImmutableArray.Create <IDependenciesSnapshotFilter>(snapshotFilter),
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.True(snapshotFilter.Completed);

            Assert.Same(previousSnapshot, snapshot);
        }
        public void FromChanges_WithDependenciesChanges()
        {
            const string previousProjectPath = @"c:\somefolder\someproject\a.csproj";
            const string newProjectPath      = @"c:\somefolder\someproject\b.csproj";

            var catalogs        = IProjectCatalogSnapshotFactory.Create();
            var targetFramework = new TargetFramework("tfm1");
            var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(previousProjectPath, catalogs, targetFramework);

            var previousSnapshot = new DependenciesSnapshot(
                previousProjectPath,
                activeTargetFramework: targetFramework,
                dependenciesByTargetFramework);

            var targetChanges = new DependenciesChangesBuilder();
            var model         = new TestDependencyModel
            {
                ProviderType = "Xxx",
                Id           = "dependency1",
                TopLevel     = true
            };

            targetChanges.Added(model);

            var snapshot = DependenciesSnapshot.FromChanges(
                newProjectPath,
                previousSnapshot,
                targetFramework,
                targetChanges.TryBuildChanges() !,
                catalogs,
                targetFrameworks: ImmutableArray.Create <ITargetFramework>(targetFramework),
                activeTargetFramework: targetFramework,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(newProjectPath, snapshot.ProjectPath);
            Assert.Same(targetFramework, snapshot.ActiveTargetFramework);
            Assert.NotSame(previousSnapshot.DependenciesByTargetFramework, snapshot.DependenciesByTargetFramework);

            var(actualTfm, targetedSnapshot) = Assert.Single(snapshot.DependenciesByTargetFramework);
            Assert.Same(targetFramework, actualTfm);
            var dependency = Assert.Single(targetedSnapshot.TopLevelDependencies);

            Assert.Equal(@"tfm1\Xxx\dependency1", dependency.Id);
            Assert.Equal("Xxx", dependency.ProviderType);
            Assert.Same(dependency, targetedSnapshot.DependenciesWorld.Single().Value);
        }
        public async Task WheEmptySnapshotAndVisibilityMarkerProvided_ShouldDisplaySubTreeRoot()
        {
            var dependencyModelRootYyy = new TestDependencyModel
            {
                ProviderType = "Yyy",
                Id           = "YyyDependencyRoot",
                Name         = "YyyDependencyRoot",
                Caption      = "YyyDependencyRoot",
                Resolved     = true
            };

            var dependencyVisibilityMarker = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "someid",
                Name         = "someid",
                Caption      = "someid",
                Resolved     = false,
                Visible      = false,
                Flags        = DependencyTreeFlags.ShowEmptyProviderRootNode
            };

            var dependenciesRoot = new TestProjectTree
            {
                Caption  = "MyDependencies",
                Children =
                {
                    new TestProjectTree
                    {
                        Caption  = "YyyDependencyRoot",
                        FilePath = "YyyDependencyRoot"
                    }
                }
            };

            var provider = CreateProvider(rootModels: new[] { dependencyModelRootYyy });

            var snapshot = GetSnapshot((_tfm1, new[] { dependencyVisibilityMarker }));

            // Act
            var resultTree = await provider.BuildTreeAsync(dependenciesRoot, snapshot);

            // Assert
            var expectedFlatHierarchy =
                @"Caption=MyDependencies, FilePath=, IconHash=325248080, ExpandedIconHash=325248080, Rule=, IsProjectItem=False, CustomTag=
    Caption=YyyDependencyRoot, FilePath=YyyDependencyRoot, IconHash=0, ExpandedIconHash=0, Rule=, IsProjectItem=False, CustomTag=";

            Assert.Equal(expectedFlatHierarchy, ToTestDataString((TestProjectTree)resultTree));
        }
        public async Task WhenEmptySnapshotAndVisibilityMarkerNotProvided_ShouldHideSubTreeRoot()
        {
            var dependencyModelRootYyy = new TestDependencyModel
            {
                ProviderType     = "Yyy",
                Id               = "YyyDependencyRoot",
                OriginalItemSpec = "YyyDependencyRoot",
                Caption          = "YyyDependencyRoot",
                Resolved         = true
            };

            var dependencyVisibilityMarker = new TestDependency
            {
                ProviderType     = "Yyy",
                Id               = "someid",
                OriginalItemSpec = "someid",
                Caption          = "someid",
                Resolved         = false,
                Visible          = false
            };

            var dependenciesRoot = new TestProjectTree
            {
                Caption  = "MyDependencies",
                Children =
                {
                    new TestProjectTree
                    {
                        Caption = "YyyDependencyRoot"
                    }
                }
            };

            var provider = CreateProvider(rootModels: new[] { dependencyModelRootYyy });

            var snapshot = GetSnapshot((_tfm1, new[] { dependencyVisibilityMarker }));

            // Act
            var resultTree = await provider.BuildTreeAsync(dependenciesRoot, snapshot);

            // Assert
            var expectedFlatHierarchy =
                @"Caption=MyDependencies, IconHash=325248080, ExpandedIconHash=325248080, Rule=, IsProjectItem=False, CustomTag=";

            AssertTestData(expectedFlatHierarchy, resultTree);
        }
        public void Dependency_Alias(string originalItemSpec, string path, string caption, string expectedAlias)
        {
            var dependencyModel = new TestDependencyModel
            {
                ProviderType     = "providerType",
                Id               = "someId",
                OriginalItemSpec = originalItemSpec,
                Path             = path,
                Caption          = caption
            };

            var targetFramework = new TargetFramework("tfm");

            var dependency = new Dependency(dependencyModel, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Equal(expectedAlias, dependency.Alias);
        }
Beispiel #21
0
        public void FromChanges_ProjectPathAndTargetChange()
        {
            const string previousProjectPath = @"c:\somefolder\someproject\a.csproj";
            const string newProjectPath      = @"c:\somefolder\someproject\b.csproj";

            var catalogs        = IProjectCatalogSnapshotFactory.Create();
            var targetFramework = new TargetFramework("tfm1");
            var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(previousProjectPath, catalogs, targetFramework);

            var previousSnapshot = new DependenciesSnapshot(
                previousProjectPath,
                activeTargetFramework: targetFramework,
                dependenciesByTargetFramework);

            var targetChanges = new DependenciesChangesBuilder();
            var model         = new TestDependencyModel
            {
                ProviderType = "Xxx",
                Id           = "dependency1"
            };

            targetChanges.Added(model);
            var changes = new Dictionary <ITargetFramework, IDependenciesChanges> {
                [targetFramework] = targetChanges.Build()
            };

            var snapshot = DependenciesSnapshot.FromChanges(
                newProjectPath,
                previousSnapshot,
                changes.ToImmutableDictionary(),
                catalogs,
                targetFrameworks: ImmutableArray <ITargetFramework> .Empty.Add(targetFramework),
                activeTargetFramework: targetFramework,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(newProjectPath, snapshot.ProjectPath);
            Assert.Same(targetFramework, snapshot.ActiveTargetFramework);
            Assert.NotSame(previousSnapshot.DependenciesByTargetFramework, snapshot.DependenciesByTargetFramework);
            Assert.Equal(@"tfm1\Xxx\dependency1", snapshot.DependenciesByTargetFramework[targetFramework].DependenciesWorld.First().Value.Id);
        }
        public void FromChanges_DifferentModelIdCapitalisation()
        {
            var targetFramework = new TargetFramework("tfm1");

            var dependencyPrevious = new TestDependency
            {
                ProviderType = "Xxx",
                Id           = "dependency1",
                Resolved     = false
            };

            var dependencyModelUpdated = new TestDependencyModel
            {
                ProviderType = "XXX",         // changed case
                Id           = "DEPENDENCY1", // changed case
                Resolved     = true
            };

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                targetFramework,
                catalogs,
                ImmutableArray.Create <IDependency>(dependencyPrevious));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelUpdated);

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                previousSnapshot,
                changes.TryBuildChanges() !,
                catalogs,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            var dependency = Assert.Single(snapshot.Dependencies);

            Assert.Equal("DEPENDENCY1", dependency.Id);
            Assert.Equal("XXX", dependency.ProviderType);
            Assert.True(dependency.Resolved);
        }
        public void Dependency_Constructor_WhenRequiredParamsNotProvided_ShouldThrow()
        {
            var targetFramework       = new TargetFramework("tfm");
            var containingProjectPath = @"c:\SomePath\SomeProject.csproj";

            Assert.Throws <ArgumentNullException>("dependencyModel", () =>
            {
                new Dependency(null, targetFramework, containingProjectPath);
            });

            Assert.Throws <ArgumentNullException>("ProviderType", () =>
            {
                var dependencyModel = new TestDependencyModel {
                    ProviderType = null, Id = "Id"
                };
                new Dependency(dependencyModel, targetFramework, containingProjectPath);
            });

            Assert.Throws <ArgumentNullException>("Id", () =>
            {
                var dependencyModel = new TestDependencyModel {
                    ProviderType = "providerType", Id = null
                };
                new Dependency(dependencyModel, targetFramework, containingProjectPath);
            });

            Assert.Throws <ArgumentNullException>("targetFramework", () =>
            {
                var dependencyModel = new TestDependencyModel {
                    ProviderType = "providerType", Id = "id"
                };
                new Dependency(dependencyModel, null, containingProjectPath);
            });

            Assert.Throws <ArgumentNullException>("containingProjectPath", () =>
            {
                var dependencyModel = new TestDependencyModel {
                    ProviderType = "providerType", Id = "id"
                };
                new Dependency(dependencyModel, targetFramework: targetFramework, containingProjectPath: null);
            });
        }
        public void Dependency_SetProperties()
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId"
            };

            var dependency = new Dependency(dependencyModel, new TargetFramework("tfm1"), @"C:\Foo\Project.csproj");

            var newDependency = dependency.SetProperties(
                caption: "newcaption",
                resolved: true,
                flags: DependencyTreeFlags.BaseReferenceFlags,
                dependencyIDs: ImmutableArray.Create("aaa"));

            Assert.Equal("newcaption", newDependency.Caption);
            Assert.True(newDependency.Resolved);
            Assert.True(newDependency.Flags.Equals(DependencyTreeFlags.BaseReferenceFlags));
            Assert.Single(newDependency.DependencyIDs);
            Assert.Equal("aaa", newDependency.DependencyIDs[0]);
        }
        public void FromChanges_WithDependenciesChanges()
        {
            var catalogs        = IProjectCatalogSnapshotFactory.Create();
            var targetFramework = new TargetFramework("tfm1");
            var dependenciesByTargetFramework = CreateDependenciesByTargetFramework(catalogs, targetFramework);

            var previousSnapshot = new DependenciesSnapshot(
                activeTargetFramework: targetFramework,
                dependenciesByTargetFramework);

            var targetChanges = new DependenciesChangesBuilder();
            var model         = new TestDependencyModel
            {
                ProviderType = "Xxx",
                Id           = "dependency1"
            };

            targetChanges.Added(model);

            var snapshot = DependenciesSnapshot.FromChanges(
                previousSnapshot,
                targetFramework,
                targetChanges.TryBuildChanges() !,
                catalogs,
                targetFrameworks: ImmutableArray.Create <TargetFramework>(targetFramework),
                activeTargetFramework: targetFramework,
                ImmutableArray <IDependenciesSnapshotFilter> .Empty,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(targetFramework, snapshot.ActiveTargetFramework);
            Assert.NotSame(previousSnapshot.DependenciesByTargetFramework, snapshot.DependenciesByTargetFramework);

            var(actualTfm, targetedSnapshot) = Assert.Single(snapshot.DependenciesByTargetFramework);
            Assert.Same(targetFramework, actualTfm);
            var dependency = Assert.Single(targetedSnapshot.Dependencies);

            Assert.Equal("dependency1", dependency.Id);
            Assert.Equal("Xxx", dependency.ProviderType);
        }
        public void Dependency_Constructor_WhenOptionalValuesNotProvided_ShouldSetDefaults()
        {
            var mockModel = new TestDependencyModel
            {
                ProviderType = "xxx",
                Id           = "mymodel"
            };

            var dependency = new Dependency(mockModel, new TargetFramework("tfm1"), @"C:\Foo\Project.csproj");

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(string.Empty, dependency.Name);
            Assert.Equal(string.Empty, dependency.Caption);
            Assert.Equal(string.Empty, dependency.OriginalItemSpec);
            Assert.Equal(string.Empty, dependency.Path);
            Assert.Equal("Folder", dependency.SchemaName);
            Assert.Equal("Folder", dependency.SchemaItemType);
            AssertEx.CollectionLength(dependency.Properties, 2);
            Assert.True(dependency.Properties.ContainsKey("Identity"));
            Assert.True(dependency.Properties.ContainsKey("FullPath"));
            Assert.Empty(dependency.DependencyIDs);
        }
        public void Dependency_EqualsAndGetHashCode()
        {
            var dependencyModel1 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1"
            };
            var dependencyModel2 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1"
            };
            var dependencyModel3 = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId_other"
            };

            var targetFramework = new TargetFramework("tfm1");
            var dependency1     = new Dependency(dependencyModel1, targetFramework, @"C:\Foo\Project.csproj");
            var dependency2     = new Dependency(dependencyModel2, targetFramework, @"C:\Foo\Project.csproj");
            var dependency3     = new Dependency(dependencyModel3, targetFramework, @"C:\Foo\Project.csproj");

            Assert.Equal(dependency1, dependency2);
            Assert.NotEqual(dependency1, dependency3);
            Assert.False(dependency1.Equals(other: null));
            Assert.Equal(dependency1.GetHashCode(), dependency2.GetHashCode());
            Assert.NotEqual(dependency1.GetHashCode(), dependency3.GetHashCode());
        }
        public void Dependency_SetProperties_PreservesDependencyIDs()
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = "cube", DependencyIDs = ImmutableList <string> .Empty.Add("glass")
            };
            var dependency = new Dependency(dependencyModel, new TargetFramework("tfm1"), @"C:\Foo\Project.csproj");

            var expectedId           = "tfm1\\providerType\\cube";
            var expectedDependencyId = "tfm1\\providerType\\glass";

            Assert.Equal(expectedId, dependency.Id);
            Assert.Single(dependency.DependencyIDs);
            Assert.Equal(expectedDependencyId, dependency.DependencyIDs[0]);

            var newDependency = dependency.SetProperties(
                caption: "newcaption");

            Assert.Equal("newcaption", newDependency.Caption);

            Assert.Equal(expectedId, newDependency.Id);
            Assert.Single(newDependency.DependencyIDs);
            Assert.Equal(expectedDependencyId, newDependency.DependencyIDs[0]);
        }
        public void Dependency_DependencyIDsProperty()
        {
            var dependencyModel1 = new TestDependencyModel
            {
                ProviderType  = "providerType",
                Id            = "someId1",
                DependencyIDs = new[] { "someId2", "someId_other" }.ToImmutableArray()
            };
            var dependencyModel2 = new TestDependencyModel
            {
                ProviderType = "providerType",
                Id           = "someId2"
            };
            var dependencyModel3 = new TestDependencyModel
            {
                ProviderType = "providerType",
                Id           = "someId_other"
            };

            var targetFramework = new TargetFramework("Tfm1");

            var projectPath = "projectPath";

            var dependency1 = new Dependency(dependencyModel1, targetFramework, projectPath);
            var dependency2 = new Dependency(dependencyModel2, targetFramework, projectPath);
            var dependency3 = new Dependency(dependencyModel3, targetFramework, projectPath);

            var children = new IDependency[] { dependency1, dependency2, dependency3 }.ToImmutableDictionary(d => d.Id);

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementMock(targetFramework: targetFramework);

            mockSnapshot.Setup(x => x.DependenciesWorld).Returns(children);

            AssertEx.CollectionLength(dependency1.DependencyIDs, 2);
            Assert.Contains(dependency1.DependencyIDs, x => x.Equals(dependency2.Id));
            Assert.Contains(dependency1.DependencyIDs, x => x.Equals(dependency3.Id));
        }
        public async Task WhenOneTargetSnapshotWithExistingDependencies_ShouldApplyChanges()
        {
            var dependencyModelRootXxx = new TestDependencyModel
            {
                ProviderType     = "Xxx",
                Id               = "XxxDependencyRoot",
                OriginalItemSpec = "XxxDependencyRoot",
                Caption          = "XxxDependencyRoot",
                Resolved         = true
            };

            var dependencyModelRootYyy = new TestDependencyModel
            {
                ProviderType     = "Yyy",
                Id               = "YyyDependencyRoot",
                OriginalItemSpec = "YyyDependencyRoot",
                Caption          = "YyyDependencyRoot"
            };

            var dependencyXxx1 = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "dependency1",
                OriginalItemSpec = "dependency1",
                FilePath         = "dependencyXxxpath",
                Caption          = "Dependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var dependencyYyy1 = new TestDependency
            {
                ProviderType     = "Yyy",
                Id               = "dependency1",
                OriginalItemSpec = "dependency1",
                FilePath         = "dependencyYyypath",
                Caption          = "Dependency1",
                SchemaItemType   = "Yyy",
                Resolved         = true
            };

            var dependencyYyyExisting = new TestDependency
            {
                ProviderType     = "Yyy",
                Id               = "dependencyExisting",
                OriginalItemSpec = "dependencyExisting",
                FilePath         = "dependencyExistingPath",
                Caption          = "DependencyExisting",
                SchemaItemType   = "Yyy",
                Resolved         = true
            };

            var dependenciesRoot = new TestProjectTree
            {
                Caption  = "MyDependencies",
                Children =
                {
                    new TestProjectTree
                    {
                        Caption = "OldRootChildToBeRemoved"
                    },
                    new TestProjectTree
                    {
                        Caption  = "YyyDependencyRoot",
                        Children =
                        {
                            new TestProjectTree
                            {
                                Caption = "DependencyExisting"
                            }
                        }
                    }
                }
            };

            var provider = CreateProvider(rootModels: new[] { dependencyModelRootXxx, dependencyModelRootYyy });

            var snapshot = GetSnapshot((_tfm1, new[] { dependencyXxx1, dependencyYyy1, dependencyYyyExisting }));

            // Act
            var resultTree = await provider.BuildTreeAsync(dependenciesRoot, snapshot);

            // Assert
            const string expectedFlatHierarchy =
                @"Caption=MyDependencies, IconHash=325248080, ExpandedIconHash=325248080, Rule=, IsProjectItem=False, CustomTag=
    Caption=YyyDependencyRoot, IconHash=0, ExpandedIconHash=0, Rule=, IsProjectItem=False, CustomTag=
        Caption=DependencyExisting, IconHash=325248088, ExpandedIconHash=325248260, Rule=, IsProjectItem=False, CustomTag=
        Caption=Dependency1, IconHash=325248088, ExpandedIconHash=325248260, Rule=, IsProjectItem=True, CustomTag=
    Caption=XxxDependencyRoot, IconHash=0, ExpandedIconHash=0, Rule=, IsProjectItem=False, CustomTag=
        Caption=Dependency1, IconHash=325248088, ExpandedIconHash=325248260, Rule=, IsProjectItem=True, CustomTag=";

            AssertTestData(expectedFlatHierarchy, resultTree);
        }