コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }