Ejemplo n.º 1
2
        private object DummyEcommerceMethod2()
        {
            SKUInfo          sku             = null;
            IOrderRepository orderRepository = null;
            int orderId = 0;

            //DocSection:DisplayCatalogDiscounts
            // Initializes the needed services
            ShoppingService shoppingService = new ShoppingService();
            PricingService  pricingService  = new PricingService();

            // Gets the current shopping cart
            ShoppingCart shoppingCart = shoppingService.GetCurrentShoppingCart();

            // Calculates prices for the specified product
            ProductPrice price = pricingService.CalculatePrice(sku, shoppingCart);

            // Gets the catalog discount
            decimal catalogDiscount = price.Discount;
            //EndDocSection:DisplayCatalogDiscounts

            //DocSection:DisplayOrderList
            // Gets the current customer
            Customer currentCustomer = shoppingService.GetCurrentCustomer();

            // If the customer does not exist, returns error 404
            if (currentCustomer == null)
            {
                return(HttpNotFound());
            }

            // Creates a view model representing a collection of the customer's orders
            OrdersViewModel model = new OrdersViewModel()
            {
                Orders = orderRepository.GetByCustomerId(currentCustomer.ID)
            };
            //EndDocSection:DisplayOrderList

            //DocSection:ReorderExistingOrder
            // Gets the order based on its ID
            Order order = orderRepository.GetById(orderId);

            // Gets the current visitor's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // Loops through the items in the order and adds them to the shopping cart
            foreach (OrderItem item in order.OrderItems)
            {
                cart.AddItem(item.SKUID, item.Units);
            }

            // Evaluates the shopping cart
            cart.Evaluate();

            // Saves the shopping cart
            cart.Save();
            //EndDocSection:ReorderExistingOrder

            return(null);
        }
Ejemplo n.º 2
0
        public void scenarios1()
        {
            var customerService = new CustomerService(new CustomerRepository());
            var customer        = new Customer()
            {
                Discounts = new List <Discount> {
                    new Discount {
                        ServiceId = "c",
                        Start     = new DateTime(2019, 09, 22),
                        End       = new DateTime(2019, 09, 24),
                        Percent   = 20
                    }
                },
                Services = new List <IService> {
                    new ServiceA(new DateTime(2019, 09, 20)),
                    new ServiceC(new DateTime(2019, 09, 20))
                }
            };

            customerService.AddCustomer(customer);

            var sut    = new PricingService(customerService);
            var result = sut.GetPrices(customer.CustomerId, new DateTime(2019, 09, 20), new DateTime(2019, 10, 01));

            Assert.That(result, Is.EqualTo(6.16M));
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            if (File.Exists("Readme.md"))
            {
                Console.WriteLine(File.ReadAllText("Readme.md"));
            }

            // persistence
            var store  = CreateFileStoreForTesting();
            var events = new EventStore(store);

            // various domain services
            var pricing = new PricingService();

            var server = new ApplicationServer();

            server.Handlers.Add(new LoggingWrapper(new CustomerApplicationService(events, pricing)));

            // send some sample commands
            server.Dispatch(new CreateCustomer {
                Id = new CustomerId(12), Name = "Lokad", Currency = Currency.Eur
            });
            server.Dispatch(new RenameCustomer {
                Id = new CustomerId(12), NewName = "Lokad SAS"
            });
            server.Dispatch(new ChargeCustomer {
                Id = new CustomerId(12), Amount = 20m.Eur(), Name = "Forecasting"
            });

            Console.WriteLine("Press any key to exit");
            Console.ReadKey(true);
        }
        private decimal GetThePriceToPlace(ShirtVariation currentContent)
        {
            PricingService myPricing = new PricingService(
                _priceService, _currentMarket, _priceDetailService);

            return(myPricing.GetTheRightPrice(currentContent)); // for the group and so forth
        }
Ejemplo n.º 5
0
        private async void LoadPrices()
        {
            try
            {
                ToggleProgress();

                var prices = await PricingService.ReceiveEc2PricesAsync(regionName);

                var images = await ImagesService.LoadSelfImagesAsync(RegionEndpoint.GetBySystemName(regionName));

                foreach (var price in prices)
                {
                    Prices.Add(new Ec2InstancePriceViewModel(price));
                }

                foreach (var image in images)
                {
                    Images.Add(new Ec2InstanceImageViewModel(new Ec2InstanceImage
                    {
                        ImageId = image.ImageId,
                        Name    = image.Name
                    }));
                }
            }
            catch
            {
                MessageBox.Show("Не удалось загрузить цены. Попробуйте позже");
                NavigateToInstances();
            }
            finally
            {
                ToggleProgress();
            }
        }
Ejemplo n.º 6
0
        public void scenarios2()
        {
            var customerService = new CustomerService(new CustomerRepository());
            var customer        = new Customer()
            {
                Discounts = new List <Discount> {
                    new Discount {
                        ServiceId = "B",
                        Start     = new DateTime(2018, 01, 01),
                        Percent   = 30
                    },
                    new Discount {
                        ServiceId = "C",
                        Start     = new DateTime(2018, 01, 01),
                        Percent   = 30
                    }
                },
                Services = new List <IService> {
                    new ServiceB(new DateTime(2018, 01, 01)),
                    new ServiceC(new DateTime(2018, 01, 01))
                },
                FreeDays = 200
            };

            customerService.AddCustomer(customer);

            var sut    = new PricingService(customerService);
            var result = sut.GetPrices(customer.CustomerId, customer.Services.First().StartDate, new DateTime(2019, 10, 01));

            Assert.That(result, Is.EqualTo(175.504M));
        }
Ejemplo n.º 7
0
        static EvaluationService()
        {
            KbbService = new PricingService {
                Url = KbbServiceEndpoint
            };

            _evaluationTypes = new List <EvaluationType>
            {
                new EvaluationType
                {
                    Key   = "TI",
                    Value = "Trade-In"
                },
                new EvaluationType
                {
                    Key   = "PP",
                    Value = "Private-Party"
                },
                new EvaluationType
                {
                    Key   = "R",
                    Value = "Suggested-Retail"
                }
            };
        }
Ejemplo n.º 8
0
 public void OneItem()
 {
     double price = AnyInstance.AnyDouble;
     PricingService service = new PricingService(new MockProductRepository(x => new Product { Id = x, UnitPrice = price }));
     service.AddToCart(new OrderItem { Amount = 1, ItemId = 1 });
     Assert.AreEqual(price, service.PriceOrder());
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Promotions using pricing");
            System.Console.WriteLine("--------------------");
            System.Console.WriteLine("Scenario A");
            var pricingA = new PricingService(new GetPrices(), new GetPromotions());

            pricingA.AddItem(new UnpricedItem("A", 1));
            pricingA.AddItem(new UnpricedItem("B", 1));
            pricingA.AddItem(new UnpricedItem("C", 1));

            System.Console.WriteLine($"Basket A:");
            foreach (var item in pricingA.Basket())
            {
                System.Console.WriteLine(item);
            }

            System.Console.WriteLine($"Total  A: {pricingA.BasketTotal()}");

            System.Console.WriteLine("--------------------");

            System.Console.WriteLine("Scenario B");
            var pricingB = new PricingService(new GetPrices(), new GetPromotions());

            pricingB.AddItem(new UnpricedItem("A", 5));
            pricingB.AddItem(new UnpricedItem("B", 5));
            pricingB.AddItem(new UnpricedItem("C", 1));

            System.Console.WriteLine($"Basket B:");
            foreach (var item in pricingB.Basket())
            {
                System.Console.WriteLine(item);
            }

            System.Console.WriteLine($"Total  B: {pricingB.BasketTotal()}");

            System.Console.WriteLine("--------------------");

            System.Console.WriteLine("Scenario B");
            var pricingC = new PricingService(new GetPrices(), new GetPromotions());

            pricingC.AddItem(new UnpricedItem("A", 3));
            pricingC.AddItem(new UnpricedItem("B", 2));
            pricingC.AddItem(new UnpricedItem("C", 1));
            pricingC.AddItem(new UnpricedItem("D", 1));
            pricingC.AddItem(new UnpricedItem("B", 3));

            System.Console.WriteLine($"Basket C:");
            foreach (var item in pricingC.Basket())
            {
                System.Console.WriteLine(item);
            }

            System.Console.WriteLine($"Total  C: {pricingC.BasketTotal()}");

            System.Console.WriteLine("--------------------");
            System.Console.WriteLine("Finis!");
            System.Console.ReadKey();
        }
        private EPiServer.Commerce.SpecializedProperties.Price GetCustomerPricingPrice(ShirtVariation currentContent)
        {
            // This is the original...
            PricingService myPricing = new PricingService(
                _priceService, _currentMarket, _priceDetailService);

            return(myPricing.GetTheRightCustomerPrice(currentContent)); // for the group and so forth
        }
        public void CalculatePrice_HasValidPeriods_ResultShouldBeCorrect(string checkIn, string checkOut, decimal price, decimal expResult)
        {
            _mockedPricingRepository.Setup(x => x.GetPricings()).Returns(_pricingFixtureData.MockedPricings);

            var pricingSerice = new PricingService(_mockedPricingRepository.Object);
            var result        = pricingSerice.CalculatePrice(DateTime.Parse(checkIn), DateTime.Parse(checkOut), price);

            Assert.Equal(expResult, result);
        }
        public void CalculatePrice_WithClassDataHasValidPeriods_ResultShouldBeCorrect(PriceTestCases testCase)
        {
            _mockedPricingRepository.Setup(x => x.GetPricings()).Returns(_pricingFixtureData.MockedPricings);

            var pricingSerice = new PricingService(_mockedPricingRepository.Object);
            var result        = pricingSerice.CalculatePrice(testCase.CheckIn, testCase.CheckOut, testCase.Price);

            Assert.Equal(testCase.ExpPrice, result);
        }
        public void Setup()
        {
            this._dao       = new Mock <IConferenceDao>();
            this._seatTypes = new[] {
                new SeatType(Guid.NewGuid(), ConferenceId, "Name1", "Desc1", 15.10m, 999),
                new SeatType(Guid.NewGuid(), ConferenceId, "Name2", "Desc2", 9.987m, 600)
            };
            _dao.Setup(d => d.GetPublishedSeatTypes(ConferenceId)).Returns(_seatTypes);

            this._sut = new PricingService(_dao.Object);
        }
Ejemplo n.º 14
0
        public PricingServiceFixture()
        {
            dao       = new Mock <IConferenceDao>();
            seatTypes = new[] {
                new SeatType(Guid.NewGuid(), ConferenceId, "Name1", "Desc1", 15.10m, 999),
                new SeatType(Guid.NewGuid(), ConferenceId, "Name2", "Desc2", 9.987m, 600)
            };
            dao.Setup(d => d.GetPublishedSeatTypes(ConferenceId)).Returns(seatTypes);

            sut = new PricingService(dao.Object);
        }
Ejemplo n.º 15
0
        public void DiscountPercentage_NullCheck()
        {
            // Arrange
            const decimal expectedDiscount = 0M;
            var           ps = new PricingService();

            // Act
            var result = ps.DiscountPercentage(null);

            // Assert
            Assert.Equal(expectedDiscount, result);
        }
Ejemplo n.º 16
0
 public void MultipleItems()
 {
     double price1 = AnyInstance.AnyDouble;
     double price2 = AnyInstance.AnyDouble + 1;
     int amount1 = AnyInstance.AnyInt;
     int amount2 = AnyInstance.AnyInt + 3;
     PricingService service = new PricingService(new MockProductRepository(x => new Product { Id = x, UnitPrice = x == 1 ? price1 : price2 }));
     service.AddToCart(new OrderItem { ItemId = 1, Amount = amount1 });
     service.AddToCart(new OrderItem { ItemId = 2, Amount = amount2 });
     double expectedPrice = price1 * amount1 + price2 * amount2;
     Assert.AreEqual(expectedPrice, service.PriceOrder());
 }
Ejemplo n.º 17
0
        public void CalculatePrice_TestCasesAreDefinedAsMemberData_ResultShouldBeCorrect(DateTime checkIn, DateTime checkOut, decimal price, decimal expectedResult)
        {
            //Arrange
            _pricingRepository.Setup(x => x.GetPricings()).Returns(_pricingFixtureData.MockedPricings);

            //Act
            var pricingService = new PricingService(_pricingRepository.Object);
            var result         = pricingService.CalculatePrice(checkIn, checkOut, price);

            //Assert
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 18
0
        public void should_return_product_prices()
        {
            var pricingService = new PricingService(new InMemoryPricingRepository());
            var products       = new List <Product>()
            {
                new Product('A', 50), new Product('B', 30)
            };

            var totalPrice = pricingService.TotalCostOf(products);

            Assert.That(totalPrice, Is.EqualTo(80));
        }
Ejemplo n.º 19
0
        public void OneItem()
        {
            double         price   = AnyInstance.AnyDouble;
            PricingService service = new PricingService(new MockProductRepository(x => new Product {
                Id = x, UnitPrice = price
            }));

            service.AddToCart(new OrderItem {
                Amount = 1, ItemId = 1
            });
            Assert.AreEqual(price, service.PriceOrder());
        }
        public PricingServiceFixture()
        {
            this.dao = new Mock<IConferenceDao>();
            this.seatTypes = new[]
                                {
                                    new SeatType(Guid.NewGuid(), ConferenceId, "Name1", "Desc1", 15.10m, 999),
                                    new SeatType(Guid.NewGuid(), ConferenceId, "Name2", "Desc2", 9.987m, 600),
                                };
            dao.Setup(d => d.GetPublishedSeatTypes(ConferenceId)).Returns(seatTypes);

            this.sut = new PricingService(dao.Object);
        }
        public void GetPricingPercent_PeriodsAreNotDefined_ResultShouldBe13()
        {
            var expResult = 13;
            var fromDate  = DateTime.Now.AddDays(10);
            var toDate    = DateTime.Now.AddDays(15);

            _mockedPricingRepository.Setup(x => x.GetPricings()).Returns(new List <Pricing>());

            var pricingSerice = new PricingService(_mockedPricingRepository.Object);
            var result        = pricingSerice.GetPricingPercent(fromDate, toDate);

            Assert.Equal(expResult, result);
        }
        public void GetPricingPercent_PeriodsAreDefinedHaveOnlyMatchForOne_ResultShouldBe13()
        {
            var expResult = 13;
            var fromDate  = new DateTime(2020, 12, 25);
            var toDate    = new DateTime(2021, 01, 05);

            _mockedPricingRepository.Setup(x => x.GetPricings()).Returns(_pricingFixtureData.MockedPricings);

            var pricingSerice = new PricingService(_mockedPricingRepository.Object);
            var result        = pricingSerice.GetPricingPercent(fromDate, toDate);

            Assert.Equal(expResult, result);
        }
 public PricingDetailsController(ApplicationDbContext context, ProjectService project, EmployeeService employee, HourService hour, ProjectTeamService projectTeam, ClientService client, PricingService pricing, Files files, IConfiguration config, IHostingEnvironment env)
 {
     _context            = context;
     _projectService     = project;
     _projectTeamService = projectTeam;
     _employeeService    = employee;
     _hourService        = hour;
     _clientService      = client;
     _pricingService     = pricing;
     _files          = files;
     _config         = config;
     _appEnvironment = env;
 }
Ejemplo n.º 24
0
        public void Setup()
        {
            _cheapPriceUSD     = new Money(1, "USD");
            _expensivePriceGBP = new Money(2, "GBP");

            _currencyServiceMock = new Mock <ICurrencyService>();
            _currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(new Currency("USD"));

            _currentMarketMock = new Mock <ICurrentMarket>();
            _currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(new Mock <IMarket>().Object);

            _priceServiceMock = new Mock <IPriceService>();
            _priceServiceMock.Setup(
                x =>
                x.GetPrices(
                    It.IsAny <MarketId>(),
                    It.IsAny <DateTime>(),
                    It.IsAny <CatalogKey>(),
                    It.IsAny <PriceFilter>()))
            .Returns(() => new[]
            {
                new PriceValue {
                    UnitPrice = _expensivePriceGBP
                },
                new PriceValue {
                    UnitPrice = _cheapPriceUSD
                }
            });
            _priceServiceMock.Setup(
                x =>
                x.GetPrices(
                    It.IsAny <MarketId>(),
                    It.IsAny <DateTime>(),
                    It.IsAny <IEnumerable <CatalogKey> >(),
                    It.IsAny <PriceFilter>()))
            .Returns(() => new[]
            {
                new PriceValue {
                    UnitPrice = _expensivePriceGBP
                },
                new PriceValue {
                    UnitPrice = _cheapPriceUSD
                }
            });

            _subject = new PricingService(
                _priceServiceMock.Object,
                _currentMarketMock.Object,
                _currencyServiceMock.Object,
                new FakeAppContext());
        }
Ejemplo n.º 25
0
        private void DummyEcommerceMethod3()
        {
            //DocSection:DisplayFreeShippingOffers
            // Initializes the needed services
            ShoppingService shoppingService = new ShoppingService();
            PricingService  pricingService  = new PricingService();

            // Gets the current shopping cart
            ShoppingCart shoppingCart = shoppingService.GetCurrentShoppingCart();

            // Gets the remaining amount for free shipping
            decimal remainingFreeShipping = pricingService.CalculateRemainingAmountForFreeShipping(shoppingCart);
            //EndDocSection:DisplayFreeShippingOffers
        }
Ejemplo n.º 26
0
        public OfferResult ApplyOffer(Basket basket)
        {
            var quantity = basket.GetQuantity(_product);

            if (quantity <= 0)
            {
                return(null);
            }
            var unitPrice   = PricingService.GetUnitPrice(_product);
            var description = $"{_product.Name} {_discount:P0} off";
            var discount    = RoundingHelper.RoundPrice(unitPrice * quantity * _discount);

            return(new OfferResult(description, discount));
        }
Ejemplo n.º 27
0
        public void GetPricingPercent_PeriodAreDefinedForOneParametar_ResultShouldBeCorrectCase1()
        {
            var fromDate       = new DateTime(2020, 12, 25);
            var toDate         = new DateTime(2021, 01, 05);
            var expecterResult = 13;

            _pricingRepository.Setup(x => x.GetPricings()).Returns(_pricingFixtureData.MockedPricings);


            var pricingService = new PricingService(_pricingRepository.Object);
            var result         = pricingService.GetPricingPercent(fromDate, toDate);


            Assert.Equal(expecterResult, result);
        }
Ejemplo n.º 28
0
        public ShellViewModel(PricingService pricingService)
        {
            Items = new BindableCollection <ItemPrice>();

            monitor = new ClipboardMonitor();
            monitor.ClipboardData += (object sender, RoutedEventArgs e) =>
            {
                if (monitor.ClipboardContainsText)
                {
                    var lines = monitor.ClipboardText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    Items.Clear();
                    Items.AddRange(pricingService.GetPricesByNames(lines).OrderByDescending(x => x.DucatsRatio));
                }
            };
        }
Ejemplo n.º 29
0
        public CreateEc2InstancesViewModel(PricingService pricingService, ImagesService imagesService, InstancesStore instancesStore)
        {
            Prices    = new ObservableCollection <Ec2InstancePriceViewModel>();
            Instances = new ObservableCollection <CreateEc2InstanceViewModel>();
            Instances.Add(new CreateEc2InstanceViewModel());

            Images = new ObservableCollection <Ec2InstanceImageViewModel>();

            AppendInstanceCommand  = new Command(AppendInstance);
            CreateInstancesCommand = new Command(CreateInstances);
            LoadPricesCommand      = new Command(LoadPrices);

            PricingService = pricingService;
            ImagesService  = imagesService;
            InstancesStore = instancesStore;
        }
Ejemplo n.º 30
0
        public void Setup()
        {
            _customerId = Guid.NewGuid();
            List <IService> services = new List <IService> {
                new ServiceA(new DateTime(2020, 10, 01))
            };

            _customer = new Customer(_customerId)
            {
                Services = services
            };

            _customerService = Mock.Of <ICustomerService>();
            Mock.Get(_customerService).Setup(x => x.GetCustomer(_customerId)).Returns(() => _customer);
            _sut = new PricingService(_customerService);
        }
        public OfferResult ApplyOffer(Basket basket)
        {
            var ifProductQuantity = basket.GetQuantity(_ifProduct);

            if (ifProductQuantity > 0 && ifProductQuantity >= _ifQuantity)
            {
                var offerQuantity             = ifProductQuantity / _ifQuantity;
                var thenProductQuantity       = basket.GetQuantity(_thenProduct);
                var qualifyingProductQuantity = Math.Min(_thenQuantity * offerQuantity, thenProductQuantity);
                var unitPrice   = PricingService.GetUnitPrice(_thenProduct);
                var discount    = RoundingHelper.RoundPrice(qualifyingProductQuantity * unitPrice * _discount);
                var description = $"Buy {_ifQuantity} {_ifProduct.Name} get {_thenQuantity} {_thenProduct.Name} {_discount:P0} off";
                return(new OfferResult(description, discount));
            }
            return(null);
        }
Ejemplo n.º 32
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            StartCodeNumeric.Enabled = false;
            EndCodeNumeric.Enabled   = false;
            ThreadsNumeric.Enabled   = false;
            StartButton.Enabled      = false;

            _currentCode = (int)StartCodeNumeric.Value;

            for (var i = 0; i < ThreadsNumeric.Value; i++)
            {
                var thread         = new Thread(ThreadLoop);
                var pricingService = new PricingService();

                _couponScanners.Add(Tuple.Create(thread, pricingService));
                thread.Start(pricingService);
            }

            UpdateRequestsTimer.Enabled = true;
        }
Ejemplo n.º 33
0
        public void MultipleItems()
        {
            double         price1  = AnyInstance.AnyDouble;
            double         price2  = AnyInstance.AnyDouble + 1;
            int            amount1 = AnyInstance.AnyInt;
            int            amount2 = AnyInstance.AnyInt + 3;
            PricingService service = new PricingService(new MockProductRepository(x => new Product {
                Id = x, UnitPrice = x == 1 ? price1 : price2
            }));

            service.AddToCart(new OrderItem {
                ItemId = 1, Amount = amount1
            });
            service.AddToCart(new OrderItem {
                ItemId = 2, Amount = amount2
            });
            double expectedPrice = price1 * amount1 + price2 * amount2;

            Assert.AreEqual(expectedPrice, service.PriceOrder());
        }
Ejemplo n.º 34
0
 public void EmptyCart()
 {
     PricingService service = new PricingService(new MockProductRepository(x => new Product()));
     Assert.AreEqual(0, service.PriceOrder());
 }