public void TestSetup()
        {
            // Prepare here our fake dependencies.
            var account1 = new Account { Id = 1, Name = "Account1", Balance = 100.5m };
            var account2 = new Account { Id = 2, Name = "Account2", Balance = 2000.17m };

            var order1 = new Order
            {
                Id = 1,
                AccountId = 1,
                Account = account1,
                Date = DateTime.Now,
                Total = PurchaseService.ORDERS_HISTORY_DISCOUNT_THRESHOLD - 10
            };
            var order2 = new Order { Id = 2, AccountId = 1, Account = account1, Date = DateTime.Now, Total = 20.1m };
            var order3 = new Order { Id = 3, AccountId = 2, Account = account2, Date = DateTime.Now, Total = 170.87m };

            var product1 = new Product { Id = 1, Title = "Product1", Price = 250.99m, Amount = 2 };
            var product2 = new Product { Id = 2, Title = "Product2", Price = 50.5m, Amount = 1 };
            var product3 = new Product { Id = 3, Title = "Product3", Price = 70.15m, Amount = 10 };
            var product4 = new Product { Id = 4, Title = "Product4", Price = 10.75m, Amount = 0 };

            _fakeAccountRepository.Data.AddRange(new[] { account1, account2 });
            _fakeOrderRepository.Data.AddRange(new[] { order1, order2, order3 });
            _fakeProductRepository.Data.AddRange(new[] { product1, product2, product3, product4 });
        }
        public void GetDiscount_When_having_ordered_enough_products_Then_get_5percent_discount()
        {
            var account = new Account { Id = 1, Balance = 400m, Name = "John" };
            var order1 = new Order { Id = 1, AccountId = 1};

            var orderRepository = A.Fake<IRepository<Order>>();
            A.CallTo(() => orderRepository.Query()).Returns(new[] { order1 }.AsQueryable());

            var accountRepository = A.Fake<IRepository<Account>>();
            A.CallTo(() => accountRepository.Query()).Returns(new[] { account }.AsQueryable());

            var unitOfWork = A.Fake<IUnitOfWork>();
            A.CallTo(() => unitOfWork.Repository<Account>()).Returns(accountRepository);
            A.CallTo(() => unitOfWork.Repository<Order>()).Returns(orderRepository);

            var unitOfWorkFactory = A.Fake<IUnitOfWorkFactory>();
            A.CallTo(() => unitOfWorkFactory.Create()).Returns(unitOfWork);

            var service = new PurchaseService(unitOfWorkFactory);

            var discount = service.GetDiscount(account.Id, 200);

            Assert.That(discount, Is.EqualTo(PurchaseService.EXPENSIVE_PRODUCTS_DISCOUNT));
        }
 public OrderViewModel(Order order)
 {
     Date = order.Date;
     Total = order.Total;
 }
        public void GetDiscount_When_products_value_and_previous_orders_value_enough_for_discount_Then_get_15percent_discount()
        {
            var account = new Account { Id = 1, Balance = 400m, Name = "John" };
            var order1 = new Order { Id = 1, AccountId = 1, Total = 250m};
            var order2 = new Order { Id = 2, AccountId = 1, Total = 250m};

            var orderRepository = A.Fake<IRepository<Order>>();
            A.CallTo(() => orderRepository.Query()).Returns(new[] { order1, order2 }.AsQueryable());

            var accountRepository = A.Fake<IRepository<Account>>();
            A.CallTo(() => accountRepository.Query()).Returns(new[] { account }.AsQueryable());

            var unitOfWork = A.Fake<IUnitOfWork>();
            A.CallTo(() => unitOfWork.Repository<Account>()).Returns(accountRepository);
            A.CallTo(() => unitOfWork.Repository<Order>()).Returns(orderRepository);

            var unitOfWorkFactory = A.Fake<IUnitOfWorkFactory>();
            A.CallTo(() => unitOfWorkFactory.Create()).Returns(unitOfWork);

            var service = new PurchaseService(unitOfWorkFactory);

            var discount = service.GetDiscount(account.Id, 200);

            Assert.That(
                discount,
                Is.EqualTo(PurchaseService.EXPENSIVE_PRODUCTS_DISCOUNT + PurchaseService.ORDERS_HISTORY_DISCOUNT));
        }
 public void GivenIHaveAnAccountWithOrderHistoryOfTotalValueOf(int total)
 {
     _account = new Account { Id = 1 };
     _order = new Order { Id = 1, AccountId = 1, Total = total};
 }
 public void GivenICreateAccountWithBalance()
 {
     _account = new Account() {Id = 1};
     _order = new Order { Id = 2, AccountId = _account.Id, Account = _account, Date = DateTime.Now, Total = 30m };
 }