Ejemplo n.º 1
0
        public async void Create_Album_ById_0_Returns_Album()
        {
            var fix         = new Fixture();
            var inputAlbum  = fix.Create <AlbumModel>();
            var zeroAlbumId = 0;

            inputAlbum.Id = zeroAlbumId;

            var outputAlbum = fix.Create <AlbumModel>();

            outputAlbum.Id = 4;

            For <IAlbumService>()
            .Setup(s => s.CreateAlbum(It.IsAny <AlbumModel>()))
            .Returns(Task.FromResult(outputAlbum)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.CreateAlbum(inputAlbum);

            var albumId = result as OkNegotiatedContentResult <AlbumModel>;

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <BadRequestResult>();
            result.ShouldNotBeOfType <NotFoundResult>();
            result.ShouldBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            albumId.Content.Id.ShouldBe(outputAlbum.Id);
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 2
0
        public void appropriate_result_is_returned()
        {
            _result.ShouldBeOfType <OkNegotiatedContentResult <CustomerEntity> >();
            var castedResult = _result as OkNegotiatedContentResult <CustomerEntity>;

            castedResult.ShouldNotBe(null);
            castedResult.Content.Id.ShouldBe(_customer.Id);
            castedResult.Content.Name.ShouldBe(_customer.Name);
        }
Ejemplo n.º 3
0
        public async void Delete_Album_ById_0_Returns_Bad_Request()
        {
            var zeroAlbumId          = 0;
            IHttpActionResult result = await ObjectUnderTest.DelteAlbum(zeroAlbumId);

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <OkNegotiatedContentResult <bool> >();
            result.ShouldBeOfType <BadRequestResult>();
        }
Ejemplo n.º 4
0
        public async void Get_Album_ById_0_Returns_Bad_Request()
        {
            var zeroAlbumId = 0;

            IHttpActionResult model = await ObjectUnderTest.GetAlbumById(zeroAlbumId);

            model.ShouldNotBeNull();
            model.ShouldBeOfType <BadRequestResult>();
            model.ShouldNotBeOfType <OkResult>();
        }
Ejemplo n.º 5
0
        public async void Update_Album_ById_0_Returns_Bad_Request()
        {
            var fix   = new Fixture();
            var album = fix.Create <AlbumModel>();

            album.Id = 0;

            IHttpActionResult model = await ObjectUnderTest.UpdateAlbum(album);

            model.ShouldNotBeNull();
            model.ShouldNotBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            model.ShouldBeOfType <BadRequestResult>();
        }
Ejemplo n.º 6
0
        public async Task ShouldReturnBadReQuestIfDuplicateTelemetryPosted()
        {
            using (new FakeHttpContext.FakeHttpContext())
            {
                IHttpActionResult result = await _controller.Post(_dto);

                IHttpActionResult res2 = await _controller.Post(_dto2);

                IHttpActionResult res3 = await _controller.Post(_dto2);

                var createdResult  = result as CreatedAtRouteNegotiatedContentResult <Telemetry>;
                var createdResult2 = res2 as CreatedAtRouteNegotiatedContentResult <Telemetry>;



                res3.ShouldBeOfType <BadRequestErrorMessageResult>();
                BadRequestErrorMessageResult doubeAddResult = res3.ShouldBeOfType <BadRequestErrorMessageResult>();

                createdResult.ShouldNotBeNull();
                createdResult2.ShouldNotBeNull();

                doubeAddResult.Message.ShouldBe("Duplicate not allowed. A lap can track a car at most once");
            }
        }
Ejemplo n.º 7
0
        public async void Get_Album_ById_Non_0_Not_Found_Returns_Not_Found()
        {
            var nonZeroAlbumId = 2;

            For <IAlbumService>()
            .Setup(s => s.GetAlbum(It.IsAny <int>()))
            .Returns(Task.FromResult <AlbumModel>(null)).Verifiable();

            IHttpActionResult model = await ObjectUnderTest.GetAlbumById(nonZeroAlbumId);

            model.ShouldNotBeNull();
            model.ShouldNotBeOfType <BadRequestResult>();
            model.ShouldNotBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            model.ShouldBeOfType <NotFoundResult>();
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 8
0
        public async void Get_Albums_When_None_Found_Returns_Not_Found()
        {
            var fix = new Fixture();
            var expectedResponse = fix.Create <AlbumListResult>();

            expectedResponse.Total  = 0;
            expectedResponse.Albums = null;

            For <IAlbumService>()
            .Setup(s => s.GetAllAlbums(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <AlbumListResult>(expectedResponse)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.GetAllAlbums(1, 10);

            result.ShouldNotBeNull();
            result.ShouldBeOfType <NotFoundResult>();
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 9
0
        public async void Create_Album_ById_0_When_NULL_Returns_ISE()
        {
            var fix         = new Fixture();
            var album       = fix.Create <AlbumModel>();
            var zeroAlbumId = 0;

            album.Id = zeroAlbumId;

            For <IAlbumService>()
            .Setup(s => s.CreateAlbum(It.IsAny <AlbumModel>()))
            .Returns(Task.FromResult <AlbumModel>(null)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.CreateAlbum(album);

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <BadRequestResult>();
            result.ShouldNotBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            result.ShouldBeOfType <ExceptionResult>();
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 10
0
        public async void Get_Albums_When_Found_Returns_Results()
        {
            var fix = new Fixture();
            var expectedResponse = fix.Create <AlbumListResult>();

            expectedResponse.Total  = 20;
            expectedResponse.Albums = fix.Create <List <AlbumModel> >();

            For <IAlbumService>()
            .Setup(s => s.GetAllAlbums(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <AlbumListResult>(expectedResponse)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.GetAllAlbums(1, 10);

            var response = result as OkNegotiatedContentResult <AlbumListResult>;

            result.ShouldNotBeNull();
            result.ShouldBeOfType <OkNegotiatedContentResult <AlbumListResult> >();
            response.Content.Total.ShouldBe(expectedResponse.Total);
            response.Content.Albums.ShouldBeEquivalentTo(expectedResponse.Albums);
            For <IAlbumService>().Verify();
        }
Ejemplo n.º 11
0
        public async void Delete_Album_ById_Non_0_Does_Not_Delete_Returns_False()
        {
            var fix         = new Fixture();
            var album       = fix.Create <AlbumModel>();
            var zeroAlbumId = 4;

            album.Id = zeroAlbumId;

            For <IAlbumService>()
            .Setup(s => s.DeleteAlbum(It.IsAny <int>()))
            .Returns(Task.FromResult <bool>(false)).Verifiable();

            IHttpActionResult result = await ObjectUnderTest.DelteAlbum(album.Id);

            var response = result as OkNegotiatedContentResult <bool>;

            result.ShouldNotBeNull();
            result.ShouldNotBeOfType <BadRequestResult>();
            result.ShouldBeOfType <OkNegotiatedContentResult <bool> >();
            response.Content.ShouldBeFalse();
            For <IAlbumService>().Verify();
        }