public void OnGet_AlbumServiceGetAlbumsByGenreReturnsAlbums_ReturnsAlbumResponse() { var pages = (IList <string>)null; var albumServiceFake = A.Fake <IAlbumService>(); A.CallTo(() => albumServiceFake.GetAlbumsByGenre(A <string> .Ignored, A <int> .Ignored, A <int> .Ignored, out pages)).Returns(new List <IAlbum> { A.Fake <Album>() }); var service = new AlbumRestService { LogFactory = A.Fake <ILogFactory>(), AlbumService = albumServiceFake }; var response = service.OnGet(new AlbumRequest { Territory = "se", Genre = 2, Page = 1 }); Assert.That(response, Is.TypeOf <AlbumResponse>()); var albumResponse = (AlbumResponse)response; Assert.That(albumResponse.Info.Territory, Is.EqualTo("se")); Assert.That(albumResponse.Info.Genre, Is.EqualTo(2)); Assert.That(albumResponse.Info.Page, Is.EqualTo(1)); Assert.That(albumResponse.Albums.Count, Is.EqualTo(1)); }
public void OnGet_GenreIsLessThanZero_ReturnsErrorResponseWithStatusCodeBadRequest() { var service = new AlbumRestService { LogFactory = A.Fake <ILogFactory>() }; var response = service.OnGet(new AlbumRequest { Territory = "se", Genre = -1, Page = 1 }); Assert.That(response, Is.TypeOf <ErrorResponse>()); Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest)); }
public void OnGet_TerritoryInvalidLength_ReturnsErrorResponseWithStatusCodeBadRequest(string territory) { var service = new AlbumRestService { LogFactory = A.Fake <ILogFactory>() }; var response = service.OnGet(new AlbumRequest { Territory = territory, Genre = null, Page = 1 }); Assert.That(response, Is.TypeOf <ErrorResponse>()); Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest)); }
public void OnGet_RequestIsValidGenreIsNull_CallsAlbumServiceGetAlbums() { var albumServiceFake = A.Fake <IAlbumService>(); var service = new AlbumRestService { LogFactory = A.Fake <ILogFactory>(), AlbumService = albumServiceFake }; var response = service.OnGet(new AlbumRequest { Territory = "se", Genre = null, Page = 1 }); var pages = (IList <string>)null; A.CallTo(() => albumServiceFake.GetAlbums("se", 1, out pages)).MustHaveHappened(Repeated.Exactly.Once); }
public void OnGet_AlbumServiceGetAlbumsByGenreThrowsException_ReturnsErrorResponseWithStatusCodeInternalServerError() { var pages = (IList <string>)null; var albumServiceFake = A.Fake <IAlbumService>(); A.CallTo(() => albumServiceFake.GetAlbumsByGenre(A <string> .Ignored, A <int> .Ignored, A <int> .Ignored, out pages)).Throws(new Exception("foo")); var service = new AlbumRestService { LogFactory = A.Fake <ILogFactory>(), AlbumService = albumServiceFake }; var response = service.OnGet(new AlbumRequest { Territory = "se", Genre = 2, Page = 1 }); Assert.That(response, Is.TypeOf <ErrorResponse>()); Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.InternalServerError)); }