Пример #1
0
        public void Must_validate_password()
        {
            // Arrange

            var requestId = Guid.NewGuid();

            _passwordFormatPolicy.Setup(p => p.Check(PASSWORD)).Returns(false);

            // Act

            var cmd    = new FulfillRegistrationRequestCommand(Db, _passwordFormatPolicy.Object, _passwordHashPolicy.Object);
            var result = cmd.Execute(requestId, PASSWORD);

            // Assert

            AssertError(result, (FulfillRegistrationRequestCommand c) => c.IncorrectPasswordFormat);
            _passwordFormatPolicy.Verify(p => p.Check(PASSWORD), Times.Exactly(1), "Пароль не проверяется");
        }
Пример #2
0
        public void When_email_is_already_taken_Must_return_error()
        {
            // Arrange

            var request = CreateRegistrationRequest();
            var user    = CreateUser();

            user.Email = request.Email; // занимаем email
            Db.SaveChanges();

            // Act

            var cmd    = new FulfillRegistrationRequestCommand(Db, _passwordFormatPolicy.Object, _passwordHashPolicy.Object);
            var result = cmd.Execute(request.Id, PASSWORD);

            // Assert

            AssertError(result, (FulfillRegistrationRequestCommand c) => c.EmailAlreadyRegistered);
        }
Пример #3
0
        public void Must_create_user_upon_register()
        {
            // Arrange

            var request = CreateRegistrationRequest();

            Db.SaveChanges();

            // Act

            var cmd    = new FulfillRegistrationRequestCommand(Db, _passwordFormatPolicy.Object, _passwordHashPolicy.Object);
            var result = cmd.Execute(request.Id, PASSWORD);

            Db.SaveChanges();

            // Assert

            AssertSuccess(result);
            Assert.AreEqual(1, Db.Users.Count(u => u.Email == request.Email), "Новый пользователь не создался, либо создалось несколько пользователей");
        }
Пример #4
0
        public void When_registration_request_has_cart_Must_put_items_to_user_cart_upon_register()
        {
            // Arrange

            var cart    = CreateCart(items: CreateCartItem());
            var request = CreateRegistrationRequest(cart);

            Db.SaveChanges();

            // Act

            var cmd    = new FulfillRegistrationRequestCommand(Db, _passwordFormatPolicy.Object, _passwordHashPolicy.Object);
            var result = cmd.Execute(request.Id, PASSWORD);

            Db.SaveChanges();

            // Assert

            AssertSuccess(result);
            Assert.IsTrue(Db.ShoppingCarts.Any(c => c.User.Email == request.Email && c.Items.Any()), "Покупки не перенеслись в корзину пользователя");
        }
Пример #5
0
        public void Must_store_password_hash_with_user()
        {
            // Arrange

            var request = CreateRegistrationRequest();

            Db.SaveChanges();

            // Act

            var cmd    = new FulfillRegistrationRequestCommand(Db, _passwordFormatPolicy.Object, _passwordHashPolicy.Object);
            var result = cmd.Execute(request.Id, PASSWORD);

            Db.SaveChanges();

            // Assert

            AssertSuccess(result);
            var user = Db.Users.First(u => u.Email == request.Email);

            _passwordHashPolicy.Verify(p => p.Apply(PASSWORD), Times.Exactly(1), "Не вызвана PasswordHashPolicy для генерации хэша");
            Assert.AreEqual(HASH, user.PasswordHash, "Хэш не сохранился");
        }