public void When_ConstructUsing_Set_To_Null_Then_Throws() { // Arrange var mapper = new Mapper(); var sut = new ClassMap(ProjectionType.Create<SimpleFrom, SimpleTo>(), mapper); // Act & Assert KKAssert.Throws<ArgumentNullException>(() => sut.ConstructUsing = null, "Value cannot be null.\r\nParameter name: value"); }
public void When_InheritsFrom_To_Type_Not_Supertype_Of_Map_To_Type_Then_Throws() { // Arrange var mapper = new Mapper(); var sut = new ClassMap(ProjectionType.Create<CarFrom, CarTo>(), mapper); // Act KKAssert.Throws<Exception>(() => sut.InheritsFrom = ProjectionType.Create<VehicleFrom, SimpleTo>(), "Cannot inherit from a ClassMap whose 'To' type 'SimpleTo' is not a supertype of this maps 'To' type 'CarTo'."); }
public void When_InheritsFrom_Then_Is_Set_On_Map() { // Arrange var map = new ClassMap(ProjectionType.Create<CarFrom, CarTo>(), new Mapper()); var sut = new ClassMapBuilder<CarFrom, CarTo>(map); var expected = ProjectionType.Create<VehicleFrom, VehicleTo>(); // Act sut.InheritsFrom<VehicleFrom, VehicleTo>(); // Assert Assert.AreEqual(expected, map.InheritsFrom); }
public void When_AfterMapping_Then_Is_Set_On_Map() { // Arrange var map = new ClassMap(ProjectionType.Create<VehicleFrom, VehicleTo>(), new Mapper()); var sut = new ClassMapBuilder<VehicleFrom, VehicleTo>(map); var flag = false; var postMapStep = (Action<VehicleFrom, VehicleTo>) ((_, __) => flag = true); // Act sut.AfterMapping(postMapStep); map.AfterMapping(null, null); // Assert Assert.IsTrue(flag); }
public void When_ConstructUsing_Then_Is_Set_On_Map() { // Arrange var map = new ClassMap(ProjectionType.Create<VehicleFrom, VehicleTo>(), new Mapper()); var sut = new ClassMapBuilder<VehicleFrom, VehicleTo>(map); var flag = false; var constructor = (Func<ConstructionContext, VehicleTo>) (_ => { flag = true; return new VehicleTo(); }); // Act // Have to do this in indirect fashion as on the map the typing is removed with a wrapping delegate on object. sut.ConstructUsing(constructor); map.ConstructUsing(null); // Assert Assert.IsTrue(flag); }