Example #1
0
        public async Task Returns_A_Recording()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.OkResponse);
            var sut           = new XenoCantoService(clientFactory);

            var result = await sut.GetSpeciesRecordings("Branta canadensis");

            Assert.IsType <List <RecordingViewModel> >(result);
        }
Example #2
0
        public async Task Returns_400_Result_When_Missing_Location()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.NotFoundResponse);
            var service       = new XenoCantoService(clientFactory);
            var sut           = new RecordingController(new NullLogger <RecordingController>(), service);

            var result = await sut.GetRecordingsAsync(String.Empty) as ObjectResult;

            Assert.Equal(400, result.StatusCode);
        }
Example #3
0
        public async Task Returns_XenoCantoException_On_XenoCantoInternalError()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.InternalErrorResponse,
                                                                     HttpStatusCode.InternalServerError);
            var sut = new XenoCantoService(clientFactory);

            var result = await Assert.ThrowsAsync <XenoCantoException>(() => sut.GetSpeciesRecordings("Branta canadensis"));

            Assert.Equal(500, (int)result.StatusCode);
        }
Example #4
0
        public async Task Returns_XenoCantoException_When_Called_With_Bad_Argument()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.NotFoundResponse,
                                                                     HttpStatusCode.NotFound);
            var sut = new XenoCantoService(clientFactory);

            var result = await Assert.ThrowsAsync <XenoCantoException>(() => sut.GetSpeciesRecordings("dnifihurvbfvije"));

            Assert.Equal(404, (int)result.StatusCode);
        }
Example #5
0
        public async Task Returns_Expected_Values_From_the_Api()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.OkResponse);
            var sut           = new XenoCantoService(clientFactory);

            var result = await sut.GetSpeciesRecordings("Branta canadensis");

            Assert.Equal("//a/b/c/d/testFileName.mp3", result[0].Url);
            Assert.Equal(0, result[0].Id);
        }
Example #6
0
        public async Task Returns_OkResult_With_Recording()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.OkResponse);
            var service       = new XenoCantoService(clientFactory);
            var sut           = new RecordingController(new NullLogger <RecordingController>(), service);

            var result = await sut.GetRecordingsAsync("Branta canadensis") as OkObjectResult;

            Assert.IsType <List <RecordingViewModel> >(result.Value);
            Assert.Equal(200, result.StatusCode);
        }
Example #7
0
        public async Task Returns_500_When_Api_Returns_Error()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.UnauthorizedResponse,
                                                                     HttpStatusCode.Unauthorized);
            var service = new XenoCantoService(clientFactory);
            var sut     = new RecordingController(new NullLogger <RecordingController>(), service);

            var result = await sut.GetRecordingsAsync("Rio de Janeiro") as ObjectResult;

            Assert.Contains("Error response from XenoCantoApi: Unauthorized", result.Value.ToString());
            Assert.Equal(500, result.StatusCode);
        }
Example #8
0
        public async Task Returns_BadRequestResult_When_Location_Not_Found()
        {
            var clientFactory = ClientBuilder.XenoCantoClientFactory(XenoCantoResponses.NotFoundResponse,
                                                                     HttpStatusCode.NotFound);
            var service = new XenoCantoService(clientFactory);
            var sut     = new RecordingController(new NullLogger <RecordingController>(), service);

            var result = await sut.GetRecordingsAsync("Westworld") as ObjectResult;

            Assert.Contains("not found", result.Value.ToString());
            Assert.Equal(400, result.StatusCode);
        }