Beispiel #1
0
        public InvoiceControllerTests()
        {
            var mockTempDataSerializer = new Mock <TempDataSerializer>();
            var mockDataProvider       = new Mock <SessionStateTempDataProvider>(mockTempDataSerializer.Object);


            MockDbContext      = new Mock <ApplicationDbContext>(new DbContextOptions <ApplicationDbContext>());
            MockInvoiceService = new Mock <IInvoiceService>();
            MockUserManager    = new Mock <FakeApplicationUserManager>();
            MockSettings       = new Mock <IOptions <SlothSettings> >();

            //MockClaimsPrincipal = new Mock<ClaimsPrincipal>();
            MockHttpContext = new Mock <HttpContext>();

            //Default Data
            UserData = new List <User>();
            for (int i = 0; i < 5; i++)
            {
                var user = CreateValidEntities.User(i + 1);
                UserData.Add(user);
            }

            InvoiceData = new List <Invoice>();
            for (int i = 0; i < 5; i++)
            {
                var invoice = CreateValidEntities.Invoice(i + 1);
                invoice.Status = Invoice.StatusCodes.Paid;
                InvoiceData.Add(invoice);
            }

            InvoiceData[1].Status = Invoice.StatusCodes.Sent;

            //Setups
            MockDbContext.Setup(a => a.Invoices).Returns(InvoiceData.AsQueryable().MockAsyncDbSet().Object);
            MockUserManager.Setup(a => a.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(UserData[1]);

            var routeData = new RouteData();

            routeData.Values.Add("team", "testSlug");
            Controller = new InvoicesController(MockUserManager.Object, MockDbContext.Object, MockInvoiceService.Object, MockSettings.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = MockHttpContext.Object,
                    RouteData   = routeData
                },
                TempData = new TempDataDictionary(MockHttpContext.Object, mockDataProvider.Object),
            };
        }
Beispiel #2
0
        public void TestCyberSourceTruncationOfDictionaryFieldCompanyName1(string value, string expectedValue)
        {
            // Arrange
            var invoice = CreateValidEntities.Invoice(1, 1);

            invoice.CustomerCompany = value;
            invoice.UpdateCalculatedValues();
            invoice.CustomerEmail.ShouldNotBeNull();
            invoice.CustomerName.ShouldNotBeNull();

            // Act
            var result = invoice.GetPaymentDictionary();

            // Assert
            result.ShouldBeOfType <Dictionary <string, string> >();
            result.Count.ShouldBe(14 + (2 * invoice.Items.Count));

            result["transaction_type"].ShouldBe("sale");
            result["reference_number"].ShouldBe(invoice.Id.ToString());
            result["amount"].ShouldBe(invoice.CalculatedTotal.ToString("F2"));
            result["currency"].ShouldBe("USD");
            result["transaction_uuid"].ShouldNotBeNull();
            result["signed_date_time"].ShouldNotBeNull();
            result["unsigned_field_names"].ShouldBe("");
            result["locale"].ShouldBe("en");
            result["bill_to_email"].ShouldBe(invoice.CustomerEmail);
            result["bill_to_forename"].ShouldBe(invoice.CustomerName);
            result["bill_to_address_country"].ShouldBe("US");
            result["bill_to_address_state"].ShouldBe("CA");
            result["line_item_count"].ShouldBe("1");
            if (expectedValue == null)
            {
                result["bill_to_company_name"].ShouldBeNull();
            }
            else
            {
                result["bill_to_company_name"].Length.ShouldBeLessThanOrEqualTo(40);
                result["bill_to_company_name"].ShouldBe(expectedValue);
            }

            for (int i = 0; i < 1; i++)
            {
                result[$"item_{i}_name"].ShouldBe(invoice.Items[i].Description);
                //result[$"item_{i}_quantity"].ShouldBe(invoice.Items[i].Quantity.ToString()); //This is gone
                result[$"item_{i}_unit_price"].ShouldBe((invoice.Items[i].Amount * invoice.Items[i].Quantity).ToString("F2"));
            }
        }
Beispiel #3
0
        public void TestGetPaymentDictionaryReturnsExpectedValues2(int value)
        {
            // Arrange
            var invoice = CreateValidEntities.Invoice(value, value);

            invoice.CustomerCompany = "FakeCompany";
            invoice.UpdateCalculatedValues();
            invoice.CustomerEmail.ShouldNotBeNull();
            invoice.CustomerName.ShouldNotBeNull();

            // Act
            var result = invoice.GetPaymentDictionary();

            // Assert
            result.ShouldBeOfType <Dictionary <string, string> >();
            result.Count.ShouldBe(14 + (2 * invoice.Items.Count));

            result["transaction_type"].ShouldBe("sale");
            result["reference_number"].ShouldBe(invoice.Id.ToString());
            result["amount"].ShouldBe(invoice.CalculatedTotal.ToString("F2"));
            result["currency"].ShouldBe("USD");
            result["transaction_uuid"].ShouldNotBeNull();
            result["signed_date_time"].ShouldNotBeNull();
            result["unsigned_field_names"].ShouldBe("");
            result["locale"].ShouldBe("en");
            result["bill_to_email"].ShouldBe(invoice.CustomerEmail);
            result["bill_to_forename"].ShouldBe(invoice.CustomerName);
            result["bill_to_address_country"].ShouldBe("US");
            result["bill_to_address_state"].ShouldBe("CA");
            result["line_item_count"].ShouldBe(value.ToString());
            result["bill_to_company_name"].ShouldBe("FakeCompany");

            for (int i = 0; i < value; i++)
            {
                result[$"item_{i}_name"].ShouldBe(invoice.Items[i].Description);
                //result[$"item_{i}_quantity"].ShouldBe(invoice.Items[i].Quantity.ToString()); //This is gone
                result[$"item_{i}_unit_price"].ShouldBe((invoice.Items[i].Amount * invoice.Items[i].Quantity).ToString("F2"));
            }
        }