コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
        }
コード例 #6
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);
        }