public void Hero_Action_GivenDataSourceError_ReturnsErrorView()
        {
            var fixture = new Fixture();
            var createViewModelResponse = fixture.Build <MediatorResponse <HeroViewModel> >()
                                          .With(x => x.Code, MediatorCodes.HeroResponse.DataSourceError)
                                          .Create();

            _heroMediator.RequestHeroViewModel().Returns(createViewModelResponse);

            var result = _controller.Hero() as ViewResult;

            result.ViewName.Should().Be("~/views/Hero/Error.cshtml");
        }
示例#2
0
        public ActionResult Hero()
        {
            var mediatorResponse = _heroMediator.RequestHeroViewModel();

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

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

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