Пример #1
0
        public async Task Create_User_Email_Already_Exists()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                // Run the test against one instance of the context
                using (var context = new AppcentTodoContext(options))
                {
                    TestHelper.EnsureCreated(context);
                    var service = new RegisterUserCommandHandler(context, TestHelper.GetMapperInstance());
                    var command = new RegisterUserCommand();
                    command.Data = new RegisterUserRequest
                    {
                        Email     = "*****@*****.**",
                        FirstName = "test firstname",
                        LastName  = "test lastname",
                        Password  = "******",
                        UserName  = "******"
                    };
                    var result = await service.Execute(command);

                    Assert.False(result.Result.IsSuccess);
                    Assert.Equal("Email is already in use", result.Result.Error.ErrorText);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Пример #2
0
        public async Task Create_User()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new AppcentTodoContext(options))
                {
                    var service = new RegisterUserCommandHandler(context, TestHelper.GetMapperInstance());
                    var command = new RegisterUserCommand();
                    command.Data = new RegisterUserRequest
                    {
                        Email     = "test email",
                        FirstName = "test firstname",
                        LastName  = "test lastname",
                        Password  = "******",
                        UserName  = "******"
                    };
                    var result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                }

                using (var context = new AppcentTodoContext(options))
                {
                    var count = context.AcUsers.Where(e => e.FirstName == "test firstname");
                    Assert.Equal(1, count.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void RegisterUserCommandHandler_Sends_Email()
        {
            var handler = new RegisterUserCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new RegisterUserCommand("*****@*****.**", "test");

            handler.Execute(command);

            _mailClient.SentMessages.Should().HaveCount(1);
            _mailClient.SentMessages[0].Subject.Should().Be("Please activate your account");
            _mailClient.SentMessages[0].To.Should().Be("*****@*****.**");
        }
        public void RegisterUserCommandHandler_Fails_For_Existing_Email()
        {
            var handler = new RegisterUserCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new RegisterUserCommand("*****@*****.**", "test");

            _context.Users.Add(new User("*****@*****.**", "test"));

            var result = handler.Execute(command);

            result.Errors.Should().HaveCount(1);
            result.Errors[0].Expression.ToString().Should().Be("p => p.Email");
            result.Errors[0].Message.Should().Be("Email address already exists");
            _mailClient.SentMessages.Should().BeEmpty();
        }
        public void RegisterUserCommandHandler_Succeeds()
        {
            var handler = new RegisterUserCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new RegisterUserCommand("*****@*****.**", "test");

            var result = handler.Execute(command);
            var user   = _context.Users.SingleOrDefault();

            result.Errors.Should().BeEmpty();
            user.Should().NotBeNull();
            user.Status.Should().Be(UserStatus.New);
            user.UserEvents.Should().HaveCount(1);
            user.UserEvents.Single().Type.Should().Be(UserEventType.Registered);
        }