public void Dependency_Constructor_WhenOptionalValuesNotProvided_ShouldSetDefaults()
        {
            const string jsonModel    = @"
{
    ""ProviderType"": ""xxx"",
    ""Id"": ""mymodel""
}";
            var          mockModel    = IDependencyModelFactory.FromJson(jsonModel);
            var          mockSnapshot = ITargetedDependenciesSnapshotFactory.Create();

            var dependency = new Dependency(mockModel, mockSnapshot);

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(string.Empty, dependency.Name);
            Assert.Equal(string.Empty, dependency.Version);
            Assert.Equal(string.Empty, dependency.Caption);
            Assert.Equal(string.Empty, dependency.OriginalItemSpec);
            Assert.Equal(string.Empty, dependency.Path);
            Assert.Equal("Folder", dependency.SchemaName);
            Assert.Equal("Folder", dependency.SchemaItemType);
            Assert.True(dependency.Properties.Count == 2);
            Assert.True(dependency.Properties.ContainsKey("Identity"));
            Assert.True(dependency.Properties.ContainsKey("FullPath"));
            Assert.True(dependency.DependencyIDs.Count == 0);
        }
        public void UnsupportedProjectsSnapshotFilter_WhenProjectSnapshotFoundAndHasUnresolvedDependencies_ShouldMakeUnresolved()
        {
            // Arrange
            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tfm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(hasUnresolvedDependency: true);
            var targets          = new Dictionary <ITargetFramework, ITargetedDependenciesSnapshot>
            {
                { targetFramework, targetedSnapshot }
            };
            var snapshot                  = IDependenciesSnapshotFactory.Implement(targets: targets);
            var snapshotProvider          = IDependenciesSnapshotProviderFactory.Implement(currentSnapshot: snapshot);
            var aggregateSnapshotProvider = IAggregateDependenciesSnapshotProviderFactory.Implement(getSnapshotProvider: snapshotProvider);
            var targetFrameworkProvider   = ITargetFrameworkProviderFactory.Implement(getNearestFramework: targetFramework);

            var dependency = IDependencyFactory.Implement(
                topLevel: true,
                resolved: true,
                flags: DependencyTreeFlags.ProjectNodeFlags.Union(DependencyTreeFlags.ResolvedFlags),
                originalItemSpec: @"c:\myproject2\project.csproj",
                snapshot: targetedSnapshot,
                setPropertiesResolved: false,
                setPropertiesFlags: DependencyTreeFlags.ProjectNodeFlags.Union(DependencyTreeFlags.UnresolvedFlags));

            var filter = new UnsupportedProjectsSnapshotFilter(aggregateSnapshotProvider, targetFrameworkProvider);

            var resultDependency = filter.BeforeAdd(
                projectPath: null,
                targetFramework: null,
                dependency: dependency.Object,
                worldBuilder: null,
                topLevelBuilder: null);

            dependency.VerifyAll();
        }
Esempio n. 3
0
        public void UnsupportedProjectsSnapshotFilter_WhenProjectSnapshotFoundAndNoUnresolvedDependencies_ShouldDoNothing()
        {
            // Arrange
            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tfm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(hasUnresolvedDependency: false);
            var targets          = new Dictionary <ITargetFramework, ITargetedDependenciesSnapshot>
            {
                { targetFramework, targetedSnapshot }
            };
            var snapshot                  = IDependenciesSnapshotFactory.Implement(targets: targets);
            var snapshotProvider          = IDependenciesSnapshotProviderFactory.Implement(currentSnapshot: snapshot);
            var aggregateSnapshotProvider = IAggregateDependenciesSnapshotProviderFactory.Implement(getSnapshotProvider: snapshotProvider);
            var targetFrameworkProvider   = ITargetFrameworkProviderFactory.Implement(getNearestFramework: targetFramework);

            var dependency = IDependencyFactory.Implement(
                topLevel: true,
                resolved: true,
                flags: DependencyTreeFlags.ProjectNodeFlags.Union(DependencyTreeFlags.ResolvedFlags),
                fullPath: @"c:\myproject1\project.csproj",
                targetFramework: targetFramework
                );

            var filter = new UnsupportedProjectsSnapshotFilter(aggregateSnapshotProvider, targetFrameworkProvider);

            var resultDependency = filter.BeforeAdd(
                null,
                null,
                dependency.Object,
                null,
                null,
                null,
                out bool filterAnyChanges);

            dependency.VerifyAll();
        }
        public void Dependency_DependenciesProperty()
        {
            var mockModel1 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId1",
                dependencyIDs: new[] { "someId2", "someId_other" });

            var mockModel2 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId2");
            var mockModel3 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId_other");

            var targetFramework = ITargetFrameworkFactory.Implement("Tfm1");
            var mockSnapshot    = ITargetedDependenciesSnapshotFactory.ImplementMock(targetFramework: targetFramework);

            var dependency1 = new Dependency(mockModel1, mockSnapshot.Object);
            var dependency2 = new Dependency(mockModel2, mockSnapshot.Object);
            var dependency3 = new Dependency(mockModel3, mockSnapshot.Object);

            var children = new Dictionary <string, IDependency>()
            {
                { dependency2.Id, dependency2 },
                { dependency3.Id, dependency3 },
            };

            mockSnapshot.Setup(x => x.DependenciesWorld).Returns(
                ImmutableDictionary <string, IDependency> .Empty.AddRange(children));

            Assert.True(dependency1.Dependencies.Count() == 2);
            Assert.True(dependency1.Dependencies.Any(x => x.Equals(dependency2)));
            Assert.True(dependency1.Dependencies.Any(x => x.Equals(dependency3)));
        }
        public void DependencyExtensionsTests_ToViewModel()
        {
            var dependencyResolved = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Yyy"",
    ""Id"": ""tfm1\\yyy\\dependencyExisting"",
    ""Name"":""dependencyExisting"",
    ""Caption"":""DependencyExisting"",
    ""HasUnresolvedDependency"":""false"",
    ""SchemaName"":""MySchema"",
    ""SchemaItemType"":""MySchemaItemType"",
    ""Priority"":""1"",
    ""Resolved"":""true""
}", icon: KnownMonikers.Uninstall,
                                                                 expandedIcon: KnownMonikers.AbsolutePosition,
                                                                 unresolvedIcon: KnownMonikers.AboutBox,
                                                                 unresolvedExpandedIcon: KnownMonikers.Abbreviation);

            var dependencyUnresolved = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Yyy"",
    ""Id"": ""tfm1\\yyy\\dependencyExisting"",
    ""Name"":""dependencyExisting"",
    ""Caption"":""DependencyExisting"",
    ""HasUnresolvedDependency"":""false"",
    ""SchemaName"":""MySchema"",
    ""SchemaItemType"":""MySchemaItemType"",
    ""Priority"":""1"",
    ""Resolved"":""false""
}", icon: KnownMonikers.Uninstall,
                                                                   expandedIcon: KnownMonikers.AbsolutePosition,
                                                                   unresolvedIcon: KnownMonikers.AboutBox,
                                                                   unresolvedExpandedIcon: KnownMonikers.Abbreviation);

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("someId1", true);

            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(dependencyResolved.Icon, viewModelResolved.Icon);
            Assert.Equal(dependencyResolved.ExpandedIcon, viewModelResolved.ExpandedIcon);
            Assert.Equal(dependencyResolved.Properties, viewModelResolved.Properties);

            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(dependencyUnresolved.UnresolvedIcon, viewModelUnresolved.Icon);
            Assert.Equal(dependencyUnresolved.UnresolvedExpandedIcon, viewModelUnresolved.ExpandedIcon);
            Assert.Equal(dependencyUnresolved.Properties, viewModelUnresolved.Properties);
        }
        public void Dependency_Constructor_WhenRequiredParamsNotProvided_ShouldThrow()
        {
            Assert.Throws <ArgumentNullException>("dependencyModel", () =>
            {
                new Dependency(null, null);
            });

            Assert.Throws <ArgumentNullException>("snapshot", () =>
            {
                var mockModel = IDependencyModelFactory.Create();
                new Dependency(mockModel, null);
            });

            Assert.Throws <ArgumentNullException>("ProviderType", () =>
            {
                var mockModel    = IDependencyModelFactory.Create();
                var mockSnapshot = ITargetedDependenciesSnapshotFactory.Create();
                new Dependency(mockModel, mockSnapshot);
            });

            Assert.Throws <ArgumentNullException>("Id", () =>
            {
                var mockModel    = IDependencyModelFactory.Implement(providerType: "someprovider");
                var mockSnapshot = ITargetedDependenciesSnapshotFactory.Create();
                new Dependency(mockModel, mockSnapshot);
            });
        }
Esempio n. 7
0
        public void TFromChanges_Empty()
        {
            const string projectPath      = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework  = ITargetFrameworkFactory.Implement("tfm1");
            var          previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                dependenciesWorld: new Dictionary <string, IDependency>(),
                topLevelDependencies: new List <IDependency>());

            var addedNodes   = new List <IDependencyModel>();
            var removedNodes = new List <IDependencyModel>();
            var changes      = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes);

            IEnumerable <IDependenciesSnapshotFilter> snapshotFilters = null;

            var catalogs = IProjectCatalogSnapshotFactory.Create();
            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                projectPath,
                targetFramework,
                previousSnapshot,
                changes,
                catalogs,
                snapshotFilters,
                null,
                null,
                out bool anyChanges);

            Assert.NotNull(snapshot.TargetFramework);
            Assert.Equal("tfm1", snapshot.TargetFramework.FullName);
            Assert.Equal(projectPath, snapshot.ProjectPath);
            Assert.Equal(catalogs, snapshot.Catalogs);
            Assert.False(anyChanges);
            Assert.Empty(snapshot.TopLevelDependencies);
            Assert.Empty(snapshot.DependenciesWorld);
        }
Esempio n. 8
0
        public void TargetedDependenciesSnapshot_FromChanges_NoChanges()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = ITargetFrameworkFactory.Implement("tfm1");

            var dependencyModelTop1 = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Xxx"",
    ""Id"": ""tfm1\\xxx\\topdependency1"",
    ""Name"":""TopDependency1"",
    ""Caption"":""TopDependency1"",
    ""SchemaItemType"":""Xxx"",
    ""Resolved"":""true""
}", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall);

            var dependencyModelChild1 = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Xxx"",
    ""Id"": ""tfm1\\xxx\\childdependency1"",
    ""Name"":""ChildDependency1"",
    ""Caption"":""ChildDependency1"",
    ""SchemaItemType"":""Xxx"",
    ""Resolved"":""true""
}", icon: KnownMonikers.Uninstall, expandedIcon: KnownMonikers.Uninstall);

            var previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                dependenciesWorld: new Dictionary <string, IDependency>()
            {
                { dependencyModelTop1.Id, dependencyModelTop1 },
                { dependencyModelChild1.Id, dependencyModelChild1 },
            },
                topLevelDependencies: new List <IDependency>()
            {
                dependencyModelTop1
            });

            var addedNodes   = new List <IDependencyModel>();
            var removedNodes = new List <IDependencyModel>();
            var changes      = IDependenciesChangesFactory.Implement(addedNodes: addedNodes, removedNodes: removedNodes);

            IEnumerable <IDependenciesSnapshotFilter> snapshotFilters = null;

            var catalogs = IProjectCatalogSnapshotFactory.Create();
            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                projectPath,
                targetFramework,
                previousSnapshot,
                changes,
                catalogs,
                snapshotFilters,
                out bool anyChanges);

            Assert.NotNull(snapshot.TargetFramework);
            Assert.Equal("tfm1", snapshot.TargetFramework.Moniker);
            Assert.Equal(projectPath, snapshot.ProjectPath);
            Assert.Equal(catalogs, snapshot.Catalogs);
            Assert.False(anyChanges);
            Assert.Equal(1, snapshot.TopLevelDependencies.Count);
            Assert.Equal(2, snapshot.DependenciesWorld.Count);
        }
Esempio n. 9
0
        public void IsOrHasUnresolvedDependency()
        {
            var dependency1 = new TestDependency
            {
                ProviderType = "Yyy",
                Id           = "tfm1\\yyy\\dependencyExisting",
                Name         = "dependencyExisting",
                Caption      = "DependencyExisting",
                Resolved     = false
            };

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.Implement();

            Assert.True(dependency1.IsOrHasUnresolvedDependency(mockSnapshot));

            var dependency2 = new TestDependency
            {
                ClonePropertiesFrom = dependency1,
                Resolved            = true
            };

            mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("tfm1\\yyy\\dependencyExisting", true);

            Assert.True(dependency2.IsOrHasUnresolvedDependency(mockSnapshot));

            mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("tfm1\\yyy\\dependencyExisting", false);

            Assert.False(dependency2.IsOrHasUnresolvedDependency(mockSnapshot));
        }
Esempio n. 10
0
        public void Dependency_DependencyIDsProperty()
        {
            var mockModel1 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId1",
                dependencyIDs: new[] { "someId2", "someId_other" });

            var mockModel2 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId2");
            var mockModel3 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId_other");

            var targetFramework = ITargetFrameworkFactory.Implement("Tfm1");
            var mockSnapshot    = ITargetedDependenciesSnapshotFactory.ImplementMock(targetFramework: targetFramework);

            var projectPath = "projectPath";

            var dependency1 = new Dependency(mockModel1, targetFramework, projectPath);
            var dependency2 = new Dependency(mockModel2, targetFramework, projectPath);
            var dependency3 = new Dependency(mockModel3, targetFramework, projectPath);

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

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

            AssertEx.CollectionLength(dependency1.DependencyIDs, 2);
            Assert.Contains(dependency1.DependencyIDs, x => x.Equals(dependency2.Id));
            Assert.Contains(dependency1.DependencyIDs, x => x.Equals(dependency3.Id));
        }
Esempio n. 11
0
        public void FromChanges_NotEmpty_NoChanges()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = new TargetFramework("tfm1");

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

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

            var changes = new DependenciesChangesBuilder();

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

            Assert.Same(previousSnapshot, snapshot);
        }
        public void Dependency_Constructor_WhenValidModelProvided_ShouldSetAllProperties()
        {
            const string jsonModel = @"
{
    ""ProviderType"": ""xxx"",
    ""Id"": ""mymodelid"",
    ""Name"": ""mymodelname"",
    ""Version"": ""2.0.0-1"",
    ""Caption"": ""mymodel"",
    ""OriginalItemSpec"": ""mymodeloriginal"",
    ""Path"": ""mymodelpath"",
    ""SchemaName"": ""MySchema"",
    ""SchemaItemType"": ""MySchemaItemType"",
    ""Resolved"": ""true"",
    ""TopLevel"": ""true"",
    ""Implicit"": ""true"",
    ""Visible"": ""true"",
    ""Priority"": ""3""
}";

            var mockModel = IDependencyModelFactory.FromJson(
                jsonModel,
                flags: DependencyTreeFlags.DependencyFlags.Union(DependencyTreeFlags.GenericDependencyFlags),
                icon: KnownMonikers.Path,
                expandedIcon: KnownMonikers.PathIcon,
                unresolvedIcon: KnownMonikers.PathListBox,
                unresolvedExpandedIcon: KnownMonikers.PathListBoxItem,
                properties: new Dictionary <string, string>()
            {
                { "prop1", "val1" }
            },
                dependenciesIds: new[] { "otherid" });

            var targetFramework = ITargetFrameworkFactory.Implement("Tfm1");
            var mockSnapshot    = ITargetedDependenciesSnapshotFactory.Implement(targetFramework: targetFramework);

            var dependency = new Dependency(mockModel, mockSnapshot);

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(mockModel.Name, dependency.Name);
            Assert.Equal(mockModel.Version, dependency.Version);
            Assert.Equal(mockModel.Caption, dependency.Caption);
            Assert.Equal(mockModel.OriginalItemSpec, dependency.OriginalItemSpec);
            Assert.Equal(mockModel.Path, dependency.Path);
            Assert.Equal(mockModel.SchemaName, dependency.SchemaName);
            Assert.Equal(mockModel.SchemaItemType, dependency.SchemaItemType);
            Assert.Equal(mockModel.Resolved, dependency.Resolved);
            Assert.Equal(mockModel.TopLevel, dependency.TopLevel);
            Assert.Equal(mockModel.Implicit, dependency.Implicit);
            Assert.Equal(mockModel.Visible, dependency.Visible);
            Assert.Equal(mockModel.Priority, dependency.Priority);
            Assert.True(dependency.Properties.Count == 1);
            Assert.True(dependency.Properties.ContainsKey("prop1"));
            Assert.True(dependency.DependencyIDs.Count == 1);
            Assert.Equal("Tfm1\\xxx\\otherid", dependency.DependencyIDs[0]);
            Assert.True(dependency.Flags.Contains(DependencyTreeFlags.ResolvedFlags));
            Assert.True(dependency.Flags.Contains(DependencyTreeFlags.DependencyFlags));
        }
Esempio n. 13
0
        public void TFromChanges_NoChangesAfterBeforeRemoveFilterDeclinedChange()
        {
            const string projectPath     = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework = ITargetFrameworkFactory.Implement("tfm1");

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

            var dependencyChild1 = IDependencyFactory.FromJson(@"
                {
                    ""ProviderType"": ""Xxx"",
                    ""Id"": ""tfm1\\xxx\\childdependency1"",
                    ""Name"":""ChildDependency1"",
                    ""Caption"":""ChildDependency1"",
                    ""SchemaItemType"":""Xxx"",
                    ""Resolved"":""true"",
                    ""TopLevel"":""false""
                }",
                                                               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 DependenciesChanges();

            changes.IncludeRemovedChange(dependencyTop1.ProviderType, dependencyTop1.Id);

            var snapshotFilter = new TestDependenciesSnapshotFilter()
                                 .ImplementBeforeRemoveResult(FilterAction.Cancel, @"tfm1\xxx\newdependency1", null);

            var snapshot = TargetedDependenciesSnapshot.FromChanges(
                projectPath,
                previousSnapshot,
                changes,
                catalogs,
                new[] { snapshotFilter },
                new Dictionary <string, IProjectDependenciesSubTreeProvider>(),
                null);

            Assert.Same(previousSnapshot, snapshot);
        }
        public void Dependency_Id_NoSnapsotTargetFramework(string modelId, string expectedId)
        {
            var mockModel    = IDependencyModelFactory.Implement(providerType: "xxx", id: modelId);
            var mockSnapshot = ITargetedDependenciesSnapshotFactory.Create();

            var dependency = new Dependency(mockModel, mockSnapshot);

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(expectedId, dependency.Id);
        }
        public void Dependency_Id(string modelId, string expectedId)
        {
            var mockModel           = IDependencyModelFactory.Implement(providerType: "providerType", id: modelId);
            var mockTargetFramework = ITargetFrameworkFactory.Implement(moniker: "tfm");
            var mockSnapshot        = ITargetedDependenciesSnapshotFactory.Implement(targetFramework: mockTargetFramework);

            var dependency = new Dependency(mockModel, mockSnapshot);

            Assert.Equal(mockModel.ProviderType, dependency.ProviderType);
            Assert.Equal(expectedId, dependency.Id);
        }
Esempio n. 16
0
        public void BeforeAddOrUpdate_WhenProjectSnapshotFoundAndHasUnresolvedDependencies_ShouldMakeUnresolved()
        {
            const string projectPath = @"c:\project\project.csproj";

            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tfm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(hasUnresolvedDependency: true);
            var targets          = new Dictionary <ITargetFramework, ITargetedDependenciesSnapshot>
            {
                { targetFramework, targetedSnapshot }
            };
            var snapshot                  = IDependenciesSnapshotFactory.Implement(targets: targets);
            var snapshotProvider          = IDependenciesSnapshotProviderFactory.Implement(currentSnapshot: snapshot);
            var aggregateSnapshotProvider = new Mock <IAggregateDependenciesSnapshotProvider>(MockBehavior.Strict);

            aggregateSnapshotProvider.Setup(x => x.GetSnapshotProvider(projectPath)).Returns(snapshotProvider);

            var targetFrameworkProvider = ITargetFrameworkProviderFactory.Implement(getNearestFramework: targetFramework);

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

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

            var context = new AddDependencyContext(worldBuilder);

            var filter = new UnsupportedProjectsSnapshotFilter(aggregateSnapshotProvider.Object, targetFrameworkProvider);

            filter.BeforeAddOrUpdate(
                null,
                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();
        }
Esempio n. 17
0
        public void FromChanges_NoChangesAfterBeforeRemoveFilterDeclinedChange()
        {
            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 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(dependencyTop1.ProviderType, dependencyTop1.Id);

            var snapshotFilter = new TestDependenciesSnapshotFilter();

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

            Assert.Same(previousSnapshot, snapshot);
        }
Esempio n. 18
0
        public void FromChanges_NoChangesAfterBeforeRemoveFilterDeclinedChange()
        {
            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 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(dependencyTop1.ProviderType, dependencyTop1.Id);

            var snapshotFilter = new TestDependenciesSnapshotFilter();

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

            Assert.Same(previousSnapshot, snapshot);
        }
Esempio n. 19
0
        public void Dependency_HasUnresolvedDependency()
        {
            var dependencyModel = new TestDependencyModel {
                ProviderType = "providerType", Id = "someId1", Resolved = true
            };

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

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

            Assert.True(dependency.HasUnresolvedDependency(mockSnapshot));
            Assert.True(dependency.IsOrHasUnresolvedDependency(mockSnapshot));
        }
Esempio n. 20
0
        public void Dependency_HasUnresolvedDependency()
        {
            var mockModel1 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId1",
                resolved: true);

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

            var dependency = new Dependency(mockModel1, ITargetFrameworkFactory.Implement("tfm1"), @"C:\Foo\Project.csproj");

            Assert.True(dependency.HasUnresolvedDependency(mockSnapshot));
            Assert.True(dependency.IsOrHasUnresolvedDependency(mockSnapshot));
        }
        public void Dependency_HasUnresolvedDependency()
        {
            var mockModel1 = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId1",
                resolved: true);

            var mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("someId1", true);

            var dependency = new Dependency(mockModel1, mockSnapshot);

            Assert.True(dependency.HasUnresolvedDependency);
            Assert.True(dependency.IsOrHasUnresolvedDependency());
        }
        public void Dependency_Alias(string originalItemSpec, string path, string caption, string expectedAlias)
        {
            var mockModel = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId",
                originalItemSpec: originalItemSpec,
                path: path,
                caption: caption);
            var mockTargetFramework = ITargetFrameworkFactory.Implement(moniker: "tfm");
            var mockSnapshot        = ITargetedDependenciesSnapshotFactory.Implement(targetFramework: mockTargetFramework);

            var dependency = new Dependency(mockModel, mockSnapshot);

            Assert.Equal(expectedAlias, dependency.Alias);
        }
        public void DependencyExtensionsTests_HasSameTarget()
        {
            var targetedSnapshot1 = ITargetedDependenciesSnapshotFactory.Implement(
                targetFramework: ITargetFrameworkFactory.Implement("tfm1"));

            var targetedSnapshot2 = ITargetedDependenciesSnapshotFactory.Implement(
                targetFramework: ITargetFrameworkFactory.Implement("tfm2"));

            var dependency1 = IDependencyFactory.Implement(snapshot: targetedSnapshot1).Object;
            var dependency2 = IDependencyFactory.Implement(snapshot: targetedSnapshot1).Object;
            var dependency3 = IDependencyFactory.Implement(snapshot: targetedSnapshot2).Object;


            Assert.True(dependency1.HasSameTarget(dependency2));
            Assert.False(dependency1.HasSameTarget(dependency3));
        }
        public void DependenciesViewModelFactoryTests_CreateTargetViewModel_NoUnresolvedDependency()
        {
            var project          = UnconfiguredProjectFactory.Create();
            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tFm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                hasUnresolvedDependency: false,
                targetFramework: targetFramework);

            var factory = new DependenciesViewModelFactory(project);

            var result = factory.CreateTargetViewModel(targetedSnapshot);

            Assert.NotNull(result);
            Assert.Equal(targetFramework.Moniker, result.Caption);
            Assert.Equal(KnownMonikers.Library, result.Icon);
            Assert.Equal(KnownMonikers.Library, result.ExpandedIcon);
            Assert.True(result.Flags.Contains(DependencyTreeFlags.TargetNodeFlags));
            Assert.True(result.Flags.Contains("$TFM:tFm1"));
        }
Esempio n. 25
0
        public void CreateTargetViewModel_HasUnresolvedDependency()
        {
            var project          = UnconfiguredProjectFactory.Create();
            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tFm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                hasUnresolvedDependency: true,
                targetFramework: targetFramework);

            var factory = new DependenciesViewModelFactory(project);

            var result = factory.CreateTargetViewModel(targetedSnapshot);

            Assert.NotNull(result);
            Assert.Equal(targetFramework.FullName, result.Caption);
            Assert.Equal(ManagedImageMonikers.LibraryWarning, result.Icon);
            Assert.Equal(ManagedImageMonikers.LibraryWarning, result.ExpandedIcon);
            Assert.True(result.Flags.Contains(DependencyTreeFlags.TargetNode));
            Assert.True(result.Flags.Contains("$TFM:tFm1"));
        }
Esempio n. 26
0
        public void BeforeAddOrUpdate_WhenProjectSnapshotFoundAndNoUnresolvedDependencies_ShouldDoNothing()
        {
            const string projectPath = @"c:\project\project.csproj";

            var targetFramework  = ITargetFrameworkFactory.Implement(moniker: "tfm1");
            var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(hasUnresolvedDependency: false);

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

            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,
                null,
                dependency,
                null,
                null,
                context);

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

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

            aggregateSnapshotProvider.VerifyAll();
        }
Esempio n. 27
0
        private IDependenciesSnapshot GetSnapshot(Dictionary <ITargetFramework, List <IDependency> > testData)
        {
            var catalogs = IProjectCatalogSnapshotFactory.Create();
            var targets  = new Dictionary <ITargetFramework, ITargetedDependenciesSnapshot>();

            foreach (var kvp in testData)
            {
                var targetedSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                    catalogs: catalogs,
                    topLevelDependencies: kvp.Value,
                    checkForUnresolvedDependencies: false,
                    targetFramework: kvp.Key);

                targets.Add(kvp.Key, targetedSnapshot);
            }
            return(IDependenciesSnapshotFactory.Implement(
                       targets: targets,
                       hasUnresolvedDependency: false,
                       activeTarget: testData.First().Key));
        }
        public void Dependency_SetProperties()
        {
            var mockModel = IDependencyModelFactory.Implement(
                providerType: "providerType",
                id: "someId");
            var mockSnapshot = ITargetedDependenciesSnapshotFactory.Implement();

            var dependency = new Dependency(mockModel, mockSnapshot);

            var newDependency = dependency.SetProperties(
                caption: "newcaption",
                resolved: true,
                flags: DependencyTreeFlags.BaseReferenceFlags,
                dependencyIDs: ImmutableList <string> .Empty.Add("aaa"));

            Assert.Equal("newcaption", newDependency.Caption);
            Assert.Equal(true, newDependency.Resolved);
            Assert.True(newDependency.Flags.Equals(DependencyTreeFlags.BaseReferenceFlags));
            Assert.True(newDependency.DependencyIDs.Count == 1);
        }
Esempio n. 29
0
        public void IsOrHasUnresolvedDependency()
        {
            var dependency1  = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Yyy"",
    ""Id"": ""tfm1\\yyy\\dependencyExisting"",
    ""Name"":""dependencyExisting"",
    ""Caption"":""DependencyExisting"",
    ""Resolved"":""false""
}");
            var mockSnapshot = ITargetedDependenciesSnapshotFactory.Implement();

            Assert.True(dependency1.IsOrHasUnresolvedDependency(mockSnapshot));

            var dependency2 = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Yyy"",
    ""Id"": ""tfm1\\yyy\\dependencyExisting"",
    ""Name"":""dependencyExisting"",
    ""Caption"":""DependencyExisting"",
    ""Resolved"":""true""
}");

            mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("tfm1\\yyy\\dependencyExisting", true);

            Assert.True(dependency2.IsOrHasUnresolvedDependency(mockSnapshot));

            var dependency3 = IDependencyFactory.FromJson(@"
{
    ""ProviderType"": ""Yyy"",
    ""Id"": ""tfm1\\yyy\\dependencyExisting"",
    ""Name"":""dependencyExisting"",
    ""Caption"":""DependencyExisting"",
    ""Resolved"":""true""
}");

            mockSnapshot = ITargetedDependenciesSnapshotFactory.ImplementHasUnresolvedDependency("tfm1\\yyy\\dependencyExisting", false);

            Assert.False(dependency3.IsOrHasUnresolvedDependency(mockSnapshot));
        }
Esempio n. 30
0
        public void TConstructor()
        {
            const string projectPath      = @"c:\somefolder\someproject\a.csproj";
            var          targetFramework  = ITargetFrameworkFactory.Implement("tfm1");
            var          previousSnapshot = ITargetedDependenciesSnapshotFactory.Implement(
                dependenciesWorld: new Dictionary <string, IDependency>(),
                topLevelDependencies: new List <IDependency>());

            var catalogs = IProjectCatalogSnapshotFactory.Create();
            var snapshot = new TestableTargetedDependenciesSnapshot(
                projectPath,
                targetFramework,
                previousSnapshot,
                catalogs);

            Assert.NotNull(snapshot.TargetFramework);
            Assert.Equal("tfm1", snapshot.TargetFramework.FullName);
            Assert.Equal(projectPath, snapshot.ProjectPath);
            Assert.Equal(catalogs, snapshot.Catalogs);
            Assert.Equal(previousSnapshot.TopLevelDependencies, snapshot.TopLevelDependencies);
            Assert.Equal(previousSnapshot.DependenciesWorld, snapshot.DependenciesWorld);
        }