public UserDataBuilder()
 {
     var fixture = new Fixture();
     user = fixture.Build<User>()
         .Without(u => u.Id)
         .Create();
 }
        public void create_user_invoke_session_save(
            User newUser)
        {
            sut.CreateUser(newUser);

            session.Received()
                .Save(newUser);
        }
 public void CreateUser(User newUser)
 {
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Save(newUser);
         transaction.Commit();
     }
 }
        public void authonticate_user_should_invoke_repository_user_exists(
            User user)
        {
            sut.LoginUser(user.Login, user.Password);

            repository.Received()
                      .UserExists(user.Login);
        }
        public void get_existing_user_by_login_and_pass_returns_that_user(
            User existingUser)
        {
            repository.CreateUser(existingUser);

            repository.GetUserByLoginAndPassword(existingUser.Login, existingUser.Password)
                .ShouldBeEquivalentTo(existingUser, o => o.Excluding(x => x.Id));
        }
        public void after_user_is_added_user_exists_check_returns_true(
            User newUser)
        {
            repository.CreateUser(newUser);

            repository.UserExists(newUser.Login)
                .Should().Be(true);
        }
示例#7
0
 public ServiceStatus RegisterUser(User newUser)
 {
     if (!repository.UserExists(newUser.Login))
     {
         repository.CreateUser(newUser);
         return ServiceStatus.Ok;
     }
     return ServiceStatus.Conflict;
 }
 public void register_user_should_invoke_service_new_user(
     [Frozen] IUserService service,
     UserController sut,
     User newUser)
 {
     sut.Post(newUser);
     service.Received()
         .RegisterUser(newUser);
 }
 public void register_user_should_return_http_status_created(
     [Frozen] IUserService service,
     UserController sut,
     User newUser)
 {
     ((HttpStatusCode)sut.Post(newUser))
         .Should()
         .Be(HttpStatusCode.Created);
 }
        public void authonticate_user_with_not_existing_login_should_return_notauthorized_user(
            User user)
        {
            repository.UserExists(user.Login)
                      .Returns(false);

            sut.LoginUser(user.Login, user.Password)
                .Should()
                .BeOfType<NotAuthorizedUser>();
        }
        public void get_user_by_wrong_login_and_pass_returns_null(
            User existingUser,
            string wrongLogin)
        {
            repository.CreateUser(existingUser);

            repository.GetUserByLoginAndPassword(wrongLogin, existingUser.Password)
                .Should()
                .BeNull();
        }
        public void authonticate_existing_user_should_invoke_repository_get_user_by_login_and_pass(
            User user)
        {
            repository.UserExists(user.Login)
                      .Returns(true);

            sut.LoginUser(user.Login, user.Password);

            repository.Received()
                      .GetUserByLoginAndPassword(user.Login, user.Password);
        }
        public void register_existing_user_should_return_http_status_conflict(
            [Frozen] IUserService service,
            UserController sut,
            User newUser)
        {
            service.RegisterUser(newUser)
                .Returns(ServiceStatus.Conflict);

            ((HttpStatusCode)sut.Post(newUser))
                .Should()
                .Be(HttpStatusCode.Conflict);
        }
        public void authonticate_user_corret_creds_should_return_that_user(
            User user)
        {
            repository.UserExists(user.Login)
                      .Returns(true);

            repository.GetUserByLoginAndPassword(user.Login, user.Password)
                      .Returns(user);

            sut.LoginUser(user.Login, user.Password)
               .Should()
               .Be(user);
        }
示例#15
0
        public ShopOrder CreateOrder(User user, Cart cart, string address, string city, string zip)
        {
            var orderItems = cart.Items.Select(cartItem => new OrderItem{
                                                    Product = cartItem.Product,
                                                    Quantity = cartItem.Quantity
                                                }).ToList();

            return new ShopOrder
            {
                User = user,
                //OrderItems = orderItems,
                Address = address,
                City = city,
                Zip = zip
            };
        }
        public void happy_run(
            [Frozen] IUserService service,
            LoginUserController sut,
            User existingUser)
        {
            service.LoginUser(existingUser.Login, existingUser.Password)
                .Returns(existingUser);

            var loginData = new LoginData
            {
                Login = existingUser.Login,
                Password = existingUser.Password
            };

            sut.Post(loginData)
                .Should()
                .Be(existingUser);
        }
示例#17
0
        public void order_factory_should_order_with_proper_user_and_order_items(
            OrderFactory sut,
            User user,
            string address,
            string city,
            string zip)
        {
            var products = new ProductDataFactory()
                .CreateSavedProductsList(5);

            var cart = new CartDataBuilder()
                .WithSomeId()
                .WithProducts(products)
                .Build();

            var actual = sut.CreateOrder(user,
                                         cart,
                                         address,
                                         city,
                                         zip);

            actual
                .Should()
                .NotBeNull();

            actual
                .Should()
                .BeOfType<ShopOrder>();

            actual.User
                .ShouldBeEquivalentTo(user);
            actual.OrderItems
                .ShouldAllBeEquivalentTo(cart.Items);

            actual.Address
                .Should().Be(address);
            actual.City
                .Should().Be(city);
            actual.Zip
               .Should().Be(zip);
        }
        public void authonticate_user_with_wrong_password_should_return_notauthorized_user(
            User user)
        {
            repository.UserExists(user.Login)
                      .Returns(true);

            repository.GetUserByLoginAndPassword(user.Login, user.Password)
                      .Returns(x => null);

            sut.LoginUser(user.Login, user.Password)
                .Should()
                .BeOfType<NotAuthorizedUser>();
        }
        public void register_existing_user_should_return_conflict(
            User newUser)
        {
            repository.UserExists(newUser.Login)
                      .Returns(true);

            sut.RegisterUser(newUser)
                .Should()
                .Be(ServiceStatus.Conflict);
        }
        public void register_nonexisting_user_invoke_repository_create_user(
            User newUser)
        {
            repository.UserExists(newUser.Login)
                .Returns(false);

            sut.RegisterUser(newUser);

            repository.Received()
                .CreateUser(newUser);
        }
        public void register_user_invoke_repository_user_exists(
            User newUser)
        {
            sut.RegisterUser(newUser);

            repository.Received()
                      .UserExists(newUser.Login);
        }
        public void register_user_should_return_status_ok(
            User newUser)
        {
            repository.UserExists(newUser.Login)
                      .Returns(false);

            sut.RegisterUser(newUser)
                .ShouldBeEquivalentTo(ServiceStatus.Ok);
        }