Ejemplo n.º 1
0
        public void returns_expected_when_no_variables_has_been_provided_but_single_variable_is_referenced()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>();

            var result = sut.ExpandVariables(stubVariables, "foo $(BAR)");

            Assert.Equal("foo $(BAR)", result);
        }
Ejemplo n.º 2
0
        public void throws_expected_exception_when_one_variable_references_another_none_declared_variable()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                { "BAR", "bar $(NOT-DECLARED)" },
            };

            Assert.Throws <VariableNotDeclaredException>(() => sut.ExpandVariables(stubVariables, "foo $(BAR)"));
        }
Ejemplo n.º 3
0
        public void prevents_self_reference_in_variables()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                { "FOO", "$(FOO)" },
            };

            Assert.Throws <CircularVariableReferenceException>(() => sut.ExpandVariables(stubVariables, "foo"));
        }
Ejemplo n.º 4
0
        public void prevents_direct_circular_references_between_variables()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                { "FOO", "$(BAR)" },
                { "BAR", "$(FOO)" },
            };

            Assert.Throws <CircularVariableReferenceException>(() => sut.ExpandVariables(stubVariables, "foo $(BAR)"));
        }
Ejemplo n.º 5
0
        public void returns_expected_when_expanding_environment_variable_that_does_not_exist()
        {
            var sut = new VariableHelperBuilder()
                      .WithEnvironmentVariableProvider(new StubEnvironmentVariableProvider())
                      .Build();

            var stubEmptyVariables = new Dictionary <string, string>();

            var result = sut.ExpandVariables(stubEmptyVariables, "foo ${BAR}");

            Assert.Equal("foo ${BAR}", result);
        }
Ejemplo n.º 6
0
        public void returns_expected_when_variable_is_expanded_inside_quotes()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                { "BAR", "bar" }
            };

            var result = sut.ExpandVariables(stubVariables, "foo \"$(BAR)\"");

            Assert.Equal("foo \"bar\"", result);
        }
Ejemplo n.º 7
0
        public void returns_expected_when_single_variable_has_been_provided_and_no_variables_are_referenced()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                {
                    "dummy", "dummy"
                }
            };
            var result = sut.ExpandVariables(stubVariables, "foo");

            Assert.Equal("foo", result);
        }
Ejemplo n.º 8
0
        public void variables_can_reference_other_variables_in_random_order()
        {
            var sut           = new VariableHelperBuilder().Build();
            var stubVariables = new Dictionary <string, string>
            {
                { "QUX", "qux" },
                { "BAZ", "baz $(QUX)" },
                { "BAR", "bar $(BAZ)" },
            };

            var result = sut.ExpandVariables(stubVariables, "foo $(BAR)");

            Assert.Equal("foo bar baz qux", result);
        }
Ejemplo n.º 9
0
        public void returns_expected_when_expanding_multiple_environment_variables()
        {
            var stubEnvVarValues = new Dictionary <string, string>
            {
                { "FOO", "foo" },
                { "BAR", "bar" },
                { "BAZ", "baz" },
                { "QUX", "qux" },
            };

            var sut = new VariableHelperBuilder()
                      .WithEnvironmentVariableProvider(new FakeEnvironmentVariableProvider(stubEnvVarValues))
                      .Build();

            var stubEmptyVariables = new Dictionary <string, string>();

            var result = sut.ExpandVariables(stubEmptyVariables, "foo ${BAR} ${BAZ} ${QUX}");

            Assert.Equal("foo bar baz qux", result);
        }
Ejemplo n.º 10
0
        public void returns_expected_when_expanding_variable_with_environment_variable_reference_inside()
        {
            var stubEnvVarValues = new Dictionary <string, string>
            {
                { "BAZ", "baz" },
                { "QUX", "qux" },
            };

            var sut = new VariableHelperBuilder()
                      .WithEnvironmentVariableProvider(new FakeEnvironmentVariableProvider(stubEnvVarValues))
                      .Build();

            var stubVariables = new Dictionary <string, string>
            {
                { "BAR", "${BAZ} ${QUX}" }
            };

            var result = sut.ExpandVariables(stubVariables, "foo $(BAR)");

            Assert.Equal("foo baz qux", result);
        }
Ejemplo n.º 11
0
        public void variables_are_expanded_when_actions_are_executed()
        {
            var spy = new SpyCommandLineExecutor();

            var variableHelper = new VariableHelperBuilder().Build();

            var sut = new EngineBuilder()
                      .WithCommandLineExecutor(spy)
                      .WithVariableHelper(variableHelper)
                      .WithFileSystem(new StubFileSystem(fileContents: new[]
            {
                "FOO=bar",
                "foo:",
                "  foo-$(FOO)"
            })
                                      )
                      .Build();

            sut.Run(new[] { "foo" });

            Assert.Equal(new[] { "foo-bar" }, spy.executedArguments);
        }