Exemplo n.º 1
0
        public void AddCart_RetrieveUserBasedOnIdentity()
        {
            var email = "*****@*****.**";
            var user = TestModelFactory.CreateUser(emailAddress: email);
            var users = new List<UserModel>();
            users.Add(user);

            var mockedUserRepository = new Mock<IUserRepository>();
            mockedUserRepository.Setup(m => m.FindByEmailAddress(email)).Returns(user);

            var deal = TestModelFactory.CreateCompleteDeal();
            var dealOption = deal.Options.First();
            var dealAttributes = dealOption.Attributes.Select(a => a.Key.ToString()).ToList();
            var dealRepository = new FakeDealRepository(new List<DealModel>() { deal });

            var repositoryFactory = new FakeUnitOfWorkFactory(userRepository: mockedUserRepository.Object, dealRepository: dealRepository);
            var cartService = new CartService(repositoryFactory);
            var controller = new CartController(cartService);
            controller.User = new GenericPrincipal(new GenericIdentity(email), new string[] { });

            var newCartItem = CreateNewCartItem(deal.Key.ToString(), dealOption.Key.ToString(), dealAttributes);
            controller.Post(newCartItem);

            mockedUserRepository.Verify(m => m.FindByEmailAddress(email), Times.Once);
        }
Exemplo n.º 2
0
        public void AddCart_UserCartAdded()
        {
            var email = "*****@*****.**";
            var user = TestModelFactory.CreateUser(emailAddress: email);
            var users = new List<UserModel>();
            users.Add(user);

            var mockedUserRepository = new Mock<IUserRepository>();
            mockedUserRepository.Setup(m => m.FindByEmailAddress(email)).Returns(user);

            var deal = TestModelFactory.CreateCompleteDeal();
            var dealOption = deal.Options.First();
            var dealAttributes = dealOption.Attributes.Select(a => a.Key.ToString()).ToList();
            var dealRepository = new FakeDealRepository(new List<DealModel>() { deal });

            var repositoryFactory = new FakeUnitOfWorkFactory(userRepository: mockedUserRepository.Object, dealRepository: dealRepository);
            var cartService = new CartService(repositoryFactory);
            var controller = new CartController(cartService);
            controller.User = new GenericPrincipal(new GenericIdentity(email), new string[] { });

            var newCartItem = CreateNewCartItem(deal.Key.ToString(), dealOption.Key.ToString(), dealAttributes);

            user.CartItems.Should().BeEmpty();
            controller.Post(newCartItem);

            user.CartItems.Count().ShouldBeEquivalentTo(1);

            var firstCartItem = user.CartItems.First();
            firstCartItem.DealOption.ShouldBeEquivalentTo(dealOption);
            firstCartItem.AttributeValues.ShouldAllBeEquivalentTo(dealOption.Attributes);
        }
Exemplo n.º 3
0
        private static CartController CreateCartController(List<UserModel> users, List<DealModel> deals = null)
        {
            var userRepository = new FakeUserRepository(users);
            var repositoryFactory = new FakeUnitOfWorkFactory(
                userRepository: userRepository,
                dealRepository: deals != null ? new FakeDealRepository(deals) : null);

            var cartService = new CartService(repositoryFactory);
            var controller = new CartController(cartService);
            return controller;
        }
Exemplo n.º 4
0
        public void GetCarts_RetrieveUserByIdentity()
        {
            var email = "*****@*****.**";
            var user = TestModelFactory.CreateUser(emailAddress: email);
            var users = new List<UserModel>();
            users.Add(user);

            var mockedUserRepository = new Mock<IUserRepository>();
            mockedUserRepository.Setup(m => m.FindByEmailAddress(email)).Returns(user);

            var repositoryFactory = new FakeUnitOfWorkFactory(userRepository: mockedUserRepository.Object);
            var cartService = new CartService(repositoryFactory);
            var controller = new CartController(cartService);
            controller.User = new GenericPrincipal(new GenericIdentity(email), new string[] { });

            controller.Get();

            mockedUserRepository.Verify(m => m.FindByEmailAddress(email), Times.Once);
        }