コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 public ApplicationTests(ApplicationFixture fixture)
 {
     _fixture = fixture;
     _context = fixture.Context;
     _context.Add(CreateEmailTemplate());
     _context.SaveChanges();
 }
コード例 #4
0
 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");
 }
コード例 #5
0
        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");
        }
コード例 #6
0
        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"])
            }));
        }
コード例 #7
0
 public QueryableExtensionTest(ApplicationFixture fixture)
 {
     _context = fixture.Context;
     _context.Users.Add(new User("Test", "User", "*****@*****.**", "password", "5050000000"));
     _context.SaveChanges();
 }