public UserPostResponseModel Post([FromBody] UserPostRequestModel request) { var inputData = new UserRegisterInputData(request.UserName); var outputData = bus.Handle(inputData); return(new UserPostResponseModel(outputData.CreatedUserId)); }
public void TestAlreadyExists() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); var userName = "******"; userRepository.Save(new User( new UserId("test-id"), new UserName(userName), UserType.Normal )); bool exceptionOccured = false; try { var command = new UserRegisterInputData(userName); interactor.Handle(command); } catch { exceptionOccured = true; } Assert.IsTrue(exceptionOccured); }
public UserRegisterOutputData Handle(UserRegisterInputData inputData) { using var transaction = new TransactionScope(); var name = new UserName(inputData.Name); var user = userFactory.Create(name); if (userService.Exists(user)) { throw new CanNotRegisterUserException(user, "이미 등록된 사용자임"); } userRepository.Save(user); transaction.Complete(); return(new UserRegisterOutputData(user.Id.Value)); }
public void TestSuccessMaxUserName() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); // 사용자명의 최장 길이(20글자)를 만족하는 사용자 등록이 정상적으로 완료되는지 확인 var userName = "******"; var maxUserNameInputData = new UserRegisterInputData(userName); interactor.Handle(maxUserNameInputData); // 사용자 정보가 잘 저장됐는지 확인 var createdUserName = new UserName(userName); var maxUserNameUser = userRepository.Find(createdUserName); Assert.IsNotNull(maxUserNameUser); }
public void TestSuccessMaxUserName() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); // 最長のユーザ名(20文字)のユーザが正常に生成できるか var userName = "******"; var maxUserNameInputData = new UserRegisterInputData(userName); interactor.Handle(maxUserNameInputData); // ユーザが正しく保存されているか var createdUserName = new UserName(userName); var maxUserNameUser = userRepository.Find(createdUserName); Assert.IsNotNull(maxUserNameUser); }
public void TestSuccessMinUserName() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); // 사용자명의 최소 길이(3글자)를 만족하는 사용자 등록이 정상적으로 완료되는지 확인 var userName = "******"; var minUserNameInputData = new UserRegisterInputData(userName); var outputData = interactor.Handle(minUserNameInputData); Assert.IsNotNull(outputData.CreatedUserId); // 사용자 정보가 잘 저장됐는지 확인 var createdUserName = new UserName(userName); var createdUser = userRepository.Find(createdUserName); Assert.IsNotNull(createdUser); }
public void TestSuccessMinUserName() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); // 最短のユーザ名(3文字)のユーザが正常に生成できるか var userName = "******"; var minUserNameInputData = new UserRegisterInputData(userName); var outputData = interactor.Handle(minUserNameInputData); Assert.IsNotNull(outputData.CreatedUserId); // ユーザが正しく保存されているか var createdUserName = new UserName(userName); var createdUser = userRepository.Find(createdUserName); Assert.IsNotNull(createdUser); }
public void TestInvalidUserNameLengthMax() { var userFactory = new InMemoryUserFactory(); var userRepository = new InMemoryUserRepository(); var userService = new UserService(userRepository); var interactor = new UserRegisterInteractor(userFactory, userRepository, userService); bool exceptionOccured = false; try { var command = new UserRegisterInputData("123456789012345678901"); interactor.Handle(command); } catch { exceptionOccured = true; } Assert.IsTrue(exceptionOccured); }