public void IndexShouldBeNotNullWhenProvidedArgumentsAreNotNullOrEmptyOrMalformed()
        {
            _productRepository.GetProducts().Returns(_preparedProducts);
            _productRepository.GetProductByName(Arg.Any <string>()).Returns(_expectedProduct);
            _stateRepository.GetStateByName(Arg.Any <string>()).Returns(_expectedState);
            var controller = new StateSelectionController(_stateRepository, _categoryRepository, _productRepository);

            var result = controller.Index(ProductName, StateName, ExampleCorrectPreferredPriceInput,
                                          ExampleCorrectCount);

            Assert.That(result, Is(NotNull()));
        }
        // GET: StateSelection
        public ActionResult Index(string product, string state, string preferredPriceInput = "0", int count = 1)
        {
            if (string.IsNullOrEmpty(product) || string.IsNullOrEmpty(state) ||
                string.IsNullOrEmpty(preferredPriceInput) || count < 1)
            {
                throw new HttpException(403, "The server cannot process request due to malformed or empty syntax");
            }

            try
            {
                var productModels        = _productDatabase.GetProducts();
                var categoryModels       = _categoryDatabase.GetCategories();
                var stateOfAmericaModels = _stateDatabase.GetStates();

                var chosenState   = _stateDatabase.GetStateByName(state.Trim());
                var chosenProduct = _productDatabase.GetProductByName(product.Trim());

                chosenProduct.PreferredPrice = ParsePrice(preferredPriceInput);

                // State Name
                var stateNameList = new List <string> {
                    chosenState.Name
                };

                // Product final price in current state
                Algorithm.CalculateFinalPrice(chosenProduct, chosenState, count);
                var finalPriceList = new List <double> {
                    chosenProduct.FinalPrice
                };

                // Tax for current state
                var taxes = new List <double> {
                    Algorithm.GetTax(chosenProduct, chosenState, count)
                };

                // Margin for chosen product in current state
                var margins = new List <double> {
                    Algorithm.CalculateMargin(chosenProduct, count)
                };

                var mainViewModel = new MainViewModel
                {
                    ProductSelectList  = new SelectList(productModels, "Name", "Name"),
                    CategorySelectList = new SelectList(categoryModels, "Name", "Name"),
                    StateSelectList    = new SelectList(stateOfAmericaModels, "Name", "Name"),
                    Tax              = taxes,
                    Margin           = margins,
                    FinalPrice       = finalPriceList,
                    StateNameList    = stateNameList,
                    ChosenProduct    = chosenProduct,
                    PurchasePrice    = Math.Round(chosenProduct.PurchasePrice, 2),
                    PreferredPrice   = chosenProduct.PreferredPrice,
                    NumberOfProducts = count,
                    ChosenState      = chosenState
                };

                return(View(mainViewModel));
            }
            catch (AccessToNotConnectedDatabaseException)
            {
                throw new HttpException(500, "Server encountered the problem with access to data");
            }
            catch (ItemNotFoundException)
            {
                throw new HttpException(404, "Requested resource does not exist");
            }
            catch (Exception)
            {
                throw new HttpException(500, "Server encountered some problems, please contact support");
            }
        }