Ejemplo n.º 1
0
        public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties()
        {
            var dependencyIDs = ImmutableArray.Create("id1", "id2");

            var targetFramework = new TargetFramework("tfm");

            const string sdkName = "sdkName";

            var sdkDependency = new TestDependency
            {
                Id       = "dependency1Id",
                Name     = sdkName,
                TopLevel = true,
                Resolved = false,
                Flags    = DependencyTreeFlags.SdkDependency
            };

            var packageDependency = new TestDependency
            {
                Id            = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, sdkName),
                Resolved      = true,
                DependencyIDs = dependencyIDs,
                Flags         = DependencyTreeFlags.PackageDependency
            };

            var worldBuilder = new IDependency[] { sdkDependency, packageDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                targetFramework,
                sdkDependency,
                null !,
                null,
                context);

            var acceptedDependency = context.GetResult(filter);

            // Dependency should be accepted, but converted to resolved state
            Assert.NotNull(acceptedDependency);
            Assert.NotSame(sdkDependency, acceptedDependency);
            DependencyAssert.Equal(
                sdkDependency.ToResolved(
                    schemaName: ResolvedSdkReference.SchemaName,
                    dependencyIDs: dependencyIDs), acceptedDependency !);

            // No changes other than the filtered dependency
            Assert.False(context.Changed);
        }
Ejemplo n.º 2
0
        public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties()
        {
            var dependencyIDs = ImmutableArray.Create("id1", "id2");

            var targetFramework = new TargetFramework("tfm");

            const string packageName = "packageName";

            var sdkDependency = new TestDependency
            {
                Id       = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName),
                TopLevel = false,
                Resolved = true,
                Flags    = DependencyTreeFlags.PackageDependency.Union(DependencyTreeFlags.Unresolved) // to see if unresolved is fixed
            };

            var packageDependency = new TestDependency
            {
                Id            = "packageId",
                Name          = packageName,
                Flags         = DependencyTreeFlags.PackageDependency,
                TopLevel      = true,
                Resolved      = true,
                DependencyIDs = dependencyIDs
            };

            var worldBuilder = new IDependency[] { packageDependency, sdkDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                targetFramework,
                packageDependency,
                null !,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(packageDependency, context.GetResult(filter));

            // Other changes made
            Assert.True(context.Changed);

            Assert.True(context.TryGetDependency(sdkDependency.Id, out IDependency sdkDependencyAfter));
            DependencyAssert.Equal(
                sdkDependency.ToResolved(
                    schemaName: ResolvedSdkReference.SchemaName,
                    dependencyIDs: dependencyIDs), sdkDependencyAfter);
        }
        public void BeforeRemove_WhenPackageRemoving_ShouldCleanupSdk()
        {
            const string packageName = "packageName";

            var targetFramework = new TargetFramework("tfm");

            var sdkDependency = new TestDependency
            {
                Id       = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName),
                TopLevel = false,
                Resolved = true,
                Flags    = DependencyTreeFlags.SdkDependency.Union(DependencyTreeFlags.Resolved)
            };

            var packageDependency = new TestDependency
            {
                Id       = "packageId",
                Name     = packageName,
                Flags    = DependencyTreeFlags.NuGetPackageDependency,
                TopLevel = true,
                Resolved = true
            };

            var worldBuilder = new IDependency[] { packageDependency, sdkDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new RemoveDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeRemove(
                targetFramework: targetFramework,
                dependency: packageDependency,
                context);

            // Accepts removal
            Assert.True(context.GetResult(filter));

            // Makes other changes too
            Assert.True(context.Changed);

            Assert.True(worldBuilder.TryGetValue(packageDependency.Id, out var afterPackageDependency));
            Assert.Same(packageDependency, afterPackageDependency);

            Assert.True(worldBuilder.TryGetValue(sdkDependency.Id, out var afterSdkDependency));
            afterSdkDependency.AssertEqualTo(
                afterSdkDependency.ToUnresolved(
                    SdkReference.SchemaName,
                    dependencyIDs: ImmutableArray <string> .Empty));
        }
        public void BeforeAddOrUpdate_WhenThereIsMatchingDependency_WithSubstringCaption()
        {
            // Both top level
            // Same provider type
            // Duplicate caption prefix
            //   -> No change

            const string providerType = "provider";
            const string caption      = "caption";

            var dependency = new TestDependency
            {
                Id           = "dependency1",
                ProviderType = providerType,
                Caption      = caption,
                TopLevel     = true
            };

            var otherDependency = new TestDependency
            {
                ClonePropertiesFrom = dependency,

                Id = "dependency2",
                OriginalItemSpec = "dependency2ItemSpec",
                Caption          = $"{caption}X" // identical caption prefix
            };

            // TODO test a longer suffix here -- looks like the implementation might not handle it correctly

            var worldBuilder = new IDependency[] { dependency, otherDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new DeduplicateCaptionsSnapshotFilter();

            filter.BeforeAddOrUpdate(
                null !,
                dependency,
                null !,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(dependency, context.GetResult(filter));

            // No other changes made
            Assert.False(context.Changed);
        }
Ejemplo n.º 5
0
        public void BeforeAddOrUpdate_WhenProjectSnapshotFoundAndHasUnresolvedDependencies_ShouldMakeUnresolved()
        {
            const string projectPath = @"c:\project\project.csproj";

            var targetFramework = ITargetFrameworkFactory.Implement(moniker: "tfm1");

            var dependency = new TestDependency
            {
                Id              = "dependency1",
                TopLevel        = true,
                Resolved        = true,
                Flags           = DependencyTreeFlags.ProjectNodeFlags.Union(DependencyTreeFlags.ResolvedFlags),
                TargetFramework = targetFramework,
                FullPath        = projectPath
            };

            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(hasUnresolvedDependency: true);

            var aggregateSnapshotProvider = new Mock <IAggregateDependenciesSnapshotProvider>(MockBehavior.Strict);

            aggregateSnapshotProvider.Setup(x => x.GetSnapshot(dependency)).Returns(targetedSnapshot);

            var worldBuilder = ImmutableDictionary <string, IDependency> .Empty.ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new UnsupportedProjectsSnapshotFilter(aggregateSnapshotProvider.Object);

            filter.BeforeAddOrUpdate(
                null,
                dependency,
                null,
                null,
                context);

            // Accepts unresolved version
            var acceptedDependency = context.GetResult(filter);

            acceptedDependency.AssertEqualTo(
                dependency.ToUnresolved(ProjectReference.SchemaName));

            // No other changes made
            Assert.False(context.Changed);

            aggregateSnapshotProvider.VerifyAll();
        }
Ejemplo n.º 6
0
        public void HasSameTarget()
        {
            var targetFramework1 = new TargetFramework("tfm1");
            var targetFramework2 = new TargetFramework("tfm2");

            var dependency1 = new TestDependency {
                TargetFramework = targetFramework1
            };
            var dependency2 = new TestDependency {
                TargetFramework = targetFramework1
            };
            var dependency3 = new TestDependency {
                TargetFramework = targetFramework2
            };

            Assert.True(dependency1.HasSameTarget(dependency2));
            Assert.False(dependency1.HasSameTarget(dependency3));
        }
        public void BeforeAddOrUpdate_NoDuplicate_ShouldNotUpdateCaption()
        {
            // Both top level
            // Same provider type
            // Different captions
            //   -> No change

            const string providerType = "provider";

            var dependency = new TestDependency
            {
                Id           = "dependency1",
                Caption      = "caption1",
                ProviderType = providerType,
                TopLevel     = true
            };

            var otherDependency = new TestDependency
            {
                Id           = "dependency2",
                Caption      = "caption2",
                ProviderType = providerType,
                TopLevel     = true
            };

            var worldBuilder = new IDependency[] { dependency, otherDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new DeduplicateCaptionsSnapshotFilter();

            filter.BeforeAddOrUpdate(
                null !,
                dependency,
                null !,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(dependency, context.GetResult(filter));

            // No other changes made
            Assert.False(context.Changed);
        }
Ejemplo n.º 8
0
        public void GetTopLevelId()
        {
            var dependency1 = new TestDependency
            {
                Id           = "id1",
                ProviderType = "MyProvider"
            };

            Assert.Equal("id1", dependency1.GetTopLevelId());

            var dependency2 = new TestDependency
            {
                Id              = "id1",
                Path            = "xxxxxxx",
                ProviderType    = "MyProvider",
                TargetFramework = new TargetFramework("tfm1")
            };

            Assert.Equal("tfm1\\MyProvider\\xxxxxxx", dependency2.GetTopLevelId());
        }
        public void BeforeAddOrUpdate_WhenSdkAndPackageUnresolved_ShouldDoNothing()
        {
            var targetFramework = new TargetFramework("tfm");

            const string sdkName = "sdkName";

            var sdkDependency = new TestDependency
            {
                Id       = "dependency1",
                Name     = sdkName,
                TopLevel = false,
                Resolved = true,
                Flags    = DependencyTreeFlags.SdkDependency
            };

            var packageDependency = new TestDependency
            {
                Id       = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, sdkName),
                Resolved = false,
                Flags    = DependencyTreeFlags.NuGetPackageDependency
            };

            var worldBuilder = new IDependency[] { sdkDependency, packageDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                targetFramework,
                sdkDependency,
                null,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(sdkDependency, context.GetResult(filter));

            // No other changes made
            Assert.False(context.Changed);
        }
Ejemplo n.º 10
0
        public void BeforeAddOrUpdate_WhenProjectSnapshotNotFound_ShouldDoNothing()
        {
            const string projectPath = @"c:\project\project.csproj";

            var dependency = new TestDependency
            {
                Id       = "dependency1",
                TopLevel = true,
                Resolved = true,
                Flags    = DependencyTreeFlags.ProjectNodeFlags.Union(DependencyTreeFlags.ResolvedFlags),
                FullPath = projectPath
            };

            var aggregateSnapshotProvider = new Mock <IAggregateDependenciesSnapshotProvider>(MockBehavior.Strict);

            aggregateSnapshotProvider.Setup(x => x.GetSnapshot(dependency)).Returns((ITargetedDependenciesSnapshot)null);

            var worldBuilder = ImmutableDictionary <string, IDependency> .Empty.ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new UnsupportedProjectsSnapshotFilter(aggregateSnapshotProvider.Object);

            filter.BeforeAddOrUpdate(
                null,
                dependency,
                null,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(dependency, context.GetResult(filter));

            // No other changes made
            Assert.False(context.Changed);

            aggregateSnapshotProvider.VerifyAll();
        }
        public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var dependencyTop1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = true
            };

            var dependencyChild1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\childdependency1",
                Name           = "ChildDependency1",
                Caption        = "ChildDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

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

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                projectPath,
                targetFramework,
                catalogs,
                new IDependency[] { dependencyTop1, dependencyChild1 }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelNew1);

            var filterAddedDependency = new TestDependency {
                Id = "unexpected", TopLevel = true
            };

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddReject(@"tfm1\xxx\newdependency1", addOrUpdate: filterAddedDependency);

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

            Assert.True(snapshotFilter.Completed);

            Assert.NotSame(previousSnapshot, snapshot);

            Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework);
            Assert.Same(previousSnapshot.ProjectPath, snapshot.ProjectPath);
            Assert.Same(previousSnapshot.Catalogs, snapshot.Catalogs);

            AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2);
            Assert.Contains(dependencyTop1, snapshot.TopLevelDependencies);
            Assert.Contains(filterAddedDependency, snapshot.TopLevelDependencies);

            AssertEx.CollectionLength(snapshot.DependenciesWorld, 3);
            Assert.Contains(dependencyTop1, snapshot.DependenciesWorld.Values);
            Assert.Contains(dependencyChild1, snapshot.DependenciesWorld.Values);
            Assert.Contains(filterAddedDependency, snapshot.DependenciesWorld.Values);
        }
        public void ToViewModel()
        {
            var iconSet = new DependencyIconSet(
                KnownMonikers.Uninstall,
                KnownMonikers.AbsolutePosition,
                KnownMonikers.AboutBox,
                KnownMonikers.Abbreviation);

            // This is a resolved dependency
            var dependencyResolved = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyResolved",
                Name           = "dependencyResolved",
                Caption        = "DependencyResolved",
                SchemaName     = "MySchema",
                SchemaItemType = "MySchemaItemType",
                Priority       = 1,
                Resolved       = true,
                TopLevel       = true,
                IconSet        = iconSet
            };

            // This is an unresolved dependency
            var dependencyUnresolved = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyUnresolved",
                Name           = "dependencyUnresolved",
                Caption        = "DependencyUnresolved",
                SchemaName     = "MySchema",
                SchemaItemType = "MySchemaItemType",
                Priority       = 1,
                Resolved       = false,
                TopLevel       = true,
                IconSet        = iconSet
            };

            // This is a resolved dependency with an unresolved child dependency
            var dependencyUnresolvedChild = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyUnresolvedChild",
                Name           = "dependencyUnresolvedChild",
                Caption        = "DependencyUnresolvedChild",
                SchemaName     = "MySchema",
                SchemaItemType = "MySchemaItemType",
                Priority       = 1,
                Resolved       = true,
                TopLevel       = true,
                IconSet        = iconSet,
                DependencyIDs  = ImmutableArray.Create(dependencyUnresolved.Id)
            };

            var snapshotResolved        = TargetedDependenciesSnapshotFactory.ImplementFromDependencies(new[] { dependencyResolved });
            var snapshotUnresolved      = TargetedDependenciesSnapshotFactory.ImplementFromDependencies(new[] { dependencyUnresolved });
            var snapshotUnresolvedChild = TargetedDependenciesSnapshotFactory.ImplementFromDependencies(new[] { dependencyUnresolved, dependencyUnresolvedChild });

            Assert.False(snapshotResolved.ShouldAppearUnresolved(dependencyResolved));
            Assert.True(snapshotUnresolved.ShouldAppearUnresolved(dependencyUnresolved));
            Assert.True(snapshotUnresolvedChild.ShouldAppearUnresolved(dependencyUnresolvedChild));

            var viewModelResolved = dependencyResolved.ToViewModel(snapshotResolved);

            Assert.Equal(dependencyResolved.Caption, viewModelResolved.Caption);
            Assert.Equal(dependencyResolved.Flags, viewModelResolved.Flags);
            Assert.Equal(dependencyResolved.Id, viewModelResolved.FilePath);
            Assert.Equal(dependencyResolved.SchemaName, viewModelResolved.SchemaName);
            Assert.Equal(dependencyResolved.SchemaItemType, viewModelResolved.SchemaItemType);
            Assert.Equal(dependencyResolved.Priority, viewModelResolved.Priority);
            Assert.Equal(iconSet.Icon, viewModelResolved.Icon);
            Assert.Equal(iconSet.ExpandedIcon, viewModelResolved.ExpandedIcon);

            var viewModelUnresolved = dependencyUnresolved.ToViewModel(snapshotResolved);

            Assert.Equal(dependencyUnresolved.Caption, viewModelUnresolved.Caption);
            Assert.Equal(dependencyUnresolved.Flags, viewModelUnresolved.Flags);
            Assert.Equal(dependencyUnresolved.Id, viewModelUnresolved.FilePath);
            Assert.Equal(dependencyUnresolved.SchemaName, viewModelUnresolved.SchemaName);
            Assert.Equal(dependencyUnresolved.SchemaItemType, viewModelUnresolved.SchemaItemType);
            Assert.Equal(dependencyUnresolved.Priority, viewModelUnresolved.Priority);
            Assert.Equal(iconSet.UnresolvedIcon, viewModelUnresolved.Icon);
            Assert.Equal(iconSet.UnresolvedExpandedIcon, viewModelUnresolved.ExpandedIcon);

            var viewModelUnresolvedChild = dependencyUnresolvedChild.ToViewModel(snapshotUnresolvedChild);

            Assert.Equal(dependencyUnresolvedChild.Caption, viewModelUnresolvedChild.Caption);
            Assert.Equal(dependencyUnresolvedChild.Flags, viewModelUnresolvedChild.Flags);
            Assert.Equal(dependencyUnresolvedChild.Id, viewModelUnresolvedChild.FilePath);
            Assert.Equal(dependencyUnresolvedChild.SchemaName, viewModelUnresolvedChild.SchemaName);
            Assert.Equal(dependencyUnresolvedChild.SchemaItemType, viewModelUnresolvedChild.SchemaItemType);
            Assert.Equal(dependencyUnresolvedChild.Priority, viewModelUnresolvedChild.Priority);
            Assert.Equal(iconSet.UnresolvedIcon, viewModelUnresolvedChild.Icon);
            Assert.Equal(iconSet.UnresolvedExpandedIcon, viewModelUnresolvedChild.ExpandedIcon);
        }
Ejemplo n.º 13
0
        public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var dependencyTop1 = IDependencyFactory.FromJson(@"
                {
                    ""ProviderType"": ""Xxx"",
                    ""Id"": ""tfm1\\xxx\\topdependency1"",
                    ""Name"":""TopDependency1"",
                    ""Caption"":""TopDependency1"",
                    ""SchemaItemType"":""Xxx"",
                    ""Resolved"":""true"",
                    ""TopLevel"":""true""
                }");

            var dependencyChild1 = IDependencyFactory.FromJson(@"
                {
                    ""ProviderType"": ""Xxx"",
                    ""Id"": ""tfm1\\xxx\\childdependency1"",
                    ""Name"":""ChildDependency1"",
                    ""Caption"":""ChildDependency1"",
                    ""SchemaItemType"":""Xxx"",
                    ""Resolved"":""true"",
                    ""TopLevel"":""false""
                }");

            var dependencyModelNew1 = IDependencyModelFactory.FromJson(@"
                {
                    ""ProviderType"": ""Xxx"",
                    ""Id"": ""newdependency1"",
                    ""Name"":""NewDependency1"",
                    ""Caption"":""NewDependency1"",
                    ""SchemaItemType"":""Xxx"",
                    ""Resolved"":""true""
                }",
                                                                       icon: KnownMonikers.Uninstall,
                                                                       expandedIcon: KnownMonikers.Uninstall);

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                projectPath: projectPath,
                targetFramework: targetFramework,
                catalogs: catalogs,
                dependenciesWorld: new [] { dependencyTop1, dependencyChild1 },
                topLevelDependencies: new [] { dependencyTop1 });

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelNew1);

            var filterAddedDependency = new TestDependency {
                Id = "unexpected", TopLevel = true
            };

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddReject(@"tfm1\xxx\newdependency1", addOrUpdate: filterAddedDependency);

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

            Assert.NotSame(previousSnapshot, snapshot);

            Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework);
            Assert.Same(previousSnapshot.ProjectPath, snapshot.ProjectPath);
            Assert.Same(previousSnapshot.Catalogs, snapshot.Catalogs);

            AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2);
            Assert.Contains(dependencyTop1, snapshot.TopLevelDependencies);
            Assert.Contains(filterAddedDependency, snapshot.TopLevelDependencies);

            AssertEx.CollectionLength(snapshot.DependenciesWorld, 3);
            Assert.Contains(dependencyTop1, snapshot.DependenciesWorld.Values);
            Assert.Contains(dependencyChild1, snapshot.DependenciesWorld.Values);
            Assert.Contains(filterAddedDependency, snapshot.DependenciesWorld.Values);
        }
Ejemplo n.º 14
0
        public void FromChanges_ReportedChangesAfterBeforeRemoveFilterDeclinedChange()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var dependencyTop1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = true
            };

            var dependencyChild1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\childdependency1",
                Name           = "ChildDependency1",
                Caption        = "ChildDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                projectPath: projectPath,
                targetFramework: targetFramework,
                catalogs: catalogs,
                dependenciesWorld: new [] { dependencyTop1, dependencyChild1 },
                topLevelDependencies: new [] { dependencyTop1 });

            var changes = new DependenciesChangesBuilder();

            changes.Removed("Xxx", "topdependency1");

            var addedOnRemove = new TestDependency {
                Id = "SomethingElse", TopLevel = false
            };

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeRemoveReject(@"tfm1\xxx\topdependency1", addOrUpdate: addedOnRemove);

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

            Assert.NotSame(previousSnapshot, snapshot);

            Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework);
            Assert.Same(projectPath, snapshot.ProjectPath);
            Assert.Same(catalogs, snapshot.Catalogs);
            Assert.Single(snapshot.TopLevelDependencies);
            AssertEx.CollectionLength(snapshot.DependenciesWorld, 3);
            Assert.Contains(addedOnRemove, snapshot.DependenciesWorld.Values);
        }
Ejemplo n.º 15
0
        public void FromChanges_NoChangesAfterBeforeAddFilterDeclinedChange()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var dependencyTop1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = Dependency.GetID(targetFramework, "Xxx", "topdependency1"),
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = true
            };

            var dependencyChild1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = Dependency.GetID(targetFramework, "Xxx", "childdependency1"),
                Name           = "ChildDependency1",
                Caption        = "ChildDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

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

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                projectPath: projectPath,
                targetFramework: targetFramework,
                catalogs: catalogs,
                dependenciesWorld: new [] { dependencyTop1, dependencyChild1 },
                topLevelDependencies: new [] { dependencyTop1 });

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelNew1);

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddReject(@"tfm1\xxx\newdependency1");

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

            Assert.Same(previousSnapshot, snapshot);
        }
        public void ShouldAppearUnresolved()
        {
            var unresolvedTopLevel = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\unresolvedTopLevel",
                Resolved     = false,
                TopLevel     = true
            };

            var unresolvedReachable = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\unresolvedReachable",
                Resolved     = false,
                TopLevel     = false
            };

            var resolvedUnreachableWithHiddenParent = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\resolvedUnreachableWithHiddenParent",
                Resolved     = true,
                TopLevel     = false
            };

            var resolvedHiddenParent = new TestDependency
            {
                ProviderType  = "Yyy",
                Id            = "tfm1\\yyy\\resolvedHiddenParent",
                Resolved      = true,
                TopLevel      = true,
                Visible       = false,
                DependencyIDs = ImmutableArray.Create(resolvedUnreachableWithHiddenParent.Id)
            };

            var resolvedTopLevelWithUnresolvedChild = new TestDependency
            {
                ProviderType  = "Yyy",
                Id            = "tfm1\\yyy\\resolvedTopLevelWithUnresolvedChild",
                Resolved      = true,
                TopLevel      = true,
                DependencyIDs = ImmutableArray.Create(unresolvedReachable.Id)
            };

            var resolvedTopLevel = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\resolvedTopLevel",
                Resolved     = true,
                TopLevel     = true
            };

            var resolvedUnreachable = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\resolvedUnreachable",
                Resolved     = true,
                TopLevel     = false
            };

            var resolvedChildWithVisibleUnresolvedParent = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\resolvedChildWithVisibleUnresolvedParent",
                Resolved     = true,
                TopLevel     = false
            };

            var unresolvedTopLevelWithUnresolvedChild = new TestDependency
            {
                ProviderType  = "Yyy",
                Id            = "tfm1\\yyy\\unresolvedTopLevelWithUnresolvedChild",
                Resolved      = false,
                TopLevel      = true,
                DependencyIDs = ImmutableArray.Create(resolvedChildWithVisibleUnresolvedParent.Id)
            };

            var snapshot = TargetedDependenciesSnapshotFactory.ImplementFromDependencies(new IDependency[]
            {
                unresolvedTopLevel, unresolvedReachable, resolvedUnreachableWithHiddenParent, resolvedHiddenParent,
                resolvedTopLevelWithUnresolvedChild, resolvedTopLevel, resolvedUnreachable, resolvedChildWithVisibleUnresolvedParent,
                unresolvedTopLevelWithUnresolvedChild
            });

            Assert.True(snapshot.ShouldAppearUnresolved(unresolvedTopLevel));
            Assert.True(snapshot.ShouldAppearUnresolved(unresolvedReachable));
            Assert.True(snapshot.ShouldAppearUnresolved(resolvedTopLevelWithUnresolvedChild));
            Assert.True(snapshot.ShouldAppearUnresolved(unresolvedTopLevelWithUnresolvedChild));
            Assert.False(snapshot.ShouldAppearUnresolved(resolvedTopLevel));
            Assert.False(snapshot.ShouldAppearUnresolved(resolvedChildWithVisibleUnresolvedParent));
#if DEBUG
            // These throw in unit tests but assert elsewhere
            Assert.ThrowsAny <Exception>(() => snapshot.ShouldAppearUnresolved(resolvedUnreachable));
            Assert.ThrowsAny <Exception>(() => snapshot.ShouldAppearUnresolved(resolvedHiddenParent));
            Assert.ThrowsAny <Exception>(() => snapshot.ShouldAppearUnresolved(resolvedUnreachableWithHiddenParent));
            Assert.ThrowsAny <Exception>(() => snapshot.ShouldAppearUnresolved(new TestDependency {
                Id = "ID", Resolved = false
            }));
            Assert.ThrowsAny <Exception>(() => snapshot.ShouldAppearUnresolved(new TestDependency {
                Id = "ID", Resolved = true
            }));
#else
            Assert.False(snapshot.ShouldAppearUnresolved(resolvedUnreachable));
            Assert.False(snapshot.ShouldAppearUnresolved(resolvedHiddenParent));
            Assert.False(snapshot.ShouldAppearUnresolved(resolvedUnreachableWithHiddenParent));
            Assert.True(snapshot.ShouldAppearUnresolved(new TestDependency {
                Id = "ID", Resolved = false
            }));
            Assert.False(snapshot.ShouldAppearUnresolved(new TestDependency {
                Id = "ID", Resolved = true
            }));
#endif
        }
        public void FromChanges_UpdatesTopLevelDependencies()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

            var dependencyTopPrevious = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true
            };

            var dependencyModelTopAdded = new TestDependencyModel
            {
                ProviderType   = "Xxx",
                Id             = "topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                Icon           = KnownMonikers.Uninstall,
                ExpandedIcon   = KnownMonikers.Uninstall
            };

            var dependencyTopUpdated = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true
            };

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                projectPath,
                targetFramework,
                catalogs,
                new IDependency[] { dependencyTopPrevious }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelTopAdded);

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddAccept(@"tfm1\xxx\topdependency1", dependencyTopUpdated);

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

            Assert.True(snapshotFilter.Completed);

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

            var dependencyTop1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\topdependency1",
                Name           = "TopDependency1",
                Caption        = "TopDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = true
            };

            var dependencyChild1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\childdependency1",
                Name           = "ChildDependency1",
                Caption        = "ChildDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

            var dependencyModelAdded1 = new TestDependencyModel
            {
                ProviderType   = "Xxx",
                Id             = "addeddependency1",
                Name           = "AddedDependency1",
                Caption        = "AddedDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false,
                Icon           = KnownMonikers.Uninstall,
                ExpandedIcon   = KnownMonikers.Uninstall
            };

            var dependencyModelAdded2 = new TestDependencyModel
            {
                ProviderType   = "Xxx",
                Id             = "addeddependency2",
                Name           = "AddedDependency2",
                Caption        = "AddedDependency2",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false,
                Icon           = KnownMonikers.Uninstall,
                ExpandedIcon   = KnownMonikers.Uninstall
            };

            var dependencyModelAdded3 = new TestDependencyModel
            {
                ProviderType   = "Xxx",
                Id             = "addeddependency3",
                Name           = "AddedDependency3",
                Caption        = "AddedDependency3",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false,
                Icon           = KnownMonikers.Uninstall,
                ExpandedIcon   = KnownMonikers.Uninstall
            };

            var dependencyAdded2Changed = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\addeddependency2",
                Name           = "AddedDependency2Changed",
                Caption        = "AddedDependency2Changed",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = true
            };

            var dependencyRemoved1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\Removeddependency1",
                Name           = "RemovedDependency1",
                Caption        = "RemovedDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

            var dependencyInsteadRemoved1 = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\InsteadRemoveddependency1",
                Name           = "InsteadRemovedDependency1",
                Caption        = "InsteadRemovedDependency1",
                SchemaItemType = "Xxx",
                Resolved       = true,
                TopLevel       = false
            };

            Assert.True(dependencyTop1.TopLevel);
            Assert.False(dependencyChild1.TopLevel);
            Assert.False(dependencyRemoved1.TopLevel);

            var catalogs         = IProjectCatalogSnapshotFactory.Create();
            var previousSnapshot = new TargetedDependenciesSnapshot(
                projectPath,
                targetFramework,
                catalogs,
                new IDependency[] { dependencyTop1, dependencyChild1, dependencyRemoved1 }.ToImmutableDictionary(d => d.Id).WithComparers(StringComparer.OrdinalIgnoreCase));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelAdded1);
            changes.Added(dependencyModelAdded2);
            changes.Added(dependencyModelAdded3);
            changes.Removed("Xxx", "Removeddependency1");

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .BeforeAddReject(@"tfm1\xxx\addeddependency1")
                                 .BeforeAddAccept(@"tfm1\xxx\addeddependency2", dependencyAdded2Changed)
                                 .BeforeAddAccept(@"tfm1\xxx\addeddependency3")
                                 .BeforeRemoveAccept(@"tfm1\xxx\Removeddependency1", dependencyInsteadRemoved1);

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

            Assert.True(snapshotFilter.Completed);

            Assert.NotSame(previousSnapshot, snapshot);

            Assert.Same(previousSnapshot.TargetFramework, snapshot.TargetFramework);
            Assert.Same(projectPath, snapshot.ProjectPath);
            Assert.Same(catalogs, snapshot.Catalogs);
            AssertEx.CollectionLength(snapshot.TopLevelDependencies, 2);
            Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\topdependency1"));
            Assert.Contains(snapshot.TopLevelDependencies, x => x.Id.Equals(@"tfm1\xxx\addeddependency2") && x.Caption.Equals("AddedDependency2Changed"));
            AssertEx.CollectionLength(snapshot.DependenciesWorld, 5);
            Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\topdependency1"));
            Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\childdependency1"));
            Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency2"));
            Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\InsteadRemoveddependency1"));
            Assert.True(snapshot.DependenciesWorld.ContainsKey(@"tfm1\xxx\addeddependency3"));
        }
Ejemplo n.º 19
0
        public void ToViewModel()
        {
            var iconSet = new DependencyIconSet(
                KnownMonikers.Uninstall,
                KnownMonikers.AbsolutePosition,
                KnownMonikers.AboutBox,
                KnownMonikers.Abbreviation);

            var dependencyResolved = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyExisting",
                Name           = "dependencyExisting",
                Caption        = "DependencyExisting",
                SchemaName     = "MySchema",
                SchemaItemType = "MySchemaItemType",
                Priority       = 1,
                Resolved       = true,
                IconSet        = iconSet
            };

            var dependencyUnresolved = new TestDependency
            {
                ProviderType   = "Yyy",
                Id             = "tfm1\\yyy\\dependencyExisting",
                Name           = "dependencyExisting",
                Caption        = "DependencyExisting",
                SchemaName     = "MySchema",
                SchemaItemType = "MySchemaItemType",
                Priority       = 1,
                Resolved       = false,
                IconSet        = iconSet
            };

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementMock(checkForUnresolvedDependencies: false).Object;
            var mockSnapshotUnresolvedDependency = ITargetedDependenciesSnapshotFactory.ImplementMock(checkForUnresolvedDependencies: true).Object;

            var viewModelResolved = dependencyResolved.ToViewModel(mockSnapshot);

            Assert.Equal(dependencyResolved.Caption, viewModelResolved.Caption);
            Assert.Equal(dependencyResolved.Flags, viewModelResolved.Flags);
            Assert.Equal(dependencyResolved.Id, viewModelResolved.FilePath);
            Assert.Equal(dependencyResolved.SchemaName, viewModelResolved.SchemaName);
            Assert.Equal(dependencyResolved.SchemaItemType, viewModelResolved.SchemaItemType);
            Assert.Equal(dependencyResolved.Priority, viewModelResolved.Priority);
            Assert.Equal(iconSet.Icon, viewModelResolved.Icon);
            Assert.Equal(iconSet.ExpandedIcon, viewModelResolved.ExpandedIcon);

            var viewModelUnresolved = dependencyUnresolved.ToViewModel(mockSnapshot);

            Assert.Equal(dependencyUnresolved.Caption, viewModelUnresolved.Caption);
            Assert.Equal(dependencyUnresolved.Flags, viewModelUnresolved.Flags);
            Assert.Equal(dependencyUnresolved.Id, viewModelUnresolved.FilePath);
            Assert.Equal(dependencyUnresolved.SchemaName, viewModelUnresolved.SchemaName);
            Assert.Equal(dependencyUnresolved.SchemaItemType, viewModelUnresolved.SchemaItemType);
            Assert.Equal(dependencyUnresolved.Priority, viewModelUnresolved.Priority);
            Assert.Equal(iconSet.UnresolvedIcon, viewModelUnresolved.Icon);
            Assert.Equal(iconSet.UnresolvedExpandedIcon, viewModelUnresolved.ExpandedIcon);

            var viewModelUnresolvedDependency = dependencyResolved.ToViewModel(mockSnapshotUnresolvedDependency);

            Assert.Equal(dependencyUnresolved.Caption, viewModelUnresolvedDependency.Caption);
            Assert.Equal(dependencyUnresolved.Flags, viewModelUnresolvedDependency.Flags);
            Assert.Equal(dependencyUnresolved.Id, viewModelUnresolvedDependency.FilePath);
            Assert.Equal(dependencyUnresolved.SchemaName, viewModelUnresolvedDependency.SchemaName);
            Assert.Equal(dependencyUnresolved.SchemaItemType, viewModelUnresolvedDependency.SchemaItemType);
            Assert.Equal(dependencyUnresolved.Priority, viewModelUnresolvedDependency.Priority);
            Assert.Equal(iconSet.UnresolvedIcon, viewModelUnresolvedDependency.Icon);
            Assert.Equal(iconSet.UnresolvedExpandedIcon, viewModelUnresolvedDependency.ExpandedIcon);
        }