Ejemplo n.º 1
0
        public async Task WhenAskedForLaunchProfileItemTypes_GetItemsAsyncReturnsAnItemForEachProfile()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var items = await itemProvider.GetItemsAsync(LaunchProfilesProjectItemProvider.ItemType);

            Assert.Collection(items,
                              item => Assert.Equal("Profile1", item.EvaluatedInclude),
                              item => Assert.Equal("Profile2", item.EvaluatedInclude));

            items = await itemProvider.GetItemsAsync(LaunchProfilesProjectItemProvider.ItemType, "Profile2");

            Assert.Collection(items,
                              item => Assert.Equal("Profile2", item.EvaluatedInclude));
        }
Ejemplo n.º 2
0
        public async Task WhenProjectPropertyContextHasLaunchProfileItemType_GetItemsAsyncReturnsAnItemWithAMatchingName()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var context = new TestProjectPropertiesContext(
                isProjectFile: true,
                file: "Foo",
                itemType: LaunchProfilesProjectItemProvider.ItemType,
                itemName: "Profile2");

            var item = await itemProvider.GetItemAsync(context);

            Assert.NotNull(item);
            Assert.Equal("Profile2", item !.EvaluatedInclude);
        }
Ejemplo n.º 3
0
        public async Task WhenProjectPropertyContextHasTheWrongItemType_GetItemsAsyncReturnsNull()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var context = new TestProjectPropertiesContext(
                isProjectFile: true,
                file: "Foo",
                itemType: "RandomItemType",
                itemName: "Profile2");

            var item = await itemProvider.GetItemAsync(context);

            Assert.Null(item);
        }
            public ProjectItem(string name, string projectFilePath, LaunchProfilesProjectItemProvider provider)
            {
                _name            = name;
                _projectFilePath = projectFilePath;
                _provider        = provider;

                PropertiesContext = new ProjectPropertiesContext(name, projectFilePath);
            }
Ejemplo n.º 5
0
        public async Task GetItemTypesAsync_ReturnsLaunchProfile()
        {
            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                ILaunchSettingsProviderFactory.Create());

            var itemTypes = await itemProvider.GetItemTypesAsync();

            Assert.Single(itemTypes, LaunchProfilesProjectItemProvider.ItemType);
        }
Ejemplo n.º 6
0
        public async Task WhenThereAreNoLaunchProfiles_GetItemsAsyncReturnsAnEmptyEnumerable()
        {
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new LaunchProfile[0]);

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var items = await itemProvider.GetItemsAsync();

            Assert.Empty(items);
        }
Ejemplo n.º 7
0
        public async Task WhenAddingAnItem_AnExceptionIsThrownIfTheItemTypeIsWrong()
        {
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create();

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                var item = await itemProvider.AddAsync(itemType: "RandomItemType", include: "Alpha Profile");
            });
        }
Ejemplo n.º 8
0
        public async Task WhenThereAreLaunchProfiles_GetExistingItemTypesAsyncReturnsASingleItem()
        {
            var profile = new WritableLaunchProfile {
                Name = "Test"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var existingItemTypes = await itemProvider.GetExistingItemTypesAsync();

            Assert.Single(existingItemTypes, LaunchProfilesProjectItemProvider.ItemType);
        }
Ejemplo n.º 9
0
        public async Task WhenFindingAnItemByName_NullIsReturnedIfNoMatchingItemExists()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var item = await itemProvider.FindItemByNameAsync("Profile3");

            Assert.Null(item);
        }
Ejemplo n.º 10
0
        public async Task WhenFindingAnItemByName_TheMatchingItemIsReturnedIfItExists()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var item = await itemProvider.FindItemByNameAsync("Profile2");

            Assert.NotNull(item);
            Assert.Equal(expected: "Profile2", actual: item !.EvaluatedInclude);
        }
Ejemplo n.º 11
0
        public async Task WhenAddingAnItem_TheReturnedItemHasTheCorrectName()
        {
            ILaunchProfile?newProfile             = null;
            var            launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                addOrUpdateProfileCallback: (p, a) =>
            {
                newProfile = p;
            },
                getProfilesCallback: initialProfiles =>
            {
                Assert.NotNull(newProfile);
                return(initialProfiles.Add(newProfile !));
            });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var item = await itemProvider.AddAsync(itemType : LaunchProfilesProjectItemProvider.ItemType, include : "Alpha Profile");

            Assert.Equal(expected: "Alpha Profile", actual: item !.EvaluatedInclude);
            Assert.Equal(expected: "Alpha Profile", actual: item !.UnevaluatedInclude);
        }
Ejemplo n.º 12
0
        public async Task WhenAskedForOtherItemTypes_GetItemsAsyncReturnsAnEmptyEnumerable()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile(), profile2.ToLaunchProfile() });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var items = await itemProvider.GetItemsAsync("RandomItemType");

            Assert.Empty(items);

            items = await itemProvider.GetItemsAsync("RandomItemType", "Profile2");

            Assert.Empty(items);
        }
Ejemplo n.º 13
0
        public async Task WhenGivenMultipleProjectPropertyContexts_GetItemsAsyncReturnsNullOrAnItemForEach()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var profile2 = new WritableLaunchProfile {
                Name = "Profile2"
            };
            var profile3 = new WritableLaunchProfile {
                Name = "Profile3"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[]
            {
                profile1.ToLaunchProfile(),
                profile2.ToLaunchProfile(),
                profile3.ToLaunchProfile()
            });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            List <IProjectPropertiesContext> contexts = new()
            {
                new TestProjectPropertiesContext(true, "Foo", null, "Profile3"),
                new TestProjectPropertiesContext(true, "Foo", "RandomItemType", "Profile2"),
                new TestProjectPropertiesContext(true, "Foo", LaunchProfilesProjectItemProvider.ItemType, "Profile1")
            };

            var items = await itemProvider.GetItemsAsync(contexts);

            Assert.Collection(items,
                              item => Assert.Equal("Profile3", item !.EvaluatedInclude),
                              item => Assert.Null(item),
                              item => Assert.Equal("Profile1", item !.EvaluatedInclude));
        }
Ejemplo n.º 14
0
        public async Task WhenAddingMultipleItems_TheReturnedItemsHaveTheCorrectNames()
        {
            ImmutableList <ILaunchProfile> newProfiles = ImmutableList <ILaunchProfile> .Empty;;
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                addOrUpdateProfileCallback: (p, a) =>
            {
                newProfiles = newProfiles.Add(p);
            },
                getProfilesCallback: initialProfiles =>
            {
                return(initialProfiles.AddRange(newProfiles));
            });

            var itemProvider = new LaunchProfilesProjectItemProvider(
                UnconfiguredProjectFactory.Create(),
                launchSettingsProvider);

            var items = await itemProvider.AddAsync(
                new Tuple <string, string, IEnumerable <KeyValuePair <string, string> >?>[]
            {
                new(LaunchProfilesProjectItemProvider.ItemType, "Alpha Profile", null),
                new(LaunchProfilesProjectItemProvider.ItemType, "Beta Profile", null),
                new(LaunchProfilesProjectItemProvider.ItemType, "Gamma Profile", null),
            });