public void GetAritsInfo_Returns_Error_If_Exception_Occurs() { var repository = MockRepository.GenerateStub <ILastfmRepository>(); var controller = new ArtistInfoController(repository); var exceptionWhenLastfmIsDown = new WebException(); repository.Stub(r => r.FindArtistInfo(Arg <string> .Is.Anything)).Throw(exceptionWhenLastfmIsDown); var result = controller.GetArtistInfo(CreateArtistName()); Assert.That(result, Is.InstanceOf <ExceptionResult>()); Assert.That((result as ExceptionResult).Exception, Is.SameAs(exceptionWhenLastfmIsDown)); }
public void GetArtistInfo_Returns_InternalServerError_If_LastfmException_And_Not_ArtistNotFound() { var repository = MockRepository.GenerateStub <ILastfmRepository>(); var controller = new ArtistInfoController(repository); var lastfmException = new LastfmException("Invalid API key") { ErrorCode = 10 }; repository.Stub(r => r.FindArtistInfo(Arg <string> .Is.Anything)).Throw(lastfmException); var result = controller.GetArtistInfo(CreateArtistName()); Assert.That(result, Is.InstanceOf <ExceptionResult>()); }
public void GetArtistInfo_Returns_NotFound_If_LastfmException_ArtistNotFound() { var repository = MockRepository.GenerateStub <ILastfmRepository>(); var controller = new ArtistInfoController(repository); var lastfmException = new LastfmException("The artist you supplied could not be found") { ErrorCode = 6 }; repository.Stub(r => r.FindArtistInfo(Arg <string> .Is.Anything)).Throw(lastfmException); var result = controller.GetArtistInfo("Fake Band"); Assert.That(result, Is.InstanceOf <NotFoundResult>()); }