public static T CreateInstance <T>(this Table table, IScenarioContext context) { var output = table.CreateInstance <T>(); ObjectTransformer.Transform(output, context); return(output); }
public void Transform_should_transform_property_using_auto_generated_key_when_key_is_not_defined() { //Arrange const string admin = "ADMIN"; var model = new Customer() { Username = admin }; var expectedGeneratedKey = ObjectTransformer.GeneratePropertyKey(nameof(Customer), nameof(Customer.Username)); //Act ObjectTransformer.Transform(model, fakeContext); //Assert model.Username.Should().NotBe(admin).And.Should().NotBeNull(); var property = valueManager.GetTransformedProperties().First(a => a.Key == expectedGeneratedKey); property.OriginalValue.Should().Be(admin); property.TransformedValue.Should().Be(model.Username); }
public void Transform_should_transform_object_using_specified_key_when_key_is_passed_in() { //Arrange const string key = "NEWCUSTOMER"; const string admin = "ADMIN"; var model = new Customer() { Username = admin }; var expectedGeneratedKey = ObjectTransformer.GeneratePropertyKey(key, nameof(Customer.Username)); //Act ObjectTransformer.Transform(model, key, fakeContext); //Assert model.Username.Should().NotBe(admin).And.Should().NotBeNull(); var property = valueManager.GetTransformedProperties().First(a => a.Key == expectedGeneratedKey); property.OriginalValue.Should().Be(admin); property.TransformedValue.Should().Be(model.Username); }
public void Transform_should_transform_properties_based_on_their_type_when_FieldType_is_set_to_auto() { //Arrange const string admin = "ADMIN"; const long referralId = 10; const int departmentId = 5; var locationId = Guid.NewGuid(); var customer = new Customer() { Username = admin, RefferalId = referralId, DepartmentId = departmentId, LocationId = locationId }; //Act ObjectTransformer.Transform(customer, this.fakeContext); //Assert customer.Username.Should().NotBe(admin, "because 'string' properties should change automatically"); customer.RefferalId.Should().NotBe(referralId, "because 'long' properties should change automatically"); customer.DepartmentId.Should().NotBe(departmentId, "because 'int' properties should change automatically"); customer.LocationId.Should().NotBe(locationId, "because 'Guid' properties should change automatically"); }