예제 #1
0
        public async Task WhenSettingAGlobalProperty_TheRuleIsPassedToTheExtensionValueProvider()
        {
            bool rulePassed             = false;
            var  extensionValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                onSetPropertyValue: (propertyName, value, globals, rule) =>
            {
                rulePassed = rule is not null;
                return(ImmutableDictionary <string, object?> .Empty.Add(propertyName, value));
            });
            var metadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("MyProperty");

            var lazy = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => extensionValueProvider,
                metadata);

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                ImmutableArray.Create(lazy));

            properties.SetRuleContext(new Rule());

            await properties.SetPropertyValueAsync("MyProperty", "alpha");

            Assert.True(rulePassed);
        }
예제 #2
0
        public async Task WhenRetrievingStandardPropertyValues_TheEmptyStringIsReturnedForUndefinedProperties()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var standardPropertyNames = new[]
            {
                "CommandName",
                "ExecutablePath",
                "CommandLineArguments",
                "WorkingDirectory",
                "LaunchUrl",
                "EnvironmentVariables"
            };

            foreach (var standardPropertyName in standardPropertyNames)
            {
                var evaluatedValue = await properties.GetEvaluatedPropertyValueAsync(standardPropertyName);

                Assert.Equal(expected: string.Empty, actual: evaluatedValue);
                var unevaluatedValue = await properties.GetUnevaluatedPropertyValueAsync(standardPropertyName);

                Assert.Equal(expected: string.Empty, actual: unevaluatedValue);
            }
        }
예제 #3
0
        public async Task WhenSettingAGlobalProperty_TheExtensionValueProviderIsCalled()
        {
            string?updatedPropertyName    = null;
            string?updatedPropertyValue   = null;
            var    extensionValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                onSetPropertyValue: (propertyName, value, globals, rule) =>
            {
                updatedPropertyName  = propertyName;
                updatedPropertyValue = value;
                return(ImmutableDictionary <string, object?> .Empty.Add(propertyName, value));
            });
            var metadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("MyProperty");

            var lazy = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => extensionValueProvider,
                metadata);

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                ImmutableArray.Create(lazy));

            await properties.SetPropertyValueAsync("MyProperty", "alpha");

            Assert.Equal(expected: "MyProperty", actual: updatedPropertyName);
            Assert.Equal(expected: "alpha", actual: updatedPropertyValue);
        }
예제 #4
0
        public async Task WhenRetrievingItemPropertyNames_AllStandardProfilePropertyNamesAreReturnedEvenIfNotDefined()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var propertyNames = await properties.GetPropertyNamesAsync();

            Assert.Contains("CommandName", propertyNames);
            Assert.Contains("ExecutablePath", propertyNames);
            Assert.Contains("CommandLineArguments", propertyNames);
            Assert.Contains("WorkingDirectory", propertyNames);
            Assert.Contains("LaunchBrowser", propertyNames);
            Assert.Contains("LaunchUrl", propertyNames);
            Assert.Contains("EnvironmentVariables", propertyNames);
        }
예제 #5
0
        public async Task WhenRetrievingPropertyNames_GlobalSettingExtensionNamesAreIncludedForDefinedProperties()
        {
            var alphaValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                (propertyName, globals, rule) =>
            {
                return("alpha");
            });
            var alphaMetadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("AlphaProperty");
            var alphaLazy     = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => alphaValueProvider,
                alphaMetadata);

            var betaValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                (propertyName, globals, rule) =>
            {
                return("");
            });
            var betaMetadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("BetaProperty");
            var betaLazy     = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => betaValueProvider,
                betaMetadata);

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                ImmutableArray.Create(alphaLazy, betaLazy));

            var names = await properties.GetPropertyNamesAsync();

            Assert.Contains("AlphaProperty", names);
            Assert.DoesNotContain("BetaProperty", names);
        }
예제 #6
0
        public async Task WhenRetrievingAGlobalProperty_TheRuleIsPassedToTheExtensionValueProvider()
        {
            bool rulePassed             = false;
            var  extensionValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                (propertyName, globals, rule) =>
            {
                rulePassed = rule is not null;
                return("alpha");
            });
            var metadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("MyProperty");

            var lazy = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => extensionValueProvider,
                metadata);

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                ImmutableArray.Create(lazy));

            properties.SetRuleContext(new Rule());

            var propertyValue = await properties.GetEvaluatedPropertyValueAsync("MyProperty");

            Assert.True(rulePassed);
            Assert.Equal(expected: "alpha", actual: propertyValue);
        }
예제 #7
0
        public async Task WhenRetrievingAGlobalProperty_TheExtensionValueProviderIsCalled()
        {
            string?requestedPropertyName  = null;
            var    extensionValueProvider = IGlobalSettingExtensionValueProviderFactory.Create(
                (propertyName, globals, rule) =>
            {
                requestedPropertyName = propertyName;
                return("alpha");
            });
            var metadata = ILaunchProfileExtensionValueProviderMetadataFactory.Create("MyProperty");

            var lazy = new Lazy <IGlobalSettingExtensionValueProvider, ILaunchProfileExtensionValueProviderMetadata>(
                () => extensionValueProvider,
                metadata);

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                ImmutableArray.Create(lazy));

            var propertyValue = await properties.GetEvaluatedPropertyValueAsync("MyProperty");

            Assert.Equal(expected: "MyProperty", actual: requestedPropertyName);
            Assert.Equal(expected: "alpha", actual: propertyValue);
        }
예제 #8
0
        public async Task WhenSettingValuesNotHandledByExtenders_ValuesOfTheExpectedTypesAreStoredInOtherSettings()
        {
            var writableProfile = new WritableLaunchProfile
            {
                Name = "Profile1",
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { writableProfile.ToLaunchProfile() },
                tryUpdateProfileCallback: (profile, action) =>
            {
                // Update writableProfile since we're hanging on to it rather than the profile given us by the mock.
                action(writableProfile);
            });

            var rule = new Rule
            {
                Properties =
                {
                    new IntProperty    {
                        Name = "anInteger"
                    },
                    new BoolProperty   {
                        Name = "aBoolean"
                    },
                    new StringProperty {
                        Name = "aString"
                    },
                    new EnumProperty   {
                        Name = "anEnumStoredAsAString"
                    }
                    // anotherString intentionally not represented
                }
            };

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            properties.SetRuleContext(rule);

            await properties.SetPropertyValueAsync("anInteger", "2");

            await properties.SetPropertyValueAsync("aBoolean", "false");

            await properties.SetPropertyValueAsync("aString", "Hello, world!");

            await properties.SetPropertyValueAsync("anEnumStoredAsAString", "valueTwo");

            await properties.SetPropertyValueAsync("anotherString", "Hello, friends!");

            Assert.Equal(expected: 2, actual: writableProfile.OtherSettings["anInteger"]);
            Assert.Equal(expected: false, actual: writableProfile.OtherSettings["aBoolean"]);
            Assert.Equal(expected: "Hello, world!", actual: writableProfile.OtherSettings["aString"]);
            Assert.Equal(expected: "valueTwo", actual: writableProfile.OtherSettings["anEnumStoredAsAString"]);
            Assert.Equal(expected: "Hello, friends!", actual: writableProfile.OtherSettings["anotherString"]);
        }
예제 #9
0
        public void WhenRetrievingItemProperties_ThePropertyKindIsItemGroup()
        {
            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            Assert.Equal(expected: PropertyKind.ItemGroup, actual: properties.PropertyKind);
        }
예제 #10
0
        public void WhenRetrievingItemProperties_TheFilePathIsTheProjectPath()
        {
            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            Assert.Equal(expected: DefaultTestProjectPath, actual: properties.FileFullPath);
        }
예제 #11
0
        public void WhenRetrievingItemProperties_TheContextHasTheExpectedValues()
        {
            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                CreateDefaultTestLaunchSettings(),
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var context = properties.Context;

            Assert.Equal(expected: DefaultTestProjectPath, actual: context.File);
            Assert.True(context.IsProjectFile);
            Assert.Equal(expected: "Profile1", actual: context.ItemName);
            Assert.Equal(expected: LaunchProfileProjectItemProvider.ItemType, actual: context.ItemType);
        }
예제 #12
0
        public async Task WhenRetrievingStandardPropertyValues_TheExpectedValuesAreReturned()
        {
            var profile1 = new WritableLaunchProfile
            {
                Name                 = "Profile1",
                CommandLineArgs      = "alpha beta gamma",
                CommandName          = "epsilon",
                EnvironmentVariables = { ["One"] = "1", ["Two"] = "2" },
                ExecutablePath       = @"D:\five\six\seven\eight.exe",
                LaunchBrowser        = true,
                LaunchUrl            = "https://localhost/profile",
                WorkingDirectory     = @"C:\users\other\temp"
            };

            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });
            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var expectedValues = new Dictionary <string, string>
            {
                ["CommandLineArguments"] = "alpha beta gamma",
                ["CommandName"]          = "epsilon",
                ["EnvironmentVariables"] = "One=1,Two=2",
                ["ExecutablePath"]       = @"D:\five\six\seven\eight.exe",
                ["LaunchBrowser"]        = "true",
                ["LaunchUrl"]            = "https://localhost/profile",
                ["WorkingDirectory"]     = @"C:\users\other\temp",
            };

            foreach (var(propertyName, expectedPropertyValue) in expectedValues)
            {
                var actualUnevaluatedValue = await properties.GetUnevaluatedPropertyValueAsync(propertyName);

                var actualEvaluatedValue = await properties.GetEvaluatedPropertyValueAsync(propertyName);

                Assert.Equal(expectedPropertyValue, actualUnevaluatedValue);
                Assert.Equal(expectedPropertyValue, actualEvaluatedValue);
            }
        }
예제 #13
0
        public async Task WhenSettingStandardPropertyValues_StandardCallbacksAreFound()
        {
            var profile1 = new WritableLaunchProfile
            {
                Name        = "Profile1",
                CommandName = "epsilon",
            };

            bool callbackInvoked;
            var  launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() },
                tryUpdateProfileCallback: (profile, action) =>
            {
                callbackInvoked = true;
            });
            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var newValues = new Dictionary <string, string>
            {
                ["CommandLineArguments"] = "delta epsilon",
                ["CommandName"]          = "arugula",
                ["EnvironmentVariables"] = "Three=3,Four=4",
                ["ExecutablePath"]       = @"D:\nine\ten.exe",
                ["LaunchBrowser"]        = "false",
                ["LaunchUrl"]            = "https://localhost/myOtherProfile",
                ["WorkingDirectory"]     = @"D:\aardvark",
            };

            foreach (var(propertyName, newPropertyValue) in newValues)
            {
                callbackInvoked = false;
                await properties.SetPropertyValueAsync(propertyName, newPropertyValue);

                Assert.True(callbackInvoked);
            }
        }
예제 #14
0
        public async Task WhenRetrievingPropertyNames_PropertiesInOtherSettingsAreIncluded()
        {
            var profile1 = new WritableLaunchProfile
            {
                Name          = "Profile1",
                OtherSettings = { { "alpha", 1 } }
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var names = await properties.GetPropertyNamesAsync();

            Assert.Contains("alpha", names);
        }
예제 #15
0
        public async Task WhenRetrievingTheLaunchBrowserValue_TheDefaultValueIsFalse()
        {
            var profile1 = new WritableLaunchProfile {
                Name = "Profile1"
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var evaluatedValue = await properties.GetEvaluatedPropertyValueAsync("LaunchBrowser");

            Assert.Equal(expected: "false", actual: evaluatedValue);
            var unevaluatedValue = await properties.GetUnevaluatedPropertyValueAsync("LaunchBrowser");

            Assert.Equal(expected: "false", actual: unevaluatedValue);
        }
예제 #16
0
        public async Task WhenRetrievingPropertyNames_PropertiesInGlobalSettingsAreNotIncluded()
        {
            var profile1 = new WritableLaunchProfile
            {
                Name          = "Profile1",
                OtherSettings = { { "alpha", 1 } }
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() },
                globalSettings: ImmutableDictionary <string, object> .Empty.Add("beta", "value"));

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            var names = await properties.GetPropertyNamesAsync();

            Assert.DoesNotContain("beta", names);
        }
예제 #17
0
        public async Task WhenRetrievingValuesFromOtherSettings_ValuesArePropertyConvertedToStrings()
        {
            var profile1 = new WritableLaunchProfile
            {
                Name          = "Profile1",
                OtherSettings =
                {
                    { "anInteger",                            1 },
                    { "aBoolean",                true           },
                    { "aString",                 "Hello, world" },
                    { "anEnumStoredAsAsAString", "valueOne"     },
                    { "anotherString",           "Hi, friends!" }
                }
            };
            var launchSettingsProvider = ILaunchSettingsProviderFactory.Create(
                launchProfiles: new[] { profile1.ToLaunchProfile() });

            var rule = new Rule
            {
                Properties =
                {
                    new IntProperty    {
                        Name = "anInteger"
                    },
                    new BoolProperty   {
                        Name = "aBoolean"
                    },
                    new StringProperty {
                        Name = "aString"
                    },
                    new EnumProperty   {
                        Name = "anEnumStoredAsAString"
                    }
                    // anotherString intentionally not represented
                }
            };

            var properties = new LaunchProfileProjectProperties(
                DefaultTestProjectPath,
                "Profile1",
                launchSettingsProvider,
                EmptyLaunchProfileExtensionValueProviders,
                EmptyGlobalSettingExtensionValueProviders);

            properties.SetRuleContext(rule);

            var anIntegerValue = await properties.GetEvaluatedPropertyValueAsync("anInteger");

            Assert.Equal(expected: "1", actual: anIntegerValue);

            var aBooleanValue = await properties.GetEvaluatedPropertyValueAsync("aBoolean");

            Assert.Equal(expected: "true", actual: aBooleanValue);

            var aStringValue = await properties.GetEvaluatedPropertyValueAsync("aString");

            Assert.Equal(expected: "Hello, world", actual: aStringValue);

            var anEnumStoredAsAsAStringValue = await properties.GetEvaluatedPropertyValueAsync("anEnumStoredAsAsAString");

            Assert.Equal(expected: "valueOne", actual: anEnumStoredAsAsAStringValue);

            var anotherStringValue = await properties.GetEvaluatedPropertyValueAsync("anotherString");

            Assert.Equal(expected: "Hi, friends!", actual: anotherStringValue);
        }