Exemple #1
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();
        }
        public async void GetAllAlbums_Returns_Valid_List_Of_Albums()
        {
            var pageNumber    = 1;
            var pageSize      = 10;
            var sortBy        = "name";
            var sortDirection = "asc";

            var fix             = new Fixture();
            var albumListResult = fix.Create <AlbumListResult>();

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

            var result = await ObjectUnderTest.GetAllAlbums(pageNumber, pageSize, sortBy, sortDirection);

            result.ShouldNotBeNull();
            result.ShouldBeEquivalentTo(albumListResult);
            For <IMediator>().Verify();
        }
Exemple #3
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();
        }