Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void BeforeAddOrUpdate_WhenThereIsMatchingDependencies_ShouldUpdateCaptionForAll()
        {
            // Same provider type
            // Same captions
            //   -> Changes caption for both to match alias

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

            var dependency = new TestDependency
            {
                Id = "id1",
                OriginalItemSpec = "originalItemSpec1",
                ProviderType     = providerType,
                Caption          = caption
            };

            var otherDependency = new TestDependency
            {
                ClonePropertiesFrom = dependency, // clone, with changes

                Id = "id2",
                OriginalItemSpec = "originalItemSpec2"
            };

            var dependencyById = new IDependency[] { dependency, otherDependency }.ToDictionary(IDependencyExtensions.GetDependencyId);

            var context = new AddDependencyContext(dependencyById);

            var filter = new DeduplicateCaptionsSnapshotFilter();

            filter.BeforeAddOrUpdate(
                dependency,
                context);

            // The context changed, beyond just the filtered dependency
            Assert.True(context.Changed);

            // The filtered dependency had its caption changed to its alias
            var dependencyAfter = context.GetResult(filter);

            DependencyAssert.Equal(new TestDependency {
                ClonePropertiesFrom = dependency, Caption = "caption (originalItemSpec1)"
            }, dependencyAfter !);

            // The other dependency had its caption changed to its alias
            Assert.True(context.TryGetDependency(otherDependency.GetDependencyId(), out IDependency otherDependencyAfter));
            DependencyAssert.Equal(new TestDependency {
                ClonePropertiesFrom = otherDependency, Caption = "caption (originalItemSpec2)"
            }, otherDependencyAfter);
        }
        public void FromChanges_NoChangesAfterBeforeRemoveFilterDeclinedChange()
        {
            var targetFramework = new TargetFramework("tfm1");

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

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

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

            var changes = new DependenciesChangesBuilder();

            changes.Removed(dependency1.ProviderType, dependency1.Id);

            var snapshotFilter = new TestDependenciesSnapshotFilter();

            snapshotFilter.BeforeRemoveReject("Xxx", "dependency1");

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

            Assert.Same(previousSnapshot, snapshot);
            Assert.True(snapshotFilter.Completed);
        }
        public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties()
        {
            var targetFramework = new TargetFramework("tfm");

            const string sdkName = "sdkName";

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

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

            var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(d => d.Id);

            var context = new AddDependencyContext(builder);

            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), acceptedDependency !);

            // No changes other than the filtered dependency
            Assert.False(context.Changed);
        }
        public void BeforeAddOrUpdate_WhenThereIsMatchingDependency_WithSubstringCaption()
        {
            // 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
            };

            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 dependencyById = new IDependency[] { dependency, otherDependency }.ToDictionary(d => d.Id);

            var context = new AddDependencyContext(dependencyById);

            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);
        }
        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),
                Resolved = true,
                Flags    = DependencyTreeFlags.SdkDependency.Union(DependencyTreeFlags.Resolved)
            };

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

            var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(d => d.Id);

            var context = new RemoveDependencyContext(builder);

            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(builder.TryGetValue(packageDependency.Id, out var afterPackageDependency));
            Assert.Same(packageDependency, afterPackageDependency);

            Assert.True(builder.TryGetValue(sdkDependency.Id, out var afterSdkDependency));
            DependencyAssert.Equal(
                afterSdkDependency.ToUnresolved(
                    SdkReference.SchemaName), afterSdkDependency);
        }
        public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties()
        {
            var targetFramework = new TargetFramework("tfm");

            const string packageName = "packageName";

            var sdkDependency = new TestDependency
            {
                Id       = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName),
                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,
                Resolved = true
            };

            var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(d => d.Id);

            var context = new AddDependencyContext(builder);

            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), sdkDependencyAfter);
        }
        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 BeforeRemove_WhenPackageRemoving_ShouldCleanupSdk()
        {
            const string packageName = "packageName";

            var sdkDependency = new TestDependency
            {
                Id           = packageName,
                ProviderType = SdkRuleHandler.ProviderTypeString,
                Resolved     = true,
                Flags        = DependencyTreeFlags.SdkDependency.Union(ProjectTreeFlags.ResolvedReference)
            };

            var packageDependency = new TestDependency
            {
                Id           = packageName,
                ProviderType = PackageRuleHandler.ProviderTypeString,
                Flags        = DependencyTreeFlags.PackageDependency,
                Resolved     = true
            };

            var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(IDependencyExtensions.GetDependencyId);

            var context = new RemoveDependencyContext(builder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeRemove(
                dependency: packageDependency,
                context);

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

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

            Assert.True(builder.TryGetValue(packageDependency.GetDependencyId(), out var afterPackageDependency));
            Assert.Same(packageDependency, afterPackageDependency);

            Assert.True(builder.TryGetValue(sdkDependency.GetDependencyId(), out var afterSdkDependency));
            DependencyAssert.Equal(
                afterSdkDependency.ToUnresolved(SdkReference.SchemaName),
                afterSdkDependency);
        }
        public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties()
        {
            const string packageName = "packageName";

            var sdkDependency = new TestDependency
            {
                Id           = packageName,
                ProviderType = SdkRuleHandler.ProviderTypeString,
                Resolved     = true,
                Flags        = DependencyTreeFlags.PackageDependency.Union(ProjectTreeFlags.BrokenReference) // to see if unresolved is fixed
            };

            var packageDependency = new TestDependency
            {
                Id           = packageName,
                ProviderType = PackageRuleHandler.ProviderTypeString,
                Flags        = DependencyTreeFlags.PackageDependency,
                Resolved     = true
            };

            var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(IDependencyExtensions.GetDependencyId);

            var context = new AddDependencyContext(builder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                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.GetDependencyId(), out IDependency sdkDependencyAfter));
            DependencyAssert.Equal(
                sdkDependency.ToResolved(schemaName: ResolvedSdkReference.SchemaName, diagnosticLevel: DiagnosticLevel.None),
                sdkDependencyAfter);
        }
        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);
        }
Exemplo n.º 12
0
        public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties()
        {
            const string sdkName = "sdkName";

            var sdkDependency = new TestDependency
            {
                Id           = sdkName,
                ProviderType = SdkRuleHandler.ProviderTypeString,
                Resolved     = false,
                Flags        = DependencyTreeFlags.SdkDependency
            };

            var packageDependency = new TestDependency
            {
                Id           = sdkName,
                ProviderType = PackageRuleHandler.ProviderTypeString,
                Resolved     = true,
                Flags        = DependencyTreeFlags.PackageDependency
            };

            var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(IDependencyExtensions.GetDependencyId);

            var context = new AddDependencyContext(builder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                sdkDependency,
                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, diagnosticLevel: DiagnosticLevel.None),
                acceptedDependency !);

            // No changes other than the filtered dependency
            Assert.False(context.Changed);
        }
        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_NoDuplicate_ShouldNotUpdateCaption()
        {
            // Same provider type
            // Different captions
            //   -> No change

            const string providerType = "provider";

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

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

            var dependencyById = new IDependency[] { dependency, otherDependency }.ToDictionary(d => d.Id);

            var context = new AddDependencyContext(dependencyById);

            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);
        }
        public void BeforeAddOrUpdate_WhenSdkAndPackageUnresolved_ShouldDoNothing()
        {
            var targetFramework = new TargetFramework("tfm");

            const string sdkName = "sdkName";

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

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

            var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(d => d.Id);

            var context = new AddDependencyContext(builder);

            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);
        }
        public void BeforeAddOrUpdate_WhenResolved_ShouldReturnDependency()
        {
            var resolvedDependency = new TestDependency {
                Id = "dependency", Resolved = true
            };

            var dependencyById = new Dictionary <DependencyId, IDependency>();

            var context = new AddDependencyContext(dependencyById);

            var filter = new UnresolvedDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                resolvedDependency,
                context);

            // Dependency accepted unchanged
            Assert.Same(resolvedDependency, context.GetResult(filter));

            // Nothing else changed
            Assert.False(context.Changed);
        }
        public void BeforeAddOrUpdate_WhenSdkAndPackageUnresolved_ShouldDoNothing()
        {
            const string sdkName = "sdkName";

            var sdkDependency = new TestDependency
            {
                Id               = "dependency1",
                ProviderType     = SdkRuleHandler.ProviderTypeString,
                OriginalItemSpec = sdkName,
                Resolved         = true,
                Flags            = DependencyTreeFlags.SdkDependency
            };

            var packageDependency = new TestDependency
            {
                Id           = sdkName,
                ProviderType = PackageRuleHandler.ProviderTypeString,
                Resolved     = false,
                Flags        = DependencyTreeFlags.PackageDependency
            };

            var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(IDependencyExtensions.GetDependencyId);

            var context = new AddDependencyContext(builder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

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

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

            // No other changes made
            Assert.False(context.Changed);
        }
Exemplo n.º 18
0
        public void BeforeAddOrUpdate_WhenUnresolvedAndNotExistsResolvedInSnapshot_ShouldReturnDependency()
        {
            var unresolvedDependency = new TestDependency {
                Id = "dependency", Resolved = false
            };

            var dependencyById = new Dictionary <(string ProviderType, string ModelId), IDependency>();

            var context = new AddDependencyContext(dependencyById);

            var filter = new UnresolvedDependenciesSnapshotFilter();

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

            // Dependency accepted unchanged
            Assert.Same(unresolvedDependency, context.GetResult(filter));

            // Nothing else changed
            Assert.False(context.Changed);
        }
Exemplo n.º 19
0
        public void FromChanges_UpdatesLevelDependencies()
        {
            var targetFramework = new TargetFramework("tfm1");

            var dependencyPrevious = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\dependency1",
                Name           = "Dependency1",
                Caption        = "Dependency1",
                SchemaItemType = "Xxx",
                Resolved       = true
            };

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

            var dependencyUpdated = new TestDependency
            {
                ProviderType   = "Xxx",
                Id             = "tfm1\\xxx\\dependency1",
                Name           = "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(@"tfm1\xxx\dependency1", dependencyUpdated);

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

            Assert.True(snapshotFilter.Completed);

            Assert.NotSame(previousSnapshot, snapshot);
            Assert.Same(dependencyUpdated, snapshot.Dependencies.Single());
        }
        public void FromChanges_RemovedAndAddedChanges()
        {
            var targetFramework = new TargetFramework("tfm1");

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

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

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

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

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

            var dependencyAdded2Changed = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "addeddependency2",
                OriginalItemSpec = "AddedDependency2Changed",
                Caption          = "AddedDependency2Changed",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var dependencyRemoved1 = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "Removeddependency1",
                OriginalItemSpec = "RemovedDependency1",
                Caption          = "RemovedDependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

            var dependencyInsteadRemoved1 = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "InsteadRemoveddependency1",
                OriginalItemSpec = "InsteadRemovedDependency1",
                Caption          = "InsteadRemovedDependency1",
                SchemaItemType   = "Xxx",
                Resolved         = true
            };

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

            var changes = new DependenciesChangesBuilder();

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

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

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                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(catalogs, snapshot.Catalogs);
            AssertEx.CollectionLength(snapshot.Dependencies, 5);
            Assert.Contains(snapshot.Dependencies, dep => dep.Id == "dependency1");
            Assert.Contains(snapshot.Dependencies, dep => dep.Id == "dependency2");
            Assert.Contains(snapshot.Dependencies, dep => dep.Id == "addeddependency2");
            Assert.Contains(snapshot.Dependencies, dep => dep.Id == "InsteadRemoveddependency1");
            Assert.Contains(snapshot.Dependencies, dep => dep.Id == "addeddependency3");
        }
Exemplo n.º 21
0
        public void FromChanges_ReportedChangesAfterBeforeAddFilterDeclinedChange()
        {
            var targetFramework = new TargetFramework("tfm1");

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

            var dependency2 = new TestDependency
            {
                ProviderType     = "Xxx",
                Id               = "dependency2",
                OriginalItemSpec = "Dependency2",
                Caption          = "Dependency2",
                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, dependency2));

            var changes = new DependenciesChangesBuilder();

            changes.Added(dependencyModelNew1);

            var filterAddedDependency = new TestDependency {
                Id = "unexpected"
            };

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

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

            Assert.True(snapshotFilter.Completed);

            Assert.NotSame(previousSnapshot, snapshot);

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

            AssertEx.CollectionLength(snapshot.Dependencies, 3);
            Assert.Contains(dependency1, snapshot.Dependencies);
            Assert.Contains(dependency2, snapshot.Dependencies);
            Assert.Contains(filterAddedDependency, snapshot.Dependencies);
        }