コード例 #1
0
        public void AddSomeMoreOrdersForLoyaltyCustomer()
        {
            /*
             *
             * 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     = loyaltyService.GetLoyaltyCustomer(Guid.Parse("68df0eb2-cb07-42b9-870f-e2080314c73e"));

            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);
        }
コード例 #2
0
 public LoyaltyEngineServices()
 {
     //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
     SetupResolver();
     //service = new LoyaltyService(conFigHelper.LOGIN_DOMAIN, conFigHelper.ACCESS_KEY);
     GetServiceURL(conFigHelper.LOGIN_DOMAIN);
     if (_serviceUrls != null)
     {
         service = new LoyaltyService(_serviceUrls.LoyaltyEngineApiUrl, conFigHelper.ACCESS_KEY);
     }
 }
コード例 #3
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);
        }
コード例 #4
0
        public LoyaltyEngineServices()
        {
            SetupResolver();

            ServiceURLHelper.GetServiceURL();

            if (ServiceURLHelper.Service_Urls != null)
            {
                _service = new LoyaltyService(ServiceURLHelper.Service_Urls.LoyaltyEngineApiUrl, _conFigHelper.ACCESS_KEY);
                //_service = new LoyaltyService("http://localhost:49653", _conFigHelper.ACCESS_KEY);

                SNIPPET_Config_URL = !string.IsNullOrWhiteSpace(_conFigHelper.SNIPPET_URL) ? _conFigHelper.SNIPPET_URL : ServiceURLHelper.Service_Urls.POSSnippetsUrl;
            }
        }
コード例 #5
0
        public async Task CreateAsync_loyaltyValidationSucceed_Createsloyalty()
        {
            // Arrange
            var loyalty  = new LoyaltyUpdateModel();
            var expected = new Loyalty();

            var loyaltyDAL = new Mock <ILoyaltyDAL>();

            loyaltyDAL.Setup(x => x.InsertAsync(loyalty)).ReturnsAsync(expected);

            var loyaltyService = new LoyaltyService(loyaltyDAL.Object);

            // Act
            var result = await loyaltyService.CreateAsync(loyalty);

            // Assert
            result.Should().Be(expected);
        }
コード例 #6
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);
        }
コード例 #7
0
        public async Task ValidateAsync_loyaltyExists_DoesNothing()
        {
            // Arrange
            var loyaltyContainer = new Mock <ILoyaltyContainer>();

            var loyalty         = new Loyalty();
            var loyaltyDAL      = new Mock <ILoyaltyDAL>();
            var loyaltyIdentity = new Mock <ILoyaltyIdentity>();

            loyaltyDAL.Setup(x => x.GetAsync(loyaltyIdentity.Object)).ReturnsAsync(loyalty);

            var loyaltyGetService = new LoyaltyService(loyaltyDAL.Object);

            // Act
            var action = new Func <Task>(() => loyaltyGetService.ValidateAsync(loyaltyContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        public async Task ValidateAsync_loyaltyNotExists_ThrowsError()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <int>();

            var loyaltyContainer = new Mock <ILoyaltyContainer>();

            loyaltyContainer.Setup(x => x.LoyaltyId).Returns(id);
            var loyaltyIdentity = new Mock <ILoyaltyIdentity>();
            var loyalty         = new Loyalty();
            var loyaltyDAL      = new Mock <ILoyaltyDAL>();

            loyaltyDAL.Setup(x => x.GetAsync(loyaltyIdentity.Object)).ReturnsAsync((Loyalty)null);

            var loyaltyGetService = new LoyaltyService(loyaltyDAL.Object);

            // Act
            var action = new Func <Task>(() => loyaltyGetService.ValidateAsync(loyaltyContainer.Object));
            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>($"Loyalty not found by id {id}");
        }
コード例 #11
0
 public DiscountsController(LoyaltyService loyaltyService) => _loyaltyService = loyaltyService;
コード例 #12
0
 public DiscountController(LoyaltyService loyaltyService) => this.loyaltyService = loyaltyService;