public void TruckInsertCommand_invalid_Description_null() { TruckInsertCommand _command = new TruckInsertCommand(); _command.Model = 1; _command.Color = "blue"; _command.Image = "img1.png"; _command.ModelYear = (DateTime.Now.Year); _command.Description = ""; _command.Validate(); var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications; Assert.False(_command.Valid); Assert.True(_command.Invalid); Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1); Assert.Equal("Description not be null.", _notification[0].Message); }
public void TruckInsertCommand_invalid_ModelYear_diferent_current_and_after_year_down() { TruckInsertCommand _command = new TruckInsertCommand(); _command.Model = 1; _command.Color = "blue"; _command.Image = "img1.png"; _command.ModelYear = (DateTime.Now.Year - 2); _command.Description = "description"; _command.Validate(); var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications; Assert.False(_command.Valid); Assert.True(_command.Invalid); Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1); Assert.Equal("The model year must be the current year or the year after.", _notification[0].Message); }
public void TruckInsertCommand_invalid_Model_diferent_FH_FM() { TruckInsertCommand _command = new TruckInsertCommand(); _command.Model = 3; _command.ModelYear = DateTime.Now.Year; _command.Description = "description"; _command.Validate(); var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications; Assert.False(_command.Valid); Assert.True(_command.Invalid); Assert.Null(_command.Color); Assert.Null(_command.Image); Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 1); Assert.Equal("Model not valid.", _notification[0].Message); }
public void TruckInsertCommand_valid() { TruckInsertCommand _command = new TruckInsertCommand(); _command.Model = 1; _command.Color = "blue"; _command.Image = "img1.png"; _command.ModelYear = DateTime.Now.Year; _command.Description = "description"; _command.Validate(); var _notification = (List <Flunt.Notifications.Notification>)_command.Notifications; Assert.True(_command.Valid); Assert.False(_command.Invalid); Assert.NotEmpty(_command.Color); Assert.NotEmpty(_command.Image); Assert.True(((List <Flunt.Notifications.Notification>)_command.Notifications).Count == 0); }
public async Task TruckHandler_insert_invalid() { var mockContextRepository = new Mock <IContextRepository>(); var mockTruckRepository = new Mock <ITruckRepository>(); TruckInsertCommand trunlInsertCommand = new TruckInsertCommand(); trunlInsertCommand.Color = "Blue"; trunlInsertCommand.Image = "img.jpg"; trunlInsertCommand.Description = "desciption"; trunlInsertCommand.Model = 1; trunlInsertCommand.ModelYear = DateTime.Now.Year; mockContextRepository.Setup(x => x.Add(It.IsAny <Truck>())).ReturnsAsync(false); TruckHandler _handler = new TruckHandler(mockContextRepository.Object, mockTruckRepository.Object); var _return = await _handler.Handle(trunlInsertCommand); Assert.False(_return.Success); Assert.False((bool)_return.Data); Assert.Equal(HttpStatusCode.BadRequest, _return.Code); }
public async Task <GenericCommandResult> PostTruck( [FromBody] TruckInsertCommand command, [FromServices] IHandler <TruckInsertCommand> handler) { return((GenericCommandResult)await handler.Handle(command)); }