public void Checkout() { // Arrange TaxServiceController controller = new TaxServiceController(); // Act // Verify initial form loads ViewResult result = controller.Checkout() as ViewResult; // Verify page loads with results ViewResult resultPost = controller.Checkout(100, "NY", "10590", false) as ViewResult; // Verify page loads after resetting form ViewResult resultPageReset = controller.Checkout(0, "", "", true) as ViewResult; // Verify error messages populate var model = (TaxResultViewModel)result.Model; var modelPost = (TaxResultViewModel)resultPost.Model; var modelPageReset = (TaxResultViewModel)resultPageReset.Model; // Assert // Initial form Assert.IsNotNull(result); // Page with results Assert.IsNotNull(resultPost); // Page after form reset Assert.IsNotNull(resultPageReset); // Error messages Assert.IsNotNull(model.ErrorMessage); Assert.IsNotNull(modelPost.ErrorMessage); Assert.IsNotNull(modelPageReset.ErrorMessage); }
public void Setup() { var taxApiProviders = new ConfigurationBuilder().AddJsonFile("taxapiproviders.json").Build(); _apiSettings = new TaxProviderSettings(); taxApiProviders.Bind(_apiSettings); _configuration = new ConfigurationRoot(new List <IConfigurationProvider>()); _configuration.Bind("TaxApiProviders", taxApiProviders); _taxServicecontroller = new TaxServiceController(_configuration) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public void TaxJar_GetTotalTaxController_InValidZip() { var mock = new Mock <TaxCalcMapper>(); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); mock.Setup(x => x.Invoke(It.IsAny <string>())).Returns(new TaxJar(configuration)); var taxServiceController = new TaxServiceController(mock.Object); var response = taxServiceController.GetTotalTax(zip: "123", orderTotal: 100); var payload = response as OkObjectResult; Assert.Equal(200, payload.StatusCode); Assert.Contains("Invalid Zip Code", payload.Value.ToString()); }
public void ConfigureServices_RegistersDependenciesCorrectly() { // Arrange IServiceCollection services = new ServiceCollection(); var target = new Startup(configuration); // Act target.ConfigureServices(services); // Mimic internal asp.net core logic. services.AddTransient <TaxServiceController>(); services.AddSingleton <ITaxjarService, TaxjarService>(); var serviceProvider = services.BuildServiceProvider(); controller = serviceProvider.GetService <TaxServiceController>(); // Assert Assert.IsNotNull(controller); }
public void GetTaxResultForOrder() { // Arrange TaxServiceController controller = new TaxServiceController(); // Act // Verify tax rate is successfully returned with valid query TaxResult result = controller.GetTaxResultForOrder(new TaxRequest() { FromCountry = "US", FromState = "NY", FromCity = "New York", FromZip = "10003", Amount = 100, ShippingAmount = 0, ToCountry = "US", ToState = "CT", ToZip = "06877", NexusAddresses = new List <NexusAddress>() { new NexusAddress { Country = "US", State = "NY", ZipCode = "10003" }, new NexusAddress { Country = "US", State = "CT", ZipCode = "06877" } } }); // Assert // Valid query Assert.IsNotNull(result); // Object returned is of type TaxResult Assert.IsTrue(result.GetType() == typeof(TaxResult)); }
public void GetTaxRateForLocation() { // Arrange TaxServiceController controller = new TaxServiceController(); // Act // Verify tax rate is successfully returned with valid query Decimal result = controller.GetTaxRateForLocation(new TaxRequest() { FromCountry = "US", FromState = "NY", FromCity = "New York", FromZip = "10003", Amount = 100, ShippingAmount = 0, ToCountry = "US", ToState = "CT", ToZip = "06877", NexusAddresses = new List <NexusAddress>() { new NexusAddress { Country = "US", State = "NY", ZipCode = "10003" }, new NexusAddress { Country = "US", State = "CT", ZipCode = "06877" } } }); // Assert // Valid query Assert.IsNotNull(result); // Value returned is a decimal greater than or equal to 0 Assert.IsTrue(result.GetType() == typeof(decimal) && result >= 0); }