Beispiel #1
0
        public void OnGet_PageIsLessThanOne_ReturnsErrorResponseWithStatusCodeBadRequest()
        {
            var service = new LastAlbumRestService {
                LogFactory = A.Fake <ILogFactory>()
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = "se", Genre = null, Page = 0
            });

            Assert.That(response, Is.TypeOf <ErrorResponse>());
            Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest));
        }
Beispiel #2
0
        public void OnGet_TerritoryInvalidLength_ReturnsErrorResponseWithStatusCodeBadRequest(string territory)
        {
            var service = new LastAlbumRestService {
                LogFactory = A.Fake <ILogFactory>()
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = territory, Genre = null
            });

            Assert.That(response, Is.TypeOf <ErrorResponse>());
            Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest));
        }
Beispiel #3
0
        public void OnGet_RequestIsValidGenreIsNotNull_CallsLastAlbumServiceGetAlbumsByGenre()
        {
            var lastLastAlbumServiceFake = A.Fake <ILastAlbumService>();

            var service = new LastAlbumRestService {
                LogFactory       = A.Fake <ILogFactory>(),
                LastAlbumService = lastLastAlbumServiceFake
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = "se", Genre = 2
            });

            A.CallTo(() => lastLastAlbumServiceFake.GetAlbumsByGenre("se", 2)).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #4
0
        public void OnGet_RequestIsValidGenreIsNullTerritoryIsNullValue_CallsLastAlbumServiceGetAlbumsWithTerritoryIsNull()
        {
            var lastLastAlbumServiceFake = A.Fake <ILastAlbumService>();

            var service = new LastAlbumRestService {
                LogFactory       = A.Fake <ILogFactory>(),
                LastAlbumService = lastLastAlbumServiceFake
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = "-", Genre = null
            });

            A.CallTo(() => lastLastAlbumServiceFake.GetAlbums(null, 1)).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #5
0
        public void OnGet_LastAlbumServiceGetAlbumsByGenreThrowsException_ReturnsErrorResponseWithStatusCodeInternalServerError()
        {
            var lastLastAlbumServiceFake = A.Fake <ILastAlbumService>();

            A.CallTo(() => lastLastAlbumServiceFake.GetAlbumsByGenre(A <string> .Ignored, A <int> .Ignored)).Throws(new Exception("foo"));

            var service = new LastAlbumRestService {
                LogFactory       = A.Fake <ILogFactory>(),
                LastAlbumService = lastLastAlbumServiceFake
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = "se", Genre = 2
            });

            Assert.That(response, Is.TypeOf <ErrorResponse>());
            Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.InternalServerError));
        }
Beispiel #6
0
        public void OnGet_LastAlbumServiceGetAlbumsByGenreReturnsAlbums_ReturnsAlbumResponse()
        {
            var lastLastAlbumServiceFake = A.Fake <ILastAlbumService>();

            A.CallTo(() => lastLastAlbumServiceFake.GetAlbumsByGenre(A <string> .Ignored, A <int> .Ignored)).Returns(new List <IAlbum> {
                A.Fake <Album>()
            });

            var service = new LastAlbumRestService {
                LogFactory       = A.Fake <ILogFactory>(),
                LastAlbumService = lastLastAlbumServiceFake
            };

            var response = service.OnGet(new LastAlbumRequest {
                Territory = "se", Genre = 2
            });

            Assert.That(response, Is.TypeOf <LastAlbumResponse>());
            var albumResponse = (LastAlbumResponse)response;

            Assert.That(albumResponse.Info.Territory, Is.EqualTo("se"));
            Assert.That(albumResponse.Info.Genre, Is.EqualTo(2));
            Assert.That(albumResponse.Albums.Count, Is.EqualTo(1));
        }