public void WriteBlockMixedAttributesAndBlocks() { var block = new OclBlock("MyBlock") { new OclAttribute("First", 1), new OclAttribute("Second", 2), new OclBlock("Third") { new OclAttribute("ThirdChild", 3) }, new OclBlock("Fourth"), new OclAttribute("Last", 9) }; var expected = @"MyBlock { First = 1 Second = 2 Third { ThirdChild = 3 } Fourth { } Last = 9 }"; Execute(w => w.Write(block)) .Should() .Be(expected.ToUnixLineEndings()); }
public void CollectionAttributeFollowedByAttribute() { var block = new OclBlock("OuterBlock") { new OclBlock("InnerBlock") { new OclAttribute("MapAttribute", new Dictionary <string, object> { { "alpha", 1 }, { "bravo", 2 } }), new OclAttribute("StringAttribute", "Value") } }; const string expected = @"OuterBlock { InnerBlock { MapAttribute = { alpha = 1 bravo = 2 } StringAttribute = ""Value"" } }"; Execute(w => w.Write(block)) .Should() .Be(expected.ToUnixLineEndings()); }
public void WriteBlockSingleLabel() { var block = new OclBlock("MyBlock"); block.Labels.Add("MyLabel"); Execute(w => w.Write(block)) .Should() .Be("MyBlock \"MyLabel\" {\n}"); }
public void WriteBlockDoubleQuotesInLabel() { var block = new OclBlock("MyBlock"); block.Labels.Add("My\"Label"); Execute(w => w.Write(block)) .Should() .Be("MyBlock \"My\\\"Label\" {\n}"); }
public void WriteBlockMultipleLabel() { var block = new OclBlock("MyBlock"); block.Labels.Add("MyLabel"); block.Labels.Add("OtherLabel"); block.Labels.Add("LastLabel"); Execute(w => w.Write(block)) .Should() .Be("MyBlock \"MyLabel\" \"OtherLabel\" \"LastLabel\" {\n}"); }
protected virtual void SetLabels(Type type, OclBlock block, object target) { var labelProperties = GetLabelProperties(type).ToArray(); if (block.Labels.Count > labelProperties.Length) { throw new OclException($"The block '{block.Name}' defines {block.Labels.Count} labels ({string.Join(", ", block.Labels)}) but the type {type.Name} only has {labelProperties.Length} label properties"); } for (var x = 0; x < block.Labels.Count; x++) { labelProperties[x].SetValue(target, block.Labels[x]); } }
public void WriteBlockSingleChildAttribute() { var block = new OclBlock("MyBlock") { new OclAttribute("Child", 5) }; var expected = @"MyBlock { Child = 5 }"; Execute(w => w.Write(block)) .Should() .Be(expected.ToUnixLineEndings()); }
public void HeredocIndented() { var literal = new OclStringLiteral(" a\n b", OclStringLiteralFormat.IndentedHeredoc); var block = new OclBlock("MyBlock") { new OclAttribute("MyAttr", literal) }; var expected = @"MyBlock { MyAttr = <<-EOT a b EOT }"; Execute(w => w.Write(block)) .Should() .Be(expected.ToUnixLineEndings()); }
public void IndentOptionsAreUsed() { var options = new OclSerializerOptions { IndentChar = '+', IndentDepth = 5 }; var block = new OclBlock("MyBlock") { new OclAttribute("Child", 5) }; var expected = @"MyBlock { +++++Child = 5 }"; Execute(w => w.Write(block), options) .Should() .Be(expected.ToUnixLineEndings()); }
public void Heredoc() { var literal = new OclStringLiteral(" a\n b", OclStringLiteralFormat.Heredoc) { HeredocTag = "ZZZ" }; var block = new OclBlock("MyBlock") { new OclAttribute("MyAttr", literal) }; var expected = @"MyBlock { MyAttr = <<ZZZ a b ZZZ }"; Execute(w => w.Write(block)) .Should() .Be(expected.ToUnixLineEndings()); }
protected override void SetLabels(Type type, OclBlock block, object target) { }