/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public ProductVariantApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _productService = MerchelloContext.Services.ProductService; _productVariantService = MerchelloContext.Services.ProductVariantService; _warehouseService = MerchelloContext.Services.WarehouseService; }
public void PutInvoiceUpdatesRepository() { //// Arrange Guid key = Guid.NewGuid(); bool wasCalled = false; int id = 1; Invoice invoice = CreateFakeInvoice(id, key); var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.Save(invoice, It.IsAny <bool>())).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutInvoice(invoice); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.True(wasCalled); }
public void GetProductByKeysReturnsCorrectItemsFromRepository() { //// Arrange Guid productKey = Guid.NewGuid(); ProductActual productActual = CreateFakeProduct(productKey, 20.0M); Guid productKey2 = Guid.NewGuid(); ProductActual product2 = CreateFakeProduct(productKey2, 30.0M); Guid productKey3 = Guid.NewGuid(); ProductActual product3 = CreateFakeProduct(productKey3, 40.0M); List <ProductActual> productsList = new List <ProductActual>(); productsList.Add(productActual); productsList.Add(product3); var productKeys = new[] { productKey, productKey3 }; var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.GetByKeys(productKeys)).Returns(productsList); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetProducts(productKeys); //// Assert Assert.AreEqual(productsList, result); }
/// <summary> /// Test to verify that the proper error response is returned on an error /// </summary> //[Test] public void PutInvoiceReturns500WhenRepositoryUpdateReturnsError() { //// Arrange Guid key = Guid.NewGuid(); int id = 1; Invoice invoice = CreateFakeInvoice(id, key); var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.Save(invoice, It.IsAny <bool>())).Throws <InvalidOperationException>(); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutInvoice(invoice); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode); }
/// <summary> /// Initializes a new instance of the <see cref="MerchelloApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> /// <param name="umbracoContext"> /// The umbraco context. /// </param> protected MerchelloApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(umbracoContext) { Mandate.ParameterNotNull(merchelloContext, "merchelloContext"); MerchelloContext = merchelloContext; InstanceId = Guid.NewGuid(); }
public void PutProductUpdatesRepository() { //// Arrange bool wasCalled = false; Guid productKey = Guid.NewGuid(); ProductActual productActual = CreateFakeProduct(productKey, 20.0M); var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.Save(productActual, It.IsAny <bool>())).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutProduct(productActual); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.True(wasCalled); }
public void DeleteProductCallsRepositoryRemove() { //// Arrange Guid removedKey = Guid.Empty; Guid productKey = new Guid(); ProductActual productActual = CreateFakeProduct(productKey, 20.0M); var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.Delete(productActual, It.IsAny <bool>())).Callback <IProductActual, bool>((p, b) => removedKey = p.Key); MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns(productActual); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.Delete(productKey); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(productKey, removedKey); }
/// <summary> /// Initializes a new instance of the <see cref="ShippingGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> public ShippingGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _shippingContext = MerchelloContext.Gateways.Shipping; _shipCountryService = ((ServiceContext)MerchelloContext.Services).ShipCountryService; }
public void DeleteInvoiceCallsRepositoryRemove() { //// Arrange Guid key = Guid.NewGuid(); int removedId = 0; int id = 1; Invoice invoice = CreateFakeInvoice(id, key); var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.Delete(invoice, It.IsAny <bool>())).Callback <IInvoice, bool>((p, b) => removedId = p.Id); MockInvoiceService.Setup(cs => cs.GetById(1)).Returns(invoice); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.Delete(id); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); }
/// <summary> /// Initializes a new instance of the <see cref="ShippingGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> public ShippingGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _shippingContext = MerchelloContext.Gateways.Shipping; _shipCountryService = ((ServiceContext)MerchelloContext.Services).ShipCountryService; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public CatalogFixedRateShippingApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _shipCountryService = ((ServiceContext)MerchelloContext.Services).ShipCountryService; _fixedRateShippingGatewayProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.GetProviderByKey(Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey); _shippingContext = MerchelloContext.Gateways.Shipping; }
public void PutCustomerUpdatesRepository() { //// Arrange bool wasCalled = false; Guid customerKey = Guid.NewGuid(); AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerKey); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.Save(anonymousCustomer, It.IsAny<bool>())).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); ctrl.Request = new HttpRequestMessage(); ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); //// Act HttpResponseMessage response = ctrl.PutCustomer(anonymousCustomer); //// Assert Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.True(wasCalled); }
/// <summary> /// This is a helper contructor for unit testing /// </summary> internal ProductVariantApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _productService = MerchelloContext.Services.ProductService; _productVariantService = MerchelloContext.Services.ProductVariantService; _warehouseService = MerchelloContext.Services.WarehouseService; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public CatalogFixedRateShippingApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _shipCountryService = ((ServiceContext) MerchelloContext.Services).ShipCountryService; _fixedRateShippingGatewayProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.GetProviderByKey(Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey); _shippingContext = MerchelloContext.Gateways.Shipping; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public ShippingGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _shippingContext = MerchelloContext.Gateways.Shipping; _gatewayProviderService = MerchelloContext.Services.GatewayProviderService; _storeSettingService = MerchelloContext.Services.StoreSettingService; _shipCountryService = ((ServiceContext)MerchelloContext.Services).ShipCountryService; }
public void NewInvoiceReturnsCorrectInvoice() { //// Arrange Guid key = Guid.NewGuid(); bool wasCalled = false; int id = 1; Invoice invoice = CreateFakeInvoice(id, key); var customer = new AnonymousCustomer(100.00m, 100.00m, DateTime.Now); customer.FirstName = "John"; customer.LastName = "Jones"; customer.Email = "*****@*****.**"; customer.MemberId = 1004; var address = new CustomerAddress(customer, "Address") { Address1 = "123 Test St.", Address2 = "Apt 1", Locality = "USA", Region = "USA", PostalCode = "97333-0123", CountryCode = "US", Phone = "555-555-5555", Company = "Test Company" }; var invoiceStatus = new InvoiceStatus() { Alias = "unpaid", Name = "Unpaid", Active = true, Reportable = true, SortOrder = 1 }; var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.CreateInvoice(customer, address, invoiceStatus, "Test Invoice 1")).Returns(invoice).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); //// Act Invoice result = null; //Invoice result = ctrl.NewInvoice(customer, address, invoiceStatus, "Test Invoice 1"); //// Assert Assert.AreEqual(invoice, result); Assert.True(wasCalled); }
public void GetProductThrowsWhenRepositoryReturnsNull() { //// Arrange Guid productKey = Guid.NewGuid(); var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns((ProductActual)null); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); //// Act & Assert var ex = Assert.Throws <HttpResponseException>(() => ctrl.GetProduct(Guid.Empty)); }
public void GetCustomerThrowsWhenRepositoryReturnsNull() { // Arrange Guid customerKey = Guid.NewGuid(); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.GetById(customerKey)).Returns((AnonymousCustomer)null); var MockServiceContext = new Mock<IServiceContext>(); MockServiceContext.SetupGet(sc => sc.CustomerService).Returns(MockCustomerService.Object); MerchelloContext merchelloContext = new MerchelloContext(MockServiceContext.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); var ex = Assert.Throws<HttpResponseException>(() => ctrl.GetCustomer(Guid.Empty)); }
public void GetInvoiceThrowsWhenRepositoryReturnsNull() { // Arrange int id = 1; var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.GetById(id)).Returns((Invoice)null); var MockServiceContext = new Mock <IServiceContext>(); MockServiceContext.SetupGet(sc => sc.InvoiceService).Returns(MockInvoiceService.Object); MerchelloContext merchelloContext = new MerchelloContext(MockServiceContext.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); var ex = Assert.Throws <HttpResponseException>(() => ctrl.GetInvoiceById(0)); }
public void GetProductByKeyReturnsCorrectItemFromRepository() { //// Arrange Guid productKey = Guid.NewGuid(); ProductActual productActual = MockProductDataMaker.MockProductComplete(productKey) as ProductActual; var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns(productActual); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetProduct(productKey); //// Assert Assert.AreEqual(productActual, result); }
public void GetCustomerByKeyReturnsCorrectItemFromRepository() { // Arrange int customerId = 20; AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerId); var MockCustomerService = new Mock<ICustomerService>(); MockCustomerService.Setup(cs => cs.GetById(customerId)).Returns(anonymousCustomer); MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object); CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetCustomer(customerId); //// Assert Assert.AreEqual(anonymousCustomer, result); }
public void GetInvoiceByKeyReturnsCorrectItemFromRepository() { // Arrange int id = 1; Guid key = Guid.NewGuid(); Invoice invoice = CreateFakeInvoice(1, key); var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.GetById(id)).Returns(invoice); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetInvoiceById(id); //// Assert Assert.AreEqual(invoice, result); }
public void GetInvoicesByCustomerReturnsCorrectItemsFromRepository() { //// Arrange Guid key = Guid.NewGuid(); int invoiceId1 = 1; Invoice invoice = CreateFakeInvoice(invoiceId1, key); int invoiceId2 = 2; Invoice invoice2 = CreateFakeInvoice(invoiceId2, key); int invoiceId3 = 3; Invoice invoice3 = CreateFakeInvoice(invoiceId3, key); List <Invoice> invoiceList = new List <Invoice>(); invoiceList.Add(invoice); invoiceList.Add(invoice2); invoiceList.Add(invoice3); List <int> invoiceIds = new List <int>() { invoiceId1, invoiceId3 }; var MockInvoiceService = new Mock <IInvoiceService>(); MockInvoiceService.Setup(cs => cs.GetInvoicesByCustomer(key)).Returns(invoiceList); MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object); InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext); //// Act var result = ctrl.GetInvoicesByCustomer(key); //// Assert Assert.AreEqual(invoiceList, result); }
public void NewProductReturnsCorrectProduct() { //// Arrange bool wasCalled = false; Guid productKey = Guid.NewGuid(); ProductActual productActual = CreateFakeProduct(productKey, 20.0M); var MockProductService = new Mock <IProductService>(); MockProductService.Setup(cs => cs.CreateProduct(productActual.Sku, productActual.Name, productActual.Price)).Returns(productActual).Callback(() => wasCalled = true); MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object); ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext); //// Act ProductActual result = ctrl.NewProduct(productActual.Sku, productActual.Name, productActual.Price); //// Assert Assert.AreEqual(productActual, result); Assert.True(wasCalled); }
/// <summary> /// Initializes a new instance of the <see cref="NotificationsApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello Context. /// </param> /// <param name="umbracoContext"> /// The umbraco Context. /// </param> internal NotificationsApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _notificationMessageService = ((ServiceContext)MerchelloContext.Services).NotificationMessageService as NotificationMessageService; }
/// <summary> /// Initializes a new instance of the <see cref="NotificationsApiController"/> class. /// </summary> /// <param name="merchelloContext">The merchello context</param> public NotificationsApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _notificationMessageService = ((ServiceContext)MerchelloContext.Services).NotificationMessageService as NotificationMessageService; }
/// <summary> /// Initializes a new instance of the <see cref="FixedRateShippingApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> public FixedRateShippingApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _fixedRateShippingGatewayProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.GetProviderByKey(Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey); }
/// <summary> /// This is a helper contructor for unit testing /// </summary> internal WarehouseApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _warehouseService = MerchelloContext.Services.WarehouseService; }
/// <summary> /// Initializes a new instance of the <see cref="WarehouseApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> /// <param name="umbracoContext"> /// The umbraco context. /// </param> internal WarehouseApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _warehouseService = MerchelloContext.Services.WarehouseService; }
/// <summary> /// Initializes a new instance of the <see cref="PaymentGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public PaymentGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _paymentContext = MerchelloContext.Gateways.Payment; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public NotificationGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _notificationContext = ((GatewayContext)MerchelloContext.Gateways).Notification; }
/// <summary> /// Initializes a new instance of the <see cref="PaymentGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public PaymentGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _paymentContext = MerchelloContext.Gateways.Payment; }
/// <summary> /// Initializes a new instance of the <see cref="FixedRateShippingApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> public FixedRateShippingApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _fixedRateShippingGatewayProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.GetProviderByKey(Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey); }
/// <summary> /// Initializes a new instance of the <see cref="WarehouseApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> public WarehouseApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _warehouseService = MerchelloContext.Services.WarehouseService; }
/// <summary> /// This is a helper contructor for unit testing /// </summary> internal CustomerApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _customerService = MerchelloContext.Services.CustomerService; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public CustomerApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _customerService = MerchelloContext.Services.CustomerService; }
/// <summary> /// Constructor /// </summary> /// <param name="merchelloContext"></param> public SettingsApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService; }
/// <summary> /// This is a helper contructor for unit testing /// </summary> internal SettingsApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService; }
/// <summary> /// Initializes a new instance of the <see cref="NotificationGatewayApiController"/> class. /// </summary> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> public NotificationGatewayApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _notificationContext = ((GatewayContext)MerchelloContext.Gateways).Notification; _notificationMessageService = ((ServiceContext)MerchelloContext.Services).NotificationMessageService; }
/// <summary> /// Initializes a new instance of the <see cref="SettingsApiController"/> class. /// Constructor /// </summary> /// <param name="merchelloContext"> /// The merchello context /// </param> public SettingsApiController(MerchelloContext merchelloContext) : base(merchelloContext) { _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService; }
/// <summary> /// Initializes a new instance of the <see cref="SettingsApiController"/> class. /// This is a helper contructor for unit testing /// </summary> /// <param name="merchelloContext"> /// The merchello Context. /// </param> /// <param name="umbracoContext"> /// The umbraco Context. /// </param> internal SettingsApiController(MerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService; }