Example #1
0
        public void BeforeAddOrUpdate_WhenNeedToApplyImplicit_ShouldSetProperties()
        {
            const string providerType    = "providerType";
            const string projectItemSpec = "projectItemSpec";
            var          implicitIcon    = KnownMonikers.Abbreviation;

            var dependency = new TestDependency
            {
                Id               = "dependency1",
                ProviderType     = providerType,
                TopLevel         = true,
                Implicit         = false,
                Resolved         = true,
                Flags            = DependencyTreeFlags.GenericDependencyFlags,
                OriginalItemSpec = projectItemSpec,
                IconSet          = new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference)
            };

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

            var context = new AddDependencyContext(worldBuilder);

            var filter = new ImplicitTopLevelDependenciesSnapshotFilter();

            var subTreeProvider = IProjectDependenciesSubTreeProviderFactory.ImplementInternal(
                providerType: providerType,
                implicitIcon: implicitIcon);

            filter.BeforeAddOrUpdate(
                null,
                null,
                dependency,
                new Dictionary <string, IProjectDependenciesSubTreeProvider> {
                { providerType, subTreeProvider }
            },
                ImmutableHashSet <string> .Empty,
                context);

            var acceptedDependency = context.GetResult(filter);

            // Returns changed dependency
            Assert.NotNull(acceptedDependency);
            Assert.NotSame(dependency, acceptedDependency);

            acceptedDependency.AssertEqualTo(
                new TestDependency
            {
                ClonePropertiesFrom = dependency,
                Implicit            = true,
                IconSet             = new DependencyIconSet(
                    implicitIcon,
                    implicitIcon,
                    KnownMonikers.Reference,
                    KnownMonikers.Reference)
            });

            // No other changes made
            Assert.False(context.Changed);
        }
        public void BeforeAddOrUpdate_WhenNeedToApplyImplicit_ShouldSetProperties()
        {
            const string providerType    = "providerType";
            const string projectItemSpec = "projectItemSpec";
            var          implicitIcon    = KnownMonikers.Abbreviation;

            var dependency = new TestDependency
            {
                Id               = "dependency1",
                ProviderType     = providerType,
                Implicit         = false,
                Resolved         = true,
                Flags            = DependencyTreeFlags.GenericResolvedDependencyFlags,
                OriginalItemSpec = projectItemSpec,
                IconSet          = new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference)
            };

            var dependencyById = new Dictionary <(string ProviderType, string ModelId), IDependency>
            {
                { (dependency.ProviderType, dependency.Id), dependency }
            };

            var context = new AddDependencyContext(dependencyById);

            var filter = new ImplicitDependenciesSnapshotFilter();

            var subTreeProvider = IProjectDependenciesSubTreeProviderFactory.ImplementInternal(
                providerType: providerType,
                implicitIcon: implicitIcon);

            filter.BeforeAddOrUpdate(
                dependency,
                new Dictionary <string, IProjectDependenciesSubTreeProvider> {
                { providerType, subTreeProvider }
            },
                ImmutableHashSet <string> .Empty,
                context);

            var acceptedDependency = context.GetResult(filter);

            // Returns changed dependency
            Assert.NotNull(acceptedDependency);
            Assert.NotSame(dependency, acceptedDependency);
            DependencyAssert.Equal(
                new TestDependency
            {
                ClonePropertiesFrom = dependency,
                Implicit            = true,
                IconSet             = new DependencyIconSet(
                    implicitIcon,
                    implicitIcon,
                    KnownMonikers.Reference,
                    KnownMonikers.Reference),
                Flags = DependencyTreeFlags.GenericResolvedDependencyFlags.Except(DependencyTreeFlags.SupportsRemove)
            }, acceptedDependency !);

            // No other changes made
            Assert.False(context.Changed);
        }
Example #3
0
        public void WhenNeedToApplyImplicit_ShouldSetProperties()
        {
            var dependency = IDependencyFactory.Implement(
                id: "mydependency2",
                providerType: "myProvider",
                topLevel: true,
                isImplicit: false,
                resolved: true,
                flags: DependencyTreeFlags.GenericDependencyFlags,
                originalItemSpec: "myprojectitem",
                setPropertiesImplicit: true,
                iconSet: new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference),
                setPropertiesIconSet: new DependencyIconSet(KnownMonikers.Abbreviation, KnownMonikers.Abbreviation, KnownMonikers.Reference, KnownMonikers.Reference));

            var worldBuilder = new Dictionary <string, IDependency>()
            {
                { dependency.Object.Id, dependency.Object }
            }.ToImmutableDictionary().ToBuilder();

            var subTreeProvider = IProjectDependenciesSubTreeProviderFactory.ImplementInternal(
                providerType: "myProvider",
                icon: KnownMonikers.Abbreviation);

            var filter           = new ImplicitTopLevelDependenciesSnapshotFilter();
            var resultDependency = filter.BeforeAdd(
                null,
                null,
                dependency.Object,
                worldBuilder,
                null,
                new Dictionary <string, IProjectDependenciesSubTreeProvider>
            {
                { subTreeProvider.ProviderType, subTreeProvider }
            },
                new HashSet <string>(),
                out bool filterAnyChanges);

            Assert.Equal(dependency.Object.Id, resultDependency.Id);
            Assert.True(filterAnyChanges);

            dependency.VerifyAll();
        }