protected override DTObject DynamicInvoke(dynamic arg) { Guid[] roleIds = Array.Empty <Guid>(); if (arg.RoleMarkedCode != null) { string markedCode = arg.RoleMarkedCode.ToString(); var role = RoleCommon.FindByMarkedCode(markedCode, QueryLevel.None); if (!role.IsEmpty()) { roleIds = new Guid[] { role.Id }; } } else { roleIds = arg.RoleIds != null?arg.RoleIds?.OfType <Guid>() : Array.Empty <Guid>(); } var cmd = new CreateUser(arg.AccountName, arg.Password, arg.DiskSize ?? VirtualDisk.Size1G) //默认给予1G的大小 { Email = arg.Email, LocationId = arg.LocationId, MobileNumber = arg.MobileNumber, Name = arg.Name, NickName = arg.NickName, PhotoId = arg.PhotoId, RoleIds = arg.RoleIds != null?arg.RoleIds?.OfType <Guid>() : Array.Empty <Guid>(), Sex = arg.Sex, IsEnabled = arg.IsEnabled }; var user = cmd.Execute(); return(DTObject.CreateReusable("{id}", user)); }
public void CreateUser_ReturnsUserAlreadyExistsException() { #region Arrange string userId = UserIdMother.Id(); string expectedMessage = $"The user '{userId}' already exists"; var userRepository = new Mock <UserRepository>(); userRepository .Setup(r => r.Find(It.IsAny <UserId>())) .ReturnsAsync(UserMother.User(userId)); userRepository .Setup(r => r.Exists(It.IsAny <UserId>())) .ReturnsAsync(true); userRepository .Setup(r => r.Save(It.IsAny <User>())); UserCreator userCreator = new UserCreator(userRepository.Object); CreateUser createUser = new CreateUser(userCreator); #endregion #region Act var exception = Record.ExceptionAsync(async() => await createUser.Execute(userId)); #endregion #region Assert Assert.Equal(expectedMessage, exception.Result.Message); #endregion }
public async Task <IActionResult> CreateUser([FromBody] Models.UserModel user) { if (ModelState.IsValid) { return(await _createUser.Execute()); } return(BadRequest(new { Code = 901, Message = "Invalid validation" })); }
public void InvokesUserRepository() { var user = new User { }; var handler = new CreateUser(_userRepo.Object); handler.Execute("id"); _userRepo .Verify(r => r.Create(It.Is <User>(u => u.AuthorizationId == "id")), Times.Once()); }
public async Task CreateUserTest(string appKey, string userName, string password, bool exception, Type exceptionType = null) { var userRep = UserRepositoryMock.CreateRepository(); var appRep = AppRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, appKey, userName, password); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task CreateUserFlowTest(string appKey = "", string userName = "", string password = "", bool incCreate = false, bool incGetByKeyToAppCount = false, bool incAppGetByKey = false) { var userRep = UserRepositoryMock.CreateRepository(); var appRep = AppRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, appKey, userName, password); Assert.AreEqual(userRep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(userRep.GetByKeyToAppCount, incGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(appRep.GetByKeyCount, incAppGetByKey ? 1 : 0, "Não deveria ter chamado a verificação de app"); } catch { Assert.AreEqual(userRep.CreateCount, incCreate ? 1 : 0); Assert.AreEqual(userRep.GetByKeyToAppCount, incGetByKeyToAppCount ? 1 : 0); Assert.AreEqual(appRep.GetByKeyCount, incAppGetByKey ? 1 : 0, "Não deveria ter chamado a verificação de app"); } }
public async Task <IActionResult> Put(string userId) { try { await _createUser.Execute(userId); return(Created($"user/create/{userId}", userId)); } catch (InvalidUserException ex) { return(Conflict(ex.Message)); } catch (UserExistsException ex) { return(Conflict(ex.Message)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task CreateUserInvalidParametersTest(bool isAppRepNull, bool isUserRepNull, string key = "", string userName = "", string password = "") { var appRep = isAppRepNull ? null : AppRepositoryMock.CreateRepository(); var userRep = isUserRepNull ? null : UserRepositoryMock.CreateRepository(); try { await CreateUser.Execute(appRep, userRep, key, userName, password); Assert.Fail(); } catch (Exception ex) { if (isAppRepNull || isUserRepNull) { Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); } else { Assert.AreEqual(ex.GetType(), typeof(ArgumentException)); } } }
public async Task CreateUser_ReturnsVoid() { #region Arrange string userId = UserIdMother.Id(); var userRepository = new Mock <UserRepository>(); userRepository .Setup(r => r.Save(It.IsAny <User>())); UserCreator userCreator = new UserCreator(userRepository.Object); CreateUser createUser = new CreateUser(userCreator); #endregion #region Act await createUser.Execute(userId); #endregion #region Assert userRepository.Verify(r => r.Save(It.IsAny <User>()), Times.Once()); #endregion }
public ActionResult SignInResponse() { var response = _relyingParty.GetResponse(); switch (response.Status) { case AuthenticationStatus.Authenticated: var user = _getUserByClaimId.Execute(response.ClaimedIdentifier); if (user == null) { user = _createUser.Execute(response.ClaimedIdentifier); } var isPersistent = (TempData.ContainsKey("rememberMe") && (bool)TempData["rememberMe"]); var ticket = UserAuthenticationTicketBuilder.CreateAuthenticationTicket(user, DateTime.Now, isPersistent); _formsAuthentication.SetAuthCookie(HttpContext, ticket); return(RedirectToAction("Index", "Dashboard")); case AuthenticationStatus.Canceled: this.SetConfirmationMessage(Messages.AuthController_CanceledAuthentication); return(RedirectToAction("Index")); case AuthenticationStatus.Failed: this.SetAlertMessage(response.Exception.Message); return(RedirectToAction("Index")); default: this.SetAlertMessage(Messages.AuthController_SignIn_UnableToAuthenticateWithProvider); return(RedirectToAction("Index")); } }
public void CreateUser(string username, string password, string email, params string[] roles) { var command = new CreateUser(username, password, email, roles); command.Execute(); }