示例#1
0
        public void Execute_WithNotExistingFile()
        {
            var buildEngine = new Mock <IBuildEngine>(MockBehavior.Strict);

            buildEngine.Setup(b => b.ProjectFileOfTaskNode)
            .Returns("The project file");
            buildEngine.Setup(b => b.LineNumberOfTaskNode)
            .Returns(1234);
            buildEngine.Setup(b => b.ColumnNumberOfTaskNode)
            .Returns(5678);
            buildEngine.Setup(b => b.LogErrorEvent(It.IsAny <BuildErrorEventArgs>()))
            .Callback((BuildErrorEventArgs args) =>
            {
                args.Message.Should().Be("The \"not_existing_file.yaml\" YAML input file does not exist.");
            });

            var task = new YamlToJson()
            {
                BuildEngine   = buildEngine.Object,
                YamlInputFile = @"not_existing_file.yaml"
            };

            var result = task.Execute();

            result.Should().BeFalse();

            buildEngine.Verify(b => b.LogErrorEvent(It.IsAny <BuildErrorEventArgs>()));
        }
示例#2
0
        public void Execute_WithNoIndentation()
        {
            if (Directory.Exists(@"sub\folder\"))
            {
                Directory.Delete(@"sub\folder\", true);
            }

            Directory.CreateDirectory(@"sub\folder\");

            var yaml = @"
object:
- value: 'v1'
- booleanValue: false
- decimalValue: 11.22
- stringValue: ""Blabla""
- stringValue2: 'Blabla'
- stringValueWithInteger: '12345'
- stringValueWithDecimal: '12.34'
- nullValue: 
- innerObject:
    innerIntValue: 1234
";

            File.WriteAllText(@"sub\folder\yaml.yaml", yaml);

            var buildEngine = new Mock <IBuildEngine>(MockBehavior.Strict);

            buildEngine.Setup(b => b.ProjectFileOfTaskNode)
            .Returns("The project file");
            buildEngine.Setup(b => b.LogMessageEvent(It.IsAny <BuildMessageEventArgs>()))
            .Callback((BuildMessageEventArgs args) =>
            {
                args.Message.Should().Be("Converting the YAML file \"sub\\folder\\yaml.yaml\" to the \"sub\\folder\\json.json\" JSON file (without indentation).");
            });

            var task = new YamlToJson()
            {
                BuildEngine     = buildEngine.Object,
                YamlInputFile   = @"sub\folder\yaml.yaml",
                JsonOutputFile  = @"sub\folder\json.json",
                WithIndentation = false
            };

            var result = task.Execute();

            result.Should().BeTrue();

            var json = File.ReadAllText(@"sub\folder\json.json");

            json.Should().Be(@"{""object"":[{""value"":""v1""},{""booleanValue"":false},{""decimalValue"":11.22},{""stringValue"":""Blabla""},{""stringValue2"":""Blabla""},{""stringValueWithInteger"":""12345""},{""stringValueWithDecimal"":""12.34""},{""nullValue"":null},{""innerObject"":{""innerIntValue"":1234}}]}");

            buildEngine.Verify(b => b.LogMessageEvent(It.IsAny <BuildMessageEventArgs>()));
        }