예제 #1
0
        public void OnGet_ArtistNameIsNullOrTrimEmpty_ReturnsErrorResponseWithStatusCodeBadRequest(string artistName)
        {
            var service = new SimilarArtistRestService()
            {
                LogFactory = A.Fake <ILogFactory>()
            };

            var response = service.OnGet(new SimilarArtistRequest {
                ArtistName = artistName
            });

            Assert.That(response, Is.TypeOf <ErrorResponse>());
            Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.BadRequest));
        }
예제 #2
0
        public void OnGet_RequestIsValid_CallsSimilarArtistServiceGetAlbums()
        {
            var similarArtistServiceFake = A.Fake <ISimilarArtistService>();

            var service = new SimilarArtistRestService {
                LogFactory           = A.Fake <ILogFactory>(),
                SimilarArtistService = similarArtistServiceFake
            };

            var response = service.OnGet(new SimilarArtistRequest {
                ArtistName = "abc"
            });

            A.CallTo(() => similarArtistServiceFake.GetArtists("abc")).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #3
0
        public void OnGet_ArtistServiceGetSimilarArtistsThrowsException_ReturnsErrorResponseWithStatusCodeInternalServerError()
        {
            var similarArtistServiceFake = A.Fake <ISimilarArtistService>();

            A.CallTo(() => similarArtistServiceFake.GetArtists(A <string> .Ignored)).Throws(new Exception("foo"));

            var service = new SimilarArtistRestService {
                LogFactory           = A.Fake <ILogFactory>(),
                SimilarArtistService = similarArtistServiceFake
            };

            var response = service.OnGet(new SimilarArtistRequest {
                ArtistName = "abc"
            });

            Assert.That(response, Is.TypeOf <ErrorResponse>());
            Assert.That(((ErrorResponse)response).Status.StatusCode, Is.EqualTo(StatusCode.InternalServerError));
        }
예제 #4
0
        public void OnGet_ArtistServiceGetSimilarArtistsReturnsArtists_ReturnsSimilarArtistResponse()
        {
            var similarArtistServiceFake = A.Fake <ISimilarArtistService>();

            A.CallTo(() => similarArtistServiceFake.GetArtists(A <string> .Ignored)).Returns(new List <IArtist> {
                A.Fake <IArtist>()
            });

            var service = new SimilarArtistRestService {
                LogFactory           = A.Fake <ILogFactory>(),
                SimilarArtistService = similarArtistServiceFake
            };

            var response = service.OnGet(new SimilarArtistRequest {
                ArtistName = "abc"
            });

            Assert.That(response, Is.TypeOf <SimilarArtistResponse>());
            var similarArtistResponse = (SimilarArtistResponse)response;

            Assert.That(similarArtistResponse.Info.ArtistName, Is.EqualTo("abc"));
            Assert.That(similarArtistResponse.Artists.Count, Is.EqualTo(1));
        }