Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }