public void IfIndexWillBeCorrectlyInvokedThenMainViewModelOfActionResultShouldMatchingToExpectedOne()
            {
                _stateRepository.GetStates().Returns(_preparedStates);
                _productRepository.GetProducts().Returns(_preparedProducts);
                _categoryRepository.GetCategories().Returns(_preparedCategories);

                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                var result = controller.Index(CategoryName) as ViewResult;

                Assert.That(result, Is(NotNull()));

                var viewModel = result?.Model as MainViewModel;

                Assert.That(viewModel, Is(NotNull()));

                var productsList   = viewModel?.ProductSelectList.Items.Cast <ProductModel>().ToList();
                var statesList     = viewModel?.StateSelectList.Items.Cast <StateOfAmericaModel>().ToList();
                var categoriesList = viewModel?.CategorySelectList.Items.Cast <CategoryModel>().ToList();

                Assert.That(productsList, Is <ICollection>(Not(OfLength(0))));
                Assert.That(statesList, Is <ICollection>(Not(OfLength(0))));
                Assert.That(categoriesList, Is <ICollection>(Not(OfLength(0))));

                Assert.That(productsList, Has(Item(EqualTo(_expectedProduct))));
                Assert.That(categoriesList, Has(Item(EqualTo(_expectedCategory))));
                Assert.That(statesList, Has(Item(EqualTo(_expectedState))));
                Assert.That(viewModel?.ProductList, Has(Item(EqualTo(_expectedProduct))));
                Assert.That(viewModel?.Category, Is(EqualTo(CategoryName)));
            }
            public void IndexPageShouldCallGetStatesOfStatesRepositoryOnlyOneTime()
            {
                _productRepository.GetProducts().Returns(_preparedProducts);
                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                controller.Index(CategoryName);
                _stateRepository.Received(1).GetStates();
            }
            public void IndexShouldBeNotNullWhenProvidedArgumentsAreNotNullOrEmptyOrMalformed()
            {
                _productRepository.GetProducts().Returns(_preparedProducts);
                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                var result = controller.Index(CategoryName);

                Assert.That(result, Is(NotNull()));
            }
            IndexShouldThrowHttpExceptionWithCode500AndSpecifiedMessageForAccessToDbIssuesIfAnyRepositoryThrewAnException()
            {
                _productRepository.GetProducts().Throws(new Exception());
                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                ActionResult Call() => controller.Index(CategoryName);

                var exception = Xunit.Assert.Throws <HttpException>(Call);

                var code    = exception.GetHttpCode();
                var message = exception.Message;

                Assert.That(code, Is(EqualTo(Http500)));
                Assert.That(message, Is(EqualTo(ExpectedMessageOf500CodeForAnyException)));
            }
            IndexShouldThrowHttpExceptionWithCode404AndSpecifiedMessageIfAnyRepositoryThrewAnItemNotFoundException()
            {
                _categoryRepository.GetCategories().Throws <ItemNotFoundException>();
                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                ActionResult Call() => controller.Index(CategoryName);

                var exception = Xunit.Assert.Throws <HttpException>(Call);

                var code    = exception.GetHttpCode();
                var message = exception.Message;

                Assert.That(code, Is(EqualTo(Http404)));
                Assert.That(message, Is(EqualTo(ExpectedMessageOf404Code)));
            }
            public void IndexShouldThrowHttpExceptionWithCode403AndSpecifiedMessageIfCategoryStringWillBeNullOrEmpty()
            {
                var controller =
                    new CategorySelectionController(_categoryRepository, _stateRepository, _productRepository);

                ActionResult Call() => controller.Index(Empty);

                ActionResult CallWithNull() => controller.Index(null);

                var exception  = Xunit.Assert.Throws <HttpException>(Call);
                var exception2 = Xunit.Assert.Throws <HttpException>(CallWithNull);

                var code    = exception.GetHttpCode();
                var message = exception.Message;

                Assert.That(code, Is(EqualTo(Http403)));
                Assert.That(message, Is(EqualTo(ExpectedMessageFor403Code)));
                Assert.That(code, Is(EqualTo(exception2.GetHttpCode())));
                Assert.That(message, Is(EqualTo(exception2.Message)));
            }