Exemplo n.º 1
0
        public void Hack_Action_GivenDataSourceError_ReturnsErrorView()
        {
            var fixture = new Fixture();
            var createViewModelResponse = fixture.Build <MediatorResponse <HackViewModel> >()
                                          .With(x => x.Code, MediatorCodes.HackResponse.DataSourceError)
                                          .Create();

            _hackMediator.RequestHackViewModel().Returns(createViewModelResponse);

            var result = _controller.Hack() as ViewResult;

            result.ViewName.Should().Be("~/views/Hack/Error.cshtml");
        }
        public ActionResult Hack()
        {
            var mediatorResponse = _hackMediator.RequestHackViewModel();

            switch (mediatorResponse.Code)
            {
            case MediatorCodes.HackResponse.DataSourceError:
            case MediatorCodes.HackResponse.ViewModelError:
                return(View("~/views/Hack/Error.cshtml"));

            case MediatorCodes.HackResponse.Ok:
                return(View(mediatorResponse.ViewModel));

            default:
                throw new InvalidMediatorResponseCodeException(mediatorResponse.Code);
            }
        }