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 async void Create_Album_ById_Non_0_Returns_Bad_Request()
        {
            var fix   = new Fixture();
            var album = fix.Create <AlbumModel>();

            album.Id = 2;

            IHttpActionResult model = await ObjectUnderTest.CreateAlbum(album);

            model.ShouldNotBeNull();
            model.ShouldNotBeOfType <OkNegotiatedContentResult <AlbumModel> >();
            model.ShouldBeOfType <BadRequestResult>();
        }
Ejemplo n.º 3
0
        public async void CreateAlbum_InValid_Request_Returns_False()
        {
            var zero         = 0;
            var fix          = new Fixture();
            var invalidAlbum = fix.Create <AlbumModel>();

            invalidAlbum.Id = zero;

            For <IMediator>()
            .Setup(m => m.Send(It.IsAny <CreateAlbumCommand>(), default(CancellationToken)))
            .Returns(Task.FromResult(zero)).Verifiable();

            var result = await ObjectUnderTest.CreateAlbum(invalidAlbum);

            result.ShouldNotBeNull();
            result.Id.ShouldBe(zero);
            For <IMediator>().Verify();
        }
Ejemplo n.º 4
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();
        }