Exemplo n.º 1
0
                public void Should_Transform_Text_From_Disc_Template_Using_Specified_Placeholders()
                {
                    // Given
                    var fileSystem = new FakeFileSystem(false);

                    fileSystem.GetCreatedFile("/Working/template.txt", "Hello {subject}");

                    var environment = Substitute.For <ICakeEnvironment>();

                    environment.WorkingDirectory.Returns("/Working");

                    var context = Substitute.For <ICakeContext>();

                    context.FileSystem.Returns(fileSystem);
                    context.Environment.Returns(environment);

                    var transform = TextTransformationAliases.TransformTextFile(context, "./template.txt", "{", "}");

                    transform.WithToken("subject", "World");

                    // When
                    var result = transform.ToString();


                    // Then
                    Assert.Equal("Hello World", result);
                }
Exemplo n.º 2
0
                public void Should_Throw_If_Context_Is_Null()
                {
                    // Given, When
                    var result = Record.Exception(() =>
                                                  TextTransformationAliases.TransformText(null, "Hello World", "{", "}"));

                    // Then
                    Assert.IsArgumentNullException(result, "context");
                }
Exemplo n.º 3
0
                public void Should_Throw_If_Context_Is_Null()
                {
                    // Given, When
                    var result = Record.Exception(() =>
                                                  TextTransformationAliases.TransformTextFile(
                                                      null, new FilePath("./template.txt"), "{", "}"));

                    // Then
                    Assert.IsArgumentNullException(result, "context");
                }
Exemplo n.º 4
0
                public void Should_Create_Text_Transformation()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = TextTransformationAliases.TransformText(context, "Hello World");

                    // Then
                    Assert.Equal("Hello World", result.ToString());
                }
Exemplo n.º 5
0
                public void Should_Throw_If_Template_Is_Null()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = Record.Exception(() =>
                                                  TextTransformationAliases.TransformText(context, null, "{", "}"));

                    // Then
                    Assert.IsArgumentNullException(result, "template");
                }
Exemplo n.º 6
0
                public void Should_Throw_If_Right_Placeholder_Is_Null()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = Record.Exception(() =>
                                                  TextTransformationAliases.TransformText(context, null, "{", null));

                    // Then
                    Assert.IsArgumentNullException(result, "rightPlaceholder");
                }
Exemplo n.º 7
0
                public void Should_Throw_If_Left_Placeholder_Is_Null()
                {
                    // Given
                    var context = Substitute.For <ICakeContext>();

                    // When
                    var result = Record.Exception(() =>
                                                  TextTransformationAliases.TransformTextFile(
                                                      context, new FilePath("./template.txt"), null, "}"));

                    // Then
                    Assert.IsArgumentNullException(result, "leftPlaceholder");
                }
            public void Should_Return_Same_Instance()
            {
                // Given
                var context        = Substitute.For <ICakeContext>();
                var transformation = TextTransformationAliases.TransformText(
                    context, "<%greeting%> World!");

                // When
                var result = transformation.WithToken("greeting", "Hello");

                // Then
                Assert.Same(transformation, result);
            }
            public void Should_Register_The_Provided_Token_With_The_Template()
            {
                // Given
                var context        = Substitute.For <ICakeContext>();
                var transformation = TextTransformationAliases.TransformText(
                    context, "<%greeting%> World!");

                // When
                transformation.WithToken("greeting", "Hello");

                // Then
                Assert.Equal("Hello World!", transformation.ToString());
            }
Exemplo n.º 10
0
                public void Should_Transform_Text_Using_Specified_Placeholders()
                {
                    // Given
                    var context   = Substitute.For <ICakeContext>();
                    var transform = TextTransformationAliases.TransformText(context, "Hello <%subject%>");

                    transform.WithToken("subject", "World");

                    // When
                    var result = transform.ToString();

                    // Then
                    Assert.Equal("Hello World", result);
                }
            public void Should_Register_The_Provided_Tokens_With_The_Template()
            {
                // Given
                var context        = Substitute.For <ICakeContext>();
                var transformation = TextTransformationAliases.TransformText(
                    context, "<%greeting%> World and <%name%>!");

                // When
                var tokens = new Dictionary <string, object>
                {
                    { "greeting", "Hello" },
                    { "name", "Tim" }
                };

                transformation.WithTokens(tokens);

                // Then
                Assert.Equal("Hello World and Tim!", transformation.ToString());
            }
Exemplo n.º 12
0
                public void Should_Create_Text_Transformation_From_Disc_Template()
                {
                    // Given
                    var environment = FakeEnvironment.CreateUnixEnvironment();
                    var fileSystem  = new FakeFileSystem(environment);

                    fileSystem.CreateFile("/Working/template.txt").SetContent("Hello World");

                    var context = Substitute.For <ICakeContext>();

                    context.FileSystem.Returns(fileSystem);
                    context.Environment.Returns(environment);

                    // When
                    var result = TextTransformationAliases.TransformTextFile(
                        context, "./template.txt", "{", "}");

                    // Then
                    Assert.Equal("Hello World", result.ToString());
                }
Exemplo n.º 13
0
                public void Should_Transform_Text_From_Disc_Template_Using_Default_Placeholders()
                {
                    // Given
                    var environment = FakeEnvironment.CreateUnixEnvironment();
                    var fileSystem  = new FakeFileSystem(environment);

                    fileSystem.CreateFile("/Working/template.txt").SetContent("Hello <%subject%>");

                    var context = Substitute.For <ICakeContext>();

                    context.FileSystem.Returns(fileSystem);
                    context.Environment.Returns(environment);

                    var transform = TextTransformationAliases.TransformTextFile(context, "./template.txt");

                    transform.WithToken("subject", "World");

                    // When
                    var result = transform.ToString();

                    // Then
                    Assert.Equal("Hello World", result);
                }