Exemplo n.º 1
0
        public void Test9_Orders_Should_Update_LoyaltyPoints_When_Using_LoyaltyPoints()
        {
            /*
             *
             * 1) Create a new Loyalty Customer with 0 points and Add them
             * 2) Create a new Order and add the Loyalty Customer, a product and a payment
             * 3) Process the order
             * 4) Get the customer
             * 5) Create a new order
             * 6) Add a product which costs as much as their points balance
             * 7) Pay for the new order with points
             * 8) Get the customer and ensure their balance is now 0
             *
             */

            var           loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection));
            IOrderService orderService   = OrderService;


            var order    = new Order();
            var customer = new LoyaltyCustomer()
            {
                CustomerId            = Guid.NewGuid(),
                EmailAddress          = "*****@*****.**",
                FirstName             = "Test",
                LastName              = "Test",
                LifetimeLoyaltyPoints = 0,
                LoyaltyPointsBalance  = 0,
                RewardStatus          = RewardStatus.Silver
            };

            loyaltyService.AddLoyaltyCustomer(customer);
            order.AddLoyaltyCustomerToOrder(customer);
            const decimal price = 1000m; // Buy a $1000 product in order to get $100 worth of points

            order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price));
            order.Payments.AddPayment(PaymentType.Cash, price);

            orderService.ProcessOrder(order);

            var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);

            order = new Order();
            order.AddLoyaltyCustomerToOrder(updatedCustomer);
            order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price / 10));
            order.Payments.AddPayment(PaymentType.LoyaltyPoints, price / 10);
            orderService.ProcessOrder(order);

            updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);
            Assert.Equal(0, updatedCustomer.LoyaltyPointsBalance);
        }
Exemplo n.º 2
0
        protected static LoyaltyCustomer GetValidLoyaltyCustomer()
        {
            var loyaltyCustomer = new LoyaltyCustomer()
            {
                CustomerId            = Guid.NewGuid(),
                EmailAddress          = "*****@*****.**",
                FirstName             = "test",
                LastName              = "test",
                RewardStatus          = RewardStatus.Gold,
                LoyaltyPointsBalance  = 1.0m,
                LifetimeLoyaltyPoints = 1.0m
            };

            return(loyaltyCustomer);
        }
Exemplo n.º 3
0
        public void AddLoyaltyCustomer(LoyaltyCustomer customer)
        {
            var sql = "INSERT INTO LoyaltyCustomer (CustomerId, FirstName, LastName, EmailAddress, RewardStatus, LoyaltyPointsBalance, LifetimeLoyaltyPoints)" +
                      " Values (@CustomerId, @FirstName, @LastName, @EmailAddress, @RewardStatus, @LoyaltyPointsBalance, @LifetimeLoyaltyPoints);";

            _db.Execute(sql, new
            {
                CustomerId            = customer.CustomerId,
                FirstName             = customer.FirstName,
                LastName              = customer.LastName,
                EmailAddress          = customer.EmailAddress,
                RewardStatus          = customer.RewardStatus.ToString(),
                LoyaltyPointsBalance  = customer.LoyaltyPointsBalance,
                LifetimeLoyaltyPoints = customer.LifetimeLoyaltyPoints
            });
        }
Exemplo n.º 4
0
        public void UpdateLoyaltyCustomer(LoyaltyCustomer customer)
        {
            // Todo: Test 2 - Need to update the SQL statement and parameters in order to save first and last names
            var sql = "UPDATE LoyaltyCustomer Set FirstName = @FirstName, LastName = @LastName, EmailAddress = @EmailAddress, RewardStatus = @RewardStatus," +
                      " LoyaltyPointsBalance = @LoyaltyPointsBalance, LifetimeLoyaltyPoints = @LifetimeLoyaltyPoints" +
                      " WHERE CustomerId = @CustomerId;";

            _db.Execute(sql, new
            {
                FirstName             = customer.FirstName,
                LastName              = customer.LastName,
                EmailAddress          = customer.EmailAddress,
                RewardStatus          = customer.RewardStatus.ToString(),
                LoyaltyPointsBalance  = customer.LoyaltyPointsBalance,
                LifetimeLoyaltyPoints = customer.LifetimeLoyaltyPoints,
                CustomerId            = customer.CustomerId
            });
        }
Exemplo n.º 5
0
        public void Test8_Orders_Should_Update_LoyaltyPoints()
        {
            /*
             *
             * 1) Create a new Loyalty Customer with 0 points and Add them
             * 2) Create a new Order and add the Loyalty Customer, a product and a payment
             * 3) Process the order
             * 4) Get the customer, and verify that their points were updated appropriately
             *
             */


            var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection));

            IOrderService orderService = OrderService;

            var customer = new LoyaltyCustomer()
            {
                CustomerId            = Guid.NewGuid(),
                EmailAddress          = "*****@*****.**",
                FirstName             = "Test",
                LastName              = "Test",
                LifetimeLoyaltyPoints = 0,
                LoyaltyPointsBalance  = 0,
                RewardStatus          = RewardStatus.Silver
            };

            loyaltyService.AddLoyaltyCustomer(customer);

            var order = new Order();

            order.AddLoyaltyCustomerToOrder(customer);
            const decimal price = 1m; // Buy a 1.00 product

            order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price));
            order.Payments.AddPayment(PaymentType.Cash, price);

            orderService.ProcessOrder(order);

            var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);

            Assert.Equal(price / 10, updatedCustomer.LoyaltyPointsBalance);
        }
Exemplo n.º 6
0
        public void Test_2_Should_Update_Customer_Name()
        {
            /*
             *
             * 1) Create a new Loyalty Customer and Add them
             * 2) Get the customer
             * 3) Change the customer's first and last name
             * 4) Update the customer
             * 5) Get the customer
             * 6) Ensure the updated customer has the new information
             */
            var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection));

            const string firstName = "Test2";
            const string lastName  = "2Test";
            var          customer  = new LoyaltyCustomer()
            {
                CustomerId            = Guid.NewGuid(),
                EmailAddress          = "*****@*****.**",
                FirstName             = firstName,
                LastName              = lastName,
                LifetimeLoyaltyPoints = 0,
                LoyaltyPointsBalance  = 0,
                RewardStatus          = RewardStatus.Silver
            };

            loyaltyService.AddLoyaltyCustomer(customer);

            var newCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);

            Assert.Equal(firstName, newCustomer.FirstName);
            Assert.Equal(lastName, newCustomer.LastName);

            newCustomer.FirstName = lastName;
            newCustomer.LastName  = firstName;
            loyaltyService.UpdateLoyaltyCustomer(newCustomer);
            var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);


            Assert.Equal(lastName, updatedCustomer.FirstName);
            Assert.Equal(firstName, updatedCustomer.LastName);
        }
Exemplo n.º 7
0
        public void Test10_LoyaltyStatus_Should_Update_When_Reaching_Milestone()
        {
            /*
             *
             * 1) Create a new Loyalty Customer with 0 points and Add them
             * 2) Create a new Order and add the Loyalty Customer, a product and a payment
             * 3) Process the order
             * 4) Get the customer and ensure their status has changed appropriately
             *
             * */
            var order          = new Order();
            var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection));

            var customer = new LoyaltyCustomer()
            {
                CustomerId            = Guid.NewGuid(),
                EmailAddress          = "*****@*****.**",
                FirstName             = "Test",
                LastName              = "Test",
                LifetimeLoyaltyPoints = 0,
                LoyaltyPointsBalance  = 0,
                RewardStatus          = RewardStatus.Silver
            };

            loyaltyService.AddLoyaltyCustomer(customer);
            order.AddLoyaltyCustomerToOrder(customer);
            const decimal price = 1001m; // Buy a $1001 product in order to become diamond status

            order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price));
            order.Payments.AddPayment(PaymentType.Cash, price);

            IOrderService orderService = OrderService;

            orderService.ProcessOrder(order);

            var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId);

            Assert.Equal(RewardStatus.Diamond, updatedCustomer.RewardStatus);
        }
 public static void AddLoyaltyPoints(this LoyaltyCustomer customer, decimal pointsToAdd)
 {
     customer.LoyaltyPointsBalance  += pointsToAdd;
     customer.LifetimeLoyaltyPoints += pointsToAdd;
 }
 public static void RemoveLoyaltyPoints(this LoyaltyCustomer customer, decimal pointsToRemove)
 {
     customer.LoyaltyPointsBalance -= pointsToRemove;
     customer.LoyaltyPointsBalance  = customer.LoyaltyPointsBalance < 0 ? 0 : customer.LoyaltyPointsBalance;
 }
Exemplo n.º 10
0
 public void DeleteLoyaltyCustomer(LoyaltyCustomer customer)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public void UpdateLoyaltyCustomer(LoyaltyCustomer customer)
 {
     _loyaltyRepository.UpdateLoyaltyCustomer(customer);
 }
Exemplo n.º 12
0
 public void AddLoyaltyCustomer(LoyaltyCustomer customer)
 {
     _loyaltyRepository.AddLoyaltyCustomer(customer);
 }
Exemplo n.º 13
0
 private bool Find(LoyaltyCustomer customer)
 {
     return(customer.LastName.StartsWith('D') &&
            customer.FirstName.StartsWith('S'));
 }