public async Task Handle_ShouldPersistFamily() { var command = new CreateFamilyCommand { GuestId = 1, ConfirmationCode = "Test ConfirmationCode", Address1 = "Test Address1", Address2 = "Test Address2", City = "Test City", StateId = 1, Zip = "Test Zip" }; var handler = new CreateFamilyCommand.CreateFamilyCommandHandler(Context); var result = await handler.Handle(command, CancellationToken.None); var entity = Context.Families.Find(result); entity.ShouldNotBeNull(); entity.ConfirmationCode.ShouldBe(command.ConfirmationCode); entity.Address1.ShouldBe(command.Address1); entity.Address2.ShouldBe(command.Address2); entity.City.ShouldBe(command.City); entity.StateId.ShouldBe(command.StateId); entity.Zip.ShouldBe(command.Zip); }
public void IsValid_ShouldBeFalse_WhenRequiredFieldsAreNotSet() { var command = new CreateFamilyCommand(); var validator = new CreateFamilyCommandValidator(Context); var result = validator.Validate(command); result.IsValid.ShouldBe(false); }
public void Excecute_ThrowsParameterValidationException_WhenPassedLessParameters() { var modelFactoryMock = new Mock <IModelsFactory>(); var dataFactoryMock = new Mock <IDataFactory>(); var parameters = new List <string> { "Petrovi" }; var command = new CreateFamilyCommand(modelFactoryMock.Object, dataFactoryMock.Object); Assert.Throws <ParameterValidationException>(() => command.Execute(parameters)); }
public void Excecute_ThrowsFormatException_WhenPassedUserIdNotInt() { var modelFactoryMock = new Mock <IModelsFactory>(); var dataFactoryMock = new Mock <IDataFactory>(); var parameters = new List <string> { "Petrovi", "au" }; var command = new CreateFamilyCommand(modelFactoryMock.Object, dataFactoryMock.Object); Assert.Throws <FormatException>(() => command.Execute(parameters)); }
public void IsValid_ShouldBeTrue_WhenRequiredFieldsAreSet() { var command = new CreateFamilyCommand { GuestId = 1, ConfirmationCode = "Test ConfirmationCode", Address1 = "Test Address1", Address2 = "Test Address2", City = "Test City", StateId = 1, Zip = "Test Zip" }; var validator = new CreateFamilyCommandValidator(Context); var result = validator.Validate(command); result.IsValid.ShouldBe(true); }
public void Excecute_ThrowsEntryNotFoundException_WhenPassedUserIdNotInDatabase() { var modelFactoryMock = new Mock <IModelsFactory>(); var dataFactoryMock = new Mock <IDataFactory>(); var parameters = new List <string> { "Petrovi", "999" }; var parsedUserId = 999; User nullUser = null; var command = new CreateFamilyCommand(modelFactoryMock.Object, dataFactoryMock.Object); dataFactoryMock.Setup(d => d.FindUser(parsedUserId)).Returns(nullUser); Assert.Throws <EntryNotFoundException>(() => command.Execute(parameters)); }
public async Task GivenValidCreateFamilyCommand_ReturnsSuccessCode() { var client = await _factory.GetAuthenticatedClientAsync(); var command = new CreateFamilyCommand { GuestId = 1, ConfirmationCode = "Test ConfirmationCode", Address1 = "Test Address1", Address2 = "Test Address2", City = "Test City", StateId = 1, Zip = "Test Zip" }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PostAsync($"/api/Family", content); response.EnsureSuccessStatusCode(); }
public void Excecute_CallsModelCreate_WhenPassedValidParameters() { var modelFactoryMock = new Mock <IModelsFactory>(); var dataFactoryMock = new Mock <IDataFactory>(); var parameters = new List <string> { "Petrovi", "1" }; var parsedUserId = 1; var command = new CreateFamilyCommand(modelFactoryMock.Object, dataFactoryMock.Object); dataFactoryMock.Setup(d => d.FindUser(parsedUserId)).Returns(new User()); modelFactoryMock.Setup(m => m.CreateFamily(It.IsAny <string>(), It.IsAny <User>())).Returns(new Family()); command.Execute(parameters); modelFactoryMock.Verify(m => m.CreateFamily(It.IsAny <string>(), It.IsAny <User>()), Times.Once); }
public async Task <ActionResult <long> > Create(CreateFamilyCommand command) { return(await Mediator.Send(command)); }