コード例 #1
0
        public void Add_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            var testItem = new Invoice()
            {
                Id            = 1,
                InvoiceSender = "Teppo",
                RecipientName = "Lasse",
                RecipientIban = "FI1212341234423453",
                Reference     = "12345672",
                InvoiceNumber = "1234567890",
                Bic           = "NDEAFIHH",
                Total         = 20.00M,
                DueDay        = new DateTime(2020, 02, 02),
                Date          = DateTime.Today
            };

            // Act
            var createdResponse = _controller.Create(testItem);
            var item            = createdResponse.Value as Invoice;

            // Assert
            Assert.IsType <Invoice>(item);
            Assert.Equal("Teppo", item.InvoiceSender);
        }
コード例 #2
0
        public void TestAddInvoice()
        {
            InvoiceController ic = new InvoiceController();

            //load first customer by calling DBcontext
            InvoiceDB db = new InvoiceDB();
            Customer  c  = db.Customers.First();

            ((IObjectContextAdapter)db).ObjectContext.Detach(c); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext
            Assert.NotNull(c);

            Invoice i = new Invoice();

            i.CustomerID        = c.CustomerID;
            i.Customer          = c;
            i.AdvancePaymentTax = 10;
            i.Notes             = "Invoice notes";
            i.TimeStamp         = DateTime.Now;
            i.DueDate           = DateTime.Now.AddDays(90);
            i.Paid = false;
            i.Name = "Test invoice";

            System.Web.Mvc.ActionResult resultAdd = ic.Create(i);

            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAdd);
        }
コード例 #3
0
ファイル: InvoiceTests.cs プロジェクト: kariIT/devops-backend
        public void Add_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var nameMissingItem = new Invoice()
            {
                InvoiceSender = "Mikko",
                Total         = 12.00M
            };

            _controller.ModelState.AddModelError("RecipientName", "Required");

            // Act
            var badResponse = _controller.Create(nameMissingItem);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
コード例 #4
0
ファイル: InvoiceTest.cs プロジェクト: njmube/CoffeeInvoice
        public void TestAddInvoice()
        {
            InvoiceController ic = new InvoiceController();

            //load first customer by calling DBcontext
            InvoiceDB db = new InvoiceDB();
            Customer c = db.Customers.First();
            ((IObjectContextAdapter)db).ObjectContext.Detach(c); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext
            Assert.NotNull(c);

            Invoice i = new Invoice();
            i.CustomerID = c.CustomerID;
            i.Customer = c;
            i.AdvancePaymentTax = 10;
            i.Notes = "Invoice notes";
            i.TimeStamp = DateTime.Now;
            i.DueDate = DateTime.Now.AddDays(90);
            i.Paid = false;
            i.Name = "Test invoice";

            System.Web.Mvc.ActionResult resultAdd = ic.Create(i);

            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAdd);
        }