public Task <int> Handle(CreateUserCommand request, CancellationToken cancellationToken) { var user = new User(request.FirstName, request.LastName, request.Email, request.Password, request.Phone); if (_context.Users.Any(x => x.Email == request.Email)) { throw new UserAlreadyExistsException(request.Email); } user.IsActiveAuditing(true); _context.Users.Add(user); _context.SaveChanges(); return(Task.FromResult(user.Id)); }
public Task <int> Handle(CreateEmailTemplateCommand request, CancellationToken cancellationToken) { bool isExists = _context.EmailTemplates.Any(x => x.Name.Equals(request.Name)); if (isExists) { throw new EmailTemplateNameAlreadyExists(request.Name); } var newRow = new EmailTemplate(request.Name, request.Body, request.UserId); _context.EmailTemplates.Add(newRow); _context.SaveChanges(); return(Task.FromResult(newRow.Id)); }
public ApplicationTests(ApplicationFixture fixture) { _fixture = fixture; _context = fixture.Context; _context.Add(CreateEmailTemplate()); _context.SaveChanges(); }
public void Sort_ItShouldBeSortedSuccessfully() { _context.Users.Add(new User("ZTest", "ZLast", "*****@*****.**", "pass", "5050000000")); _context.SaveChanges(); _context.Users.Sort(x => x.FirstName, "firstname_asc").First().FirstName.ShouldBe("Test"); _context.Users.Sort(x => x.FirstName, "firstname_desc").First().FirstName.ShouldBe("Ztest"); _context.Users.Sort(x => x.LastName, "lastname_asc").First().LastName.ShouldBe("User"); _context.Users.Sort(x => x.LastName, "lastname_desc").First().LastName.ShouldBe("Zlast"); }
public void GetAllRolesShouldBeSuccessful() { _context.Add(CreateRole()); _context.SaveChanges(); var mapper = _fixture.GetMapper(new RoleProfile()); var query = new RoleQuery(_context, mapper); var result = query.GetRoles(); result.ShouldNotBeNull(); result.Length.ShouldBeGreaterThanOrEqualTo(1); result.First().Code.ShouldBe("testRole"); }
public Task <TokenUserModel> Handle(AuthenticateCommand request, CancellationToken cancellationToken) { var user = _context.Users .Include(x => x.Roles).ThenInclude(x => x.Role) .AsSplitQuery() .FirstOrDefault(x => x.Email.Equals(request.Email.ToAsciiLower()) && x.Password.Equals(request.Password.ToSha256())) ?? throw new AuthenticateFailedException(); var history = new UserHistory(user, request.IpAddress, request.UserAgent); _context.Add(history); _context.SaveChanges(); return(Task.FromResult(new TokenUserModel { Token = user.GetToken(_configuration["Authentication:Secret"]) })); }
public QueryableExtensionTest(ApplicationFixture fixture) { _context = fixture.Context; _context.Users.Add(new User("Test", "User", "*****@*****.**", "password", "5050000000")); _context.SaveChanges(); }