public void CollectionSingleItem() { var document = new OclDocument { new OclBlock("Passengers") { new OclAttribute("Name", "Bob") } }; var context = new OclConversionContext(new OclSerializerOptions() ?? new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } ((Car)result) .Should() .BeEquivalentTo(new Car { Passengers = new List <Person> { new Person { Name = "Bob" } } }); }
public void ReadOnlyPropertiesWorkIfTheReferenceMatches() { var document = new OclDocument { new OclBlock("ReadOnlyPassengers") { new OclAttribute("Name", "Bob") } }; var expected = new Car(); expected.ReadOnlyPassengers.Add(new Person { Name = "Bob" }); var context = new OclConversionContext(new OclSerializerOptions() ?? new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } ((Car)result) .Should() .BeEquivalentTo(expected); }
public (RunbookProcess process, IReadOnlyList <IOclElement> notFound) FromDocument( OclConversionContext context, OclDocument doc ) { var runbook = new RunbookProcess("PLACEHOLDER", "PLACEHOLDER"); var properties = GetProperties(typeof(RunbookProcess)).ToArray(); var notFound = SetProperties(context, doc, runbook, properties); return(runbook, notFound); }
public void IntNullAttribute() { var document = new OclDocument { new OclAttribute("Doors", null) }; new OclSerializer().Deserialize <Car>(document) .Should() .BeEquivalentTo(new Car { Doors = null }); }
public void IntAttributeToString() { var document = new OclDocument { new OclAttribute("Name", 4) }; new OclSerializer().Deserialize <Car>(document) .Should() .BeEquivalentTo(new Car { Name = "4" }); }
public void Empty() { var document = new OclDocument(); var context = new OclConversionContext(new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } ((Car)result) .Should() .BeEquivalentTo(new Car()); }
public void EnumAttribute() { var document = new OclDocument { new OclAttribute("Type", "Suv") }; new OclSerializer().Deserialize <Car>(document) .Should() .BeEquivalentTo(new Car { Type = CarType.Suv }); }
public void DictionaryOfObjects() { var dictionary = new Dictionary <string, object?> { { "One", "1" }, { "Two", "2" } }; var document = new OclDocument { new OclAttribute("ObjectDictionary", dictionary) }; new OclSerializer().Deserialize <Car>(document) .Should() .BeEquivalentTo(new Car { ObjectDictionary = dictionary }); }
public void StringAttribute() { var document = new OclDocument { new OclAttribute("Name", "Mystery Machine") }; var context = new OclConversionContext(new OclSerializerOptions() ?? new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } ((Car)result) .Should() .BeEquivalentTo(new Car { Name = "Mystery Machine" }); }
public void ExceptionIsThrownIfPropertyCantBeSet() { var document = new OclDocument { new OclAttribute("ReadOnly", 1) }; Action action = () => { var context = new OclConversionContext(new OclSerializerOptions() ?? new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } var temp = (Car)result; }; action.Should() .Throw <OclException>() .WithMessage("*The property 'ReadOnly' on 'Car' does not have a setter*"); }
public void ExceptionIsThrownIfPropertyDoesNotExist() { var document = new OclDocument { new OclAttribute("Wings", 1) }; Action action = () => { var context = new OclConversionContext(new OclSerializerOptions() ?? new OclSerializerOptions()); var result = context.FromElement(typeof(Car), document, null); if (result == null) { throw new OclException("Document conversion resulted in null, which is not valid"); } var temp = (Car)result; }; action.Should() .Throw <OclException>() .WithMessage("*The property 'Wings' was not found on 'Car'*"); }