public void OnGet_ArtistAlbumServiceGetAlbumsReturnsAlbums_ReturnsArtistAlbumResponse() { var artistAlbumServiceFake = A.Fake <IArtistAlbumService>(); A.CallTo(() => artistAlbumServiceFake.GetAlbums(A <string> .Ignored, A <string> .Ignored)).Returns(new List <IAlbum> { A.Fake <Album>() }); var service = new ArtistAlbumRestService { LogFactory = A.Fake <ILogFactory>(), ArtistAlbumService = artistAlbumServiceFake }; var response = service.OnGet(new ArtistAlbumRequest { Territory = "se", ArtistHref = "abc" }); var pages = (IList <string>)null; var albumServiceFake = A.Fake <IAlbumService>(); A.CallTo(() => albumServiceFake.GetAlbums(A <string> .Ignored, A <int> .Ignored, out pages)).Returns(new List <IAlbum> { A.Fake <Album>() }); Assert.That(response, Is.TypeOf <ArtistAlbumResponse>()); var artistAlbumResponse = (ArtistAlbumResponse)response; Assert.That(artistAlbumResponse.Info.Territory, Is.EqualTo("se")); Assert.That(artistAlbumResponse.Info.ArtistHref, Is.EqualTo("abc")); Assert.That(artistAlbumResponse.Albums.Count, Is.EqualTo(1)); }
public void OnGet_ArtistHrefIsNullOrTrimEmpty_ReturnsErrorResponseWithStatusCodeBadRequest(string artistHref) { var service = new ArtistAlbumRestService { LogFactory = A.Fake <ILogFactory>() }; var response = service.OnGet(new ArtistAlbumRequest { Territory = "se", ArtistHref = artistHref }); 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 ArtistAlbumRestService { LogFactory = A.Fake <ILogFactory>() }; var response = service.OnGet(new ArtistAlbumRequest { Territory = territory, ArtistHref = "abc" }); Assert.That(response, Is.TypeOf <ErrorResponse>()); Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest)); }
public void OnGet_RequestIsValidTerritoryIsNullValue_CallsArtistAlbumServiceGetAlbumsWithTerritoryIsNull() { var artistAlbumServiceFake = A.Fake <IArtistAlbumService>(); var service = new ArtistAlbumRestService { LogFactory = A.Fake <ILogFactory>(), ArtistAlbumService = artistAlbumServiceFake }; var response = service.OnGet(new ArtistAlbumRequest { Territory = "-", ArtistHref = "abc" }); A.CallTo(() => artistAlbumServiceFake.GetAlbums(null, "abc")).MustHaveHappened(Repeated.Exactly.Once); }
public void OnGet_ArtistAlbumServiceGetAlbumsThrowsException_ReturnsErrorResponseWithStatusCodeInternalServerError() { var artistAlbumServiceFake = A.Fake <IArtistAlbumService>(); A.CallTo(() => artistAlbumServiceFake.GetAlbums(A <string> .Ignored, A <string> .Ignored)).Throws(new Exception("foo")); var service = new ArtistAlbumRestService { LogFactory = A.Fake <ILogFactory>(), ArtistAlbumService = artistAlbumServiceFake }; var response = service.OnGet(new ArtistAlbumRequest { Territory = "se", ArtistHref = "abc" }); Assert.That(response, Is.TypeOf <ErrorResponse>()); Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.InternalServerError)); }