public async Task <NotificationResult> InsertAsync(InsertUserCommand insertUserCommand) { BeginTransaction(); var result = await _handler.InsertAsync(insertUserCommand); return(Commit(result)); }
public async Task GivenInsertUserCommand_InsertsUserIntoMongoDatabase() { // Arrange var cancellationToken = new CancellationToken(); var insertUserCommand = new InsertUserCommand { Id = Guid.NewGuid(), EmailAddress = "*****@*****.**", Password = "******", UserName = "******", Roles = new List <UserRole> { UserRole.Standard } }; // Act var result = await _classUnderTest.Handle(insertUserCommand, cancellationToken); var user = await _userCollection .Find(x => x.Id == insertUserCommand.Id) .FirstOrDefaultAsync(cancellationToken); Assert.Multiple(() => { Assert.That(result, Is.Not.Null); Assert.That(user.EmailAddress, Is.EqualTo(insertUserCommand.EmailAddress)); Assert.That(user.Password, Is.EqualTo(insertUserCommand.Password)); Assert.That(user.UserName, Is.EqualTo(insertUserCommand.UserName)); Assert.That(user.FriendlyName, Is.Null); }); }
public void GivenInsertUserCommand_ReturnsUserEntity() { // Arrange var insertUserCommand = new InsertUserCommand { Id = Guid.NewGuid(), EmailAddress = "This is an email address", Password = "******", UserName = "******", FriendlyName = "This is a friendly name", Roles = new List <UserRole> { UserRole.Standard } }; // Act var result = insertUserCommand.ToEntity(); // Assert Assert.Multiple(() => { Assert.That(result.Id, Is.EqualTo(insertUserCommand.Id)); Assert.That(result.EmailAddress, Is.EqualTo(insertUserCommand.EmailAddress)); Assert.That(result.Password, Is.EqualTo(insertUserCommand.Password)); Assert.That(result.UserName, Is.EqualTo(insertUserCommand.UserName)); Assert.That(result.FriendlyName, Is.EqualTo(insertUserCommand.FriendlyName)); CollectionAssert.Contains(result.Roles, UserRole.Standard); }); }
public async Task GivenInsertUserCommand_InsertsUserIntoMongoCollection() { // Arrange var cancellationToken = new CancellationToken(); var insertUserCommand = new InsertUserCommand { Id = Guid.NewGuid(), EmailAddress = "*****@*****.**", Password = "******", UserName = "******", Roles = new List <UserRole> { UserRole.Standard } }; // Act var result = await _classUnderTest.Handle(insertUserCommand, cancellationToken); // Assert Assert.That(result, Is.Not.Null); _usercollection.Verify(x => x.InsertOneAsync(It.Is <UserEntity>(user => VerifyUserEntity(user, insertUserCommand)), null, cancellationToken), Times.Once); }
public UserInfo(InsertUserCommand userCommand) { FirstName = userCommand.FirstName; LastName = userCommand.LastName; Username = userCommand.Username; Password = userCommand.Password; Email = userCommand.Email; }
private static bool VerifyInsertUserCommand(InsertUserCommand command, RegisterDto register) { return(command.Id != null && command.EmailAddress == register.EmailAddress && command.Password != null && // Handled by BCrypt in the integration test. command.UserName == register.UserName && command.Roles.Contains(UserRole.Standard)); }
private static bool VerifyUserEntity(UserEntity user, InsertUserCommand command) { return(user.Id == command.Id && user.EmailAddress == command.EmailAddress && user.Password == command.Password && user.UserName == command.UserName && user.Roles.Contains(UserRole.Standard)); }
public UserModule(IMediate mediator) { Get["/"] = _ => "Hi Earth People!"; //404 if not found!!!! Get["/{id:int}"] = parameters => { var userQuery = new UserQuery((int)parameters.id); try { var person = mediator.Request(userQuery); return person; } catch (InvalidOperationException ex) { return HttpStatusCode.NotFound; } }; Put["/{id:int}"] = parameters => { var user = this.Bind<User>(); var updateUserCmd = new UpdateUserCommand(user); try { var id = mediator.Send(updateUserCmd); return Negotiate.WithStatusCode(HttpStatusCode.NoContent); } catch (ValidationException ex) { return Negotiate.WithModel(ex.Errors.Select(x => new{x.PropertyName, x.ErrorMessage})).WithStatusCode(HttpStatusCode.UnprocessableEntity); } catch (InvalidOperationException ex) { return HttpStatusCode.NotFound; } }; Post["/"] = parameters => { var user = this.Bind<User>(); var insertUserCmd = new InsertUserCommand(user); try { var id = mediator.Send(insertUserCmd); return Negotiate.WithStatusCode(HttpStatusCode.Created).WithHeader("Location", Context.Request.Url + "/" + id); } catch (ValidationException ex) { return Negotiate.WithModel(ex.Errors.Select(x => new{x.PropertyName, x.ErrorMessage})).WithStatusCode(HttpStatusCode.UnprocessableEntity); } }; }
public static UserEntity ToEntity(this InsertUserCommand insertUserCommand) { return(new UserEntity { Id = insertUserCommand.Id, EmailAddress = insertUserCommand.EmailAddress, Password = insertUserCommand.Password, UserName = insertUserCommand.UserName, FriendlyName = insertUserCommand.FriendlyName, Roles = insertUserCommand.Roles }); }
public void InsertUser(User user) { InsertUserCommand.Execute(new { user.PublicKey, user.FirstName, user.LastName, user.Email, user.Mobile, user.Description }); }
private static void AddOne() { var command = new InsertUserCommand { Email = "*****@*****.**", Firstname = "PrimeiroNome", Lastname = "UltimoNome" }; var result = Post(command); if (Equals(result.Completed, 1)) { Console.WriteLine("Integração Realizada!"); } }
private static InsertAdobeUserManagementCommand CreateInsertAdobeUser(InsertUserCommand command) { return(new InsertAdobeUserManagementCommand { User = command.Email, Do = new List <DoAddAdobeId> { new DoAddAdobeId { AddAdobeId = new AddAdobeId { Email = command.Email, Firstname = command.Firstname, Lastname = command.Lastname } } } }); }
public IHttpActionResult AddUser([FromBody] InsertUserCommand command) { ValidationError error = new InsertUserCommandValidator().Validate(command); if (error.IsInvalid) { return(BadRequest(error.Error)); } UsersRepository usersRepository = new UsersRepository(Connection); if (!usersRepository.UserExists(User.Identity.Name)) { return(BadRequest("Usuário não encontrado")); } ProjectsRepository repository = new ProjectsRepository(Connection, User); repository.AddUser(command.ProjectToken, UserRole.Guest); return(Ok(repository.Find(command.ProjectToken))); }
private static AdobeUserManagementResponseViewModel Post(InsertUserCommand command) { return(AddAdobeId(new List <InsertAdobeUserManagementCommand> { CreateInsertAdobeUser(command) })); }
public static int RegisterUser(string email, string password, string first, string last, string phone, int ChosenCompanyId, string title, string department, bool newsletter, bool?administrator, CheckBoxList cblTrainingPreferences) { SqlCommand InsertUserCommand; SqlParameterCollection Parameters; // first check if we are registering this with an administrator account if (administrator == null) { // Create query const String query = "INSERT INTO users (email, password, firstName, lastName, phone, companyId, title, department, newsletter) VALUES (@email, @password, @firstName, @lastName, @phone, @companyId, @title, @department, @newsletter); SELECT SCOPE_IDENTITY()"; // Create Insert Command InsertUserCommand = new SqlCommand(query, CTSDatabase); Parameters = InsertUserCommand.Parameters; } else { // Create query const String query = "INSERT INTO users (email, password, firstName, lastName, phone, companyId, title, department, newsletter, administrator) VALUES (@email, @password, @firstName, @lastName, @phone, @companyId, @title, @department, @newsletter, @administrator); SELECT SCOPE_IDENTITY()"; // Create Insert Command InsertUserCommand = new SqlCommand(query, CTSDatabase); Parameters = InsertUserCommand.Parameters; Parameters.AddWithValue("@administrator", administrator); } // Add our parameters Parameters.AddWithValue("@email", email.ToLower()); Parameters.AddWithValue("@password", password); Parameters.AddWithValue("@firstName", first); Parameters.AddWithValue("@lastName", last); Parameters.AddWithValue("@phone", phone); Parameters.AddWithValue("@companyId", ChosenCompanyId); Parameters.AddWithValue("@title", title); Parameters.AddWithValue("@department", department); Parameters.AddWithValue("@newsletter", newsletter); try { // Create SQL connection CTSDatabase.Open(); // Execute command, creating the user, returns the id Int32 UserId = Convert.ToInt32(InsertUserCommand.ExecuteScalar()); // Process the users training preferences AddUserInterests(UserId, cblTrainingPreferences); // Close connection to SQL Database and return the user id CTSDatabase.Close(); return(UserId); } catch (SqlException sex) { //Log out any SQL Exceptions System.Diagnostics.Debug.WriteLine("SQL exception number: " + sex.Number); System.Diagnostics.Debug.WriteLine("SQL exception message: " + sex.Message); } catch (Exception ex) { //General exceptions System.Diagnostics.Debug.WriteLine("General exception: " + ex.Message); } finally { //Ensure we close the connection CTSDatabase.Close(); } // bad value means that registration failed return(GENERAL_FAILURE); }
public async Task <NotificationResult> InsertAsync(InsertUserCommand userCommand) { var item = new UserInfo(userCommand); return(await _userRepository.InsertAsync(item)); }
public async Task <IActionResult> PostAdmin(InsertUserCommand request) => Ok(await _mediator.Send(new InsertUserCommand(UserRoles.Admin, request)));