示例#1
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));
        }
示例#2
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);
        }