public void Can_Map_Null_Values_To_Nullable_Enum_Fields() { // Arrange const int id = 1; const string firstName = "Jimbo"; const string lastName = "Smith"; const Gender gender = Gender.Male; MaritalStatus?maritalStatus = null; dynamic person = new ExpandoObject(); person.Id = id; person.FirstName = firstName; person.LastName = lastName; person.Gender = gender; person.MaritalStatus = maritalStatus; // Act PersonWithFields customer = AutoMapper.MapDynamic <PersonWithFields>(person); // Assert Assert.NotNull(customer); Assert.That(customer.Id == id); Assert.That(customer.FirstName == firstName); Assert.That(customer.LastName == lastName); Assert.That(customer.Gender == gender); Assert.That(customer.MaritalStatus == maritalStatus); }
public void Can_Map_Guid_String_Values_To_Guid_Fields() { // Arrange const int id = 1; const string firstName = "Bob"; const string lastName = "Smith"; Guid uniqueId = Guid.NewGuid(); dynamic dynamicPerson = new ExpandoObject(); dynamicPerson.Id = id; dynamicPerson.FirstName = firstName; dynamicPerson.LastName = lastName; dynamicPerson.UniqueId = uniqueId.ToString(); // This is what we are testing // Act PersonWithFields customer = AutoMapper.MapDynamic <PersonWithFields>(dynamicPerson); // Assert Assert.NotNull(customer); Assert.That(customer.Id == id); Assert.That(customer.FirstName == firstName); Assert.That(customer.LastName == lastName); Assert.That(Equals(customer.UniqueId, uniqueId)); // This is what we are testing }
public void Can_Map_Null_Values_To_Nullable_DateTime_Fields() { // Arrange const int id = 1; const string firstName = "Bob"; const string lastName = "Smith"; DateTime startDate = DateTime.Now.AddDays(-2); DateTime? endDate = null; // This is what we are testing dynamic dynamicPerson = new ExpandoObject(); dynamicPerson.Id = id; dynamicPerson.FirstName = firstName; dynamicPerson.LastName = lastName; dynamicPerson.StartDate = startDate; dynamicPerson.EndDate = endDate; // Act PersonWithFields customer = Slapper.AutoMapper.MapDynamic <PersonWithFields>(dynamicPerson); // Assert Assert.NotNull(customer); Assert.That(customer.Id == id); Assert.That(customer.FirstName == firstName); Assert.That(customer.LastName == lastName); Assert.That(customer.StartDate == startDate); Assert.That(customer.EndDate == endDate); // This is what we are testing }
public void data_fields_are_used() { var template = "Name: " + DocXTemplateEngine.TOKEN_START + "Name" + DocXTemplateEngine.TOKEN_END + ", Age: " + DocXTemplateEngine.TOKEN_START + "Age" + DocXTemplateEngine.TOKEN_END; var data = new PersonWithFields { Name = "Sam", Age = 29 }; var result = DocXTemplateEngine.ParseTemplate(template, data); result.ShouldBe("Name: Sam, Age: 29"); }
public void Should_camel_case_field_names_by_default() { // Given var input = new PersonWithFields { FirstName = "Joe", LastName = "Doe" }; // When var output = new MemoryStream(); this.serializer.Serialize("application/json", input, output); var actual = Encoding.UTF8.GetString(output.ToArray()); // Then actual.ShouldEqual("{\"firstName\":\"Joe\",\"lastName\":\"Doe\"}"); }