Exemplo n.º 1
0
        public async Task Command_can_be_executed_with_some_inherited_environment_variables_overwritten()
        {
            // Arrange
            var salt                = Guid.NewGuid();
            var variableToKeep      = $"CLIWRAP_TEST_KEEP_{salt}";
            var variableToOverwrite = $"CLIWRAP_TEST_OVERWRITE_{salt}";
            var variableToUnset     = $"CLIWRAP_TEST_UNSET_{salt}";

            using (EnvironmentVariable.Set(variableToKeep, "foo"))          // will be left unchanged
                using (EnvironmentVariable.Set(variableToOverwrite, "bar")) // will be overwritten
                    using (EnvironmentVariable.Set(variableToUnset, "baz")) // will be unset
                    {
                        var cmd = Cli.Wrap("dotnet")
                                  .WithArguments(a => a
                                                 .Add(Dummy.Program.FilePath)
                                                 .Add("print-environment-variables"))
                                  .WithEnvironmentVariables(e => e
                                                            .Set(variableToOverwrite, "new bar")
                                                            .Set(variableToUnset, null));

                        // Act
                        var result = await cmd.ExecuteBufferedAsync();

                        var stdOutLines = result.StandardOutput.Split(Environment.NewLine);

                        // Assert
                        stdOutLines.Should().Contain(new[]
                        {
                            $"[{variableToKeep}] = foo",
                            $"[{variableToOverwrite}] = new bar"
                        });

                        stdOutLines.Should().NotContain(new[]
                        {
                            $"[{variableToOverwrite}] = bar",
                            $"[{variableToUnset}] = baz"
                        });
                    }
        }