public ECommerceSurfaceController(IEcommerceService ecommerceService) { if (ecommerceService == null) { throw new ArgumentNullException("ecommerceService"); } _ecommerceService = ecommerceService; }
public CpxDisplayOrderController(IEcommerceService ecommerceService) { if (ecommerceService == null) { throw new ArgumentNullException("ecommerceService"); } _ecommerceService = ecommerceService; }
public void Add(IEcommerceService service) { if (_services.Any(x => x.Source == service.Source)) { throw new ArgumentException($"ECommerce service list already contains {service.Source.GetCode()}"); } _services.Add(service); }
public LoginModel(SignInManager <IdentityUser> signInManager, ILogger <LoginModel> logger, UserManager <IdentityUser> userManager, IEmailSender emailSender, IEcommerceService ecommerceService) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _logger = logger; _ecommerceService = ecommerceService; }
private Task MixedWorkload(IEcommerceService service, Random rng) { return(Task.Run(async() => { //90% of workload is queries if (rng.NextDouble() < 0.9) { int productId = rng.Next(1, 100000); await service.GetProductById(productId); } else { var customer = rng.Next(1, 1000); await service.PlaceOrder(customer, DateTimeOffset.Now, await RandomItems(service, rng)); } })); }
private async Task <List <OrderItem> > RandomItems(IEcommerceService service, Random rng) { var numItems = rng.Next(1, 5); var items = new List <OrderItem>(); for (int i = 0; i < numItems; i++) { var productId = rng.Next(1, 100000); var randomItem = new OrderItem { Quantity = rng.Next(1, 5), UnitPrice = rng.Next(39, 21399), Product = await service.GetProductById(productId) }; items.Add(randomItem); } return(items); }
public OrderController(IEcommerceService ecommerceService, IHttpContextAccessor context) { this.ecommerceService = ecommerceService; this.context = context; }
public void Initialise() { var builder = new ContainerBuilder(); builder.RegisterType<ContactRepository>().As<IContactRepository>(); builder.RegisterType<ContactSecondaryRepository>().As<IContactSecondaryRepository>(); builder.RegisterType<DefaultContactSynchroniser>().As<IContactSynchroniser>(); builder.RegisterType<ContactService>().As<IContactService>(); builder.RegisterType<MailChimpEmailSubscriptionConnector>().As<IEmailSubscriptionConnector>(); builder.RegisterType<OrderRepository>().As<IOrderRepository>(); builder.RegisterType<DiscountHandlerFactory>().As<IDiscountHandlerFactory>(); builder.RegisterType<EcommerceService>().As<IEcommerceService>(); builder.RegisterType<ShippingHandlerFactory>().As<IShippingHandlerFactory>(); builder.RegisterType<LocationHandlerFactory>().As<ILocationHandlerFactory>(); builder.RegisterType<LocationHandler>().As<ILocationHandler>(); builder.RegisterType<OrderQueueService>().As<IOrderQueueService>(); builder.RegisterType<EmailSubscriptionsService>().As<IEmailSubscriptionsService>(); builder.RegisterType<BespokePricingHandlerFactory>().As<IBespokePricingHandlerFactory>(); builder.RegisterType<OrderQueue>().As<IOrderQueue>(); builder.RegisterType<OrderCoordinator>().As<IOrderCoordinator>(); builder.RegisterType<Database>() .WithParameter("connectionString", ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString) .WithParameter("providerName", "System.Data.SqlClient"); //mocking config service var configService = new Mock<IConfigurationService>(); configService.Setup(x => x.GetConfiguration()).Returns(new CustomerPortalSection()); var product1 = new Product { Title = "Test Publication", Code = "OP1", ProductId = 100, OptionId = 0, Price = 5, ProductType = "P", OrderIndex = 2 }; var product1Status = new ProductOperationStatus {Status = true, Product = product1}; var course1 = new Product { Title = "Test Course 1", Location = "Flatford Mill", LocationCode = "FM", DepositAmount = 50, ProductId = 1000, OptionId = 2000, Price = 300, ProductType = "C", OptionTitle = "Sole Residency", OrderIndex = 1, Category = "F/1", VoucherCategory = "" }; var course1Status = new ProductOperationStatus {Status = true, Product = course1}; var course1WithoutOptions = new Product { Title = "Test Course 1", Location = "Flatford Mill", LocationCode = "FM", DepositAmount = 50, ProductId = 1000, ProductType = "C", OrderIndex = 1, Category = "F/1", VoucherCategory = "" }; var course1WithoutOptionsStatus = new ProductOperationStatus {Status = true, Product = course1WithoutOptions}; var course1Options = new List<ProductOption>(); course1Options.Add(new ProductOption {OptionId = 2000,Name="Sole Residency",OptionPrice=300}); course1Options.Add(new ProductOption { OptionId = 2001, Name = "Shared Room", OptionPrice = 250 }); course1Options.Add(new ProductOption { OptionId = 2002, Name = "Non Resident", OptionPrice = 200 }); var course1OptionsStatus = new ProductOptionOperationStatus {Status = true, ProductOptions = course1Options}; var course2 = new Product { Title = "Test Course 2", Location= "Juniper Hall", LocationCode = "JH", DepositAmount = 50, ProductId = 1001, OptionId = 2001, Price = 250, ProductType = "C", OptionTitle = "Shared room", OrderIndex = 1, Category = "H/1", VoucherCategory = "TESTFILT1" }; var course2Status = new ProductOperationStatus {Status = true, Product = course2}; var courseBespoke1 = new Product { Title = "Test Bespoke Course 1", Location = "Juniper Hall", LocationCode = "JH", DepositAmount = 50, ProductId = 2000, OptionId = 0, Price = (decimal)16.50, ProductType = "C", OptionTitle = "Sole occupancy", OrderIndex = 3, Category = "F/10", VoucherCategory = "" }; var courseBespoke1Status = new ProductOperationStatus { Status = true, Product = courseBespoke1 }; var courseBespoke2 = new Product { Title = "Test Bespoke Course 1", Location = "Juniper Hall", StartDateRange1 = new DateTime(2014,08,01), FinishDateRange1 = new DateTime(2014, 08, 10), LocationCode = "JH", DepositAmount = 50, ProductId = 2001, OptionId = 0, Price = (decimal)16.50, ProductType = "C", OptionTitle = "Sole occupancy", OrderIndex = 3, Category = "F/10", VoucherCategory = "" }; var courseBespoke2Status = new ProductOperationStatus { Status = true, Product = courseBespoke2 }; var Voucher20PercentOff = new Voucher { Title = "Ten per cent off", VoucherId = 1, Percentage = 10, OrderIndex = 1 }; var Voucher20PercentOffStatus = new VoucherOperationStatus { Status = true, Voucher = Voucher20PercentOff }; var Voucher20PercentOffFamilyCourses = new Voucher { Title = "Twenty per cent off family courses", VoucherId = 2, Percentage = 20, OrderIndex = 1, ProductCategoryFilter = "F", }; var Voucher20PercentOffFamilyCoursesStatus = new VoucherOperationStatus { Status = true, Voucher = Voucher20PercentOffFamilyCourses }; var Voucher20PoundPerItemWhenSpent100Pounds = new Voucher { Title = "Twenty pounds per item off when hundred pounds spent", VoucherId = 3, PerItemAmount = 20, OrderIndex = 1, MinimumPayment = 100 }; var Voucher20PoundPerItemWhenSpent100PoundsStatus = new VoucherOperationStatus { Status = true, Voucher = Voucher20PoundPerItemWhenSpent100Pounds }; var Voucher20PerCentWhenSpent100Pounds = new Voucher { Title = "Twenty pounds per cent off when hundred pounds spent", VoucherId = 4, PerItemAmount = 10, OrderIndex = 2, MinimumPayment = 100 }; var Voucher20PerCentWhenSpent100PoundsStatus = new VoucherOperationStatus { Status = true, Voucher = Voucher20PerCentWhenSpent100Pounds }; var Voucher10PerCentOnSelectedCourses = new Voucher { Title = "Ten per cent off selected courses", VoucherId = 5, Percentage = 10, VoucherCategoryFilter = "TESTFILT1", OrderIndex = 1, }; var Voucher10PerCentOnSelectedCoursesStatus = new VoucherOperationStatus { Status = true, Voucher = Voucher10PerCentOnSelectedCourses }; var VoucherNotFoundStatus = new VoucherOperationStatus { Status = false, Message="Voucher not found" }; //need to mock productRepository as tied to Umbraco nodes var productRepository = new Mock<IProductRepository>(); productRepository.Setup(x => x.GetProduct(100, 0)).Returns(product1Status); productRepository.Setup(x => x.GetProduct(1000,0)).Returns(course1WithoutOptionsStatus); productRepository.Setup(x => x.GetProduct(1000, 2000)).Returns(course1Status); productRepository.Setup(x => x.GetProductOptions(1000)).Returns(course1OptionsStatus); productRepository.Setup(x => x.GetProduct(1001, 2001)).Returns(course2Status); productRepository.Setup(x => x.GetProduct(2000, 0)).Returns(courseBespoke1Status); productRepository.Setup(x => x.GetProduct(2001, 0)).Returns(courseBespoke2Status); //need to mock VoucherRepository as tied to Umbraco nodes var VoucherRepository = new Mock<IVoucherRepository>(); VoucherRepository.Setup(x => x.GetVoucher("TEST1")).Returns(Voucher20PercentOffStatus); VoucherRepository.Setup(x => x.GetVoucher("TEST2")).Returns(Voucher20PercentOffFamilyCoursesStatus); VoucherRepository.Setup(x => x.GetVoucher("TEST3")).Returns(Voucher20PoundPerItemWhenSpent100PoundsStatus); VoucherRepository.Setup(x => x.GetVoucher("TEST4")).Returns(Voucher20PerCentWhenSpent100PoundsStatus); VoucherRepository.Setup(x => x.GetVoucher("TEST5")).Returns(Voucher10PerCentOnSelectedCoursesStatus); VoucherRepository.Setup(x => x.GetVoucher("TESTNOTFOUND")).Returns(VoucherNotFoundStatus); //need to mock IContactAuthenticationHandler as tied to HttpContext var contactAuthenticationHandler = new Mock<IContactAuthenticationHandler>(); contactAuthenticationHandler.Setup(x => x.IsCurrentUserLoggedIn()).Returns(false); contactAuthenticationHandler.Setup(x => x.GetUserId()).Returns(Guid.NewGuid().ToString()); builder.RegisterInstance(configService.Object).As<IConfigurationService>(); builder.RegisterInstance(contactAuthenticationHandler.Object).As<IContactAuthenticationHandler>(); builder.RegisterInstance(productRepository.Object).As<IProductRepository>(); builder.RegisterInstance(VoucherRepository.Object).As<IVoucherRepository>(); var container = builder.Build(); _sut = container.Resolve<IEcommerceService>(); }
public void Initialise() { var product = new Product { ProductId = 29397, ProductType = "P", OrderIndex = 1, Price = 3, Title = "Test Product" }; var product2 = new Product { ProductId = 29398, ProductType = "P", OrderIndex = 1, OptionId = 30001, Price = 3, Title = "Test Product with Option" }; var productRepository = new Mock<IProductRepository>(); productRepository.Setup(x => x.GetProduct(It.Is<int>(i => i == 29397),It.Is<int>(i => i==0))) .Returns(new ProductOperationStatus {Product = product, Status = true}); productRepository.Setup(x => x.GetProduct(It.Is<int>(i => i == 29398),It.Is<int>(i=>i==30001))) .Returns(new ProductOperationStatus {Product = product2, Status = true}); var voucherRepository = new Mock<IVoucherRepository>(); var contactRepository = new Mock<IContactRepository>(); Contact contact = new Contact {UserId = "1234", UserName = "******"}; contactRepository.Setup((x => x.GetContact())) .Returns(new ContactOperationStatus { Status = true, Contact = contact} ); //need to create UpdatedContact details new UpdatedContact var orderRepository = new Mock<IOrderRepository>(); orderRepository.Setup(x => x.Add(It.IsAny<Product>(), It.IsAny<int>(), It.IsAny<string>(),It.IsAny<decimal>(),It.IsAny<Contact>())) .Returns(new OrderOperationStatus {Status = true}); orderRepository.Setup(x => x.Update(It.IsAny<Product>(),It.IsAny<Product>(), It.IsAny<int>(),It.IsAny<string>(), It.IsAny<decimal>(),It.IsAny<Contact>())) .Returns(new OrderOperationStatus {Status = true}); orderRepository.Setup(x => x.Remove(It.IsAny<Product>(), It.IsAny<Contact>())) .Returns(new OrderOperationStatus {Status = true}); orderRepository.Setup(x => x.UpdateSpecialRequirements(It.IsAny<string>(),It.IsAny<int>(),It.IsAny<Contact>())) .Returns(new OrderOperationStatus { Status = true }); var configService = new Mock<IConfigurationService>(); configService.Setup(x => x.GetConfiguration()).Returns(new CustomerPortalSection()); _ecommerceService = new EcommerceService(orderRepository.Object, productRepository.Object, voucherRepository.Object, contactRepository.Object, configService.Object); }
public PaymentMediator(IPaymentProvider paymentProvider, ICashPaymentService cashService, IEcommerceServices ecommerceServices) { _paymentProvider = paymentProvider; _cashService = cashService; _ecommerceServices = ecommerceServices; _paymentProvider.OnFetchMoneyCommand += (sender, e) => { IEcommerceService ecomService = ecommerceServices[e.Source]; if (ecomService != null) { ecomService.FetchMoney(e.Order); } else { switch (e.Source) { case PaymentSource.Cash: foreach (ICashDeviceAdapter cashDevide in _cashService.CashDevices) { cashDevide.Start(); } break; default: throw new NotImplementedException($"Unknown payment source {e.Source.GetCode()}"); } } }; _paymentProvider.OnTotalAmountSpecified += (sender, e) => { // Notify all cash devices about duty (a remaining part of payment) was changed foreach (var cashDevice in _cashService.CashDevices) { cashDevice.ReduceOrSetDutyTo(e.Value); } }; _paymentProvider.OnGiveChangeSpecified += (sender, e) => { _cashService.IssueChange(e.ChangeAmount); }; foreach (var cashDevice in _cashService.CashDevices) { cashDevice.OnMoneyReceived += (sender, e) => { _paymentProvider.SomeMoneyIncome(PaymentSource.Cash, e.Money); // Notify all cash devices about duty (a remaining part of payment) was changed foreach (var device in _cashService.CashDevices) { device.ReduceOrSetDutyTo(_paymentProvider.Duty); } } } ; foreach (var cashDevice in _cashService.CashDevices) { cashDevice.OnSomeChangeIssued += (sender, e) => { _paymentProvider.SomeChangeExtracted(e.Money); } } ; foreach (var ecomService in _ecommerceServices.Services) { ecomService.OnReceived += (sender, e) => { _paymentProvider.SomeMoneyIncome(ecomService.Source, e.Income); }; } }
public ProductController(IEcommerceService ecommerceService, IHttpContextAccessor context = null) { this.ecommerceService = ecommerceService; this.context = context; }
public EcommerceController() { _validation = new ValidationModel(); _ecommerceService = new EcommerceService(); }