public async Task <IActionResult> Post([FromBody] RegistrationDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = ApplicationUserMapper.RegistrationDtoToApplicationUser(dto); var result = await _userService.CreateUserAsync(userIdentity, dto.Password); if (!result.Succeeded) { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } var createCommand = new CreateBusinessUserCommand(Guid.NewGuid(), new IdentityId(userIdentity.Id), dto.Location, null, null, new Email(userIdentity.Email), userIdentity.FirstName, null, userIdentity.LastName); await _commandBus.Send(createCommand); return(new OkObjectResult(new ResponseObject { Message = "Account Created" })); }
public void CreateShouldAppendToDatabaseAndSaveChanges() { var businessUserDb = new List <BusinessUser>(); var mockSet = new MockDbSet <BusinessUser>(businessUserDb); var contextMock = new Mock <SomeDataContext>(); contextMock.Setup(c => c.BusinessUsers).Returns(mockSet.Object); var createBusinessUserCommand = new CreateBusinessUserCommand(Guid.NewGuid(), new IdentityId("SomeId"), "SomeLocation", "SomeLocale", "SomeGender", new Email("*****@*****.**"), "SomeFirstName", "SomeMiddleName", "SomeLastName" ); var businessUserRepository = new BusinessUserRepository(contextMock.Object); businessUserRepository.Create(createBusinessUserCommand); contextMock.Verify(x => x.SaveChanges(), Times.Once); Assert.Single(businessUserDb); }
public void Create(CreateBusinessUserCommand businessUserCommand) { using (var context = _someDataContext) { var businessUser = BusinessUserMapper.CreateBusinessUserCommandToPersistanceModel(businessUserCommand); context.BusinessUsers.Add(businessUser); context.SaveChanges(); } }
public static BusinessUser CreateBusinessUserCommandToPersistanceModel(CreateBusinessUserCommand command) { return(new BusinessUser { Id = command.Id, Gender = command.Gender, Location = command.Location, IdentityId = command.IdentityId.Value, Locale = command.Locale }); }
public void ShouldMapCorrectlyOnCreateBusinessUserCommandToPersistanceModel() { var command = new CreateBusinessUserCommand(Guid.NewGuid(), new IdentityId(Guid.NewGuid().ToString()), "SomeLocation", "SomeLocale", "SomeGender", new Email("*****@*****.**"), "SomeFirstName", "SomeMiddleName", "SomeLastName"); var mapped = BusinessUserMapper.CreateBusinessUserCommandToPersistanceModel(command); Assert.Equal(mapped.Id, command.Id); Assert.Equal(mapped.Gender, command.Gender); Assert.Equal(mapped.IdentityId, command.IdentityId.Value); Assert.Equal(mapped.Locale, command.Locale); Assert.Equal(mapped.Location, command.Location); }