Exemple #1
0
        public async Task Should_return_none_with_invalid_id()
        {
            var fixture = new Fixture();

            var index = 1;

            Post Create(int id)
            {
                var post = fixture.Build <Post>().Without(e => e.Id).Create();

                post.Id = index++;
                return(post);
            };

            var posts_result = Enumerable.Range(0, 3).Select(Create).ToArray();

            var rssReader = A.Fake <IRssPostReader>();

            A.CallTo(() => rssReader.ReadPostsAsync(A <string> ._, A <DateTime> ._)).Returns(posts_result);

            var repository = new PostsRepository(rssReader, DateTime.MinValue, fixture.Create <string>());

            var somePost = await repository.GetPost(999);

            somePost.IsNone.Should().BeTrue();
        }
Exemple #2
0
        public async Task Should_return_some_with_valid_path()
        {
            var fixture = new Fixture();

            Post Create(string path)
            {
                var post = fixture.Build <Post>().Without(e => e.Path).Create();

                post.Path = path;
                return(post);
            };

            var posts_result = new[] {
                Create("p1"),
                Create("p2"),
                Create("p3"),
            };

            var rssReader = A.Fake <IRssPostReader>();

            A.CallTo(() => rssReader.ReadPostsAsync(A <string> ._, A <DateTime> ._)).Returns(posts_result);


            var repository = new PostsRepository(rssReader, DateTime.MinValue, fixture.Create <string>());

            var somePost = await repository.GetPost("p2");

            somePost.IsSome.Should().BeTrue();

            somePost.Some(e => e.Should().BeSameAs(posts_result[1]));
        }
Exemple #3
0
 public ActionResult GetPost([FromRoute] string id)
 {
     try
     {
         var posts = postsRepository.GetPost(id)
                     .Select(p => new PostDto(p, albumsRepository.GetAlbumAttachment(p.AlbumId))).ToArray();
         var response = new PostsResponse(posts, postsRepository.PostsCount);
         return(new JsonResult(response));
     }
     catch (Exception x)
     {
         return(new ContentResult
         {
             Content = x.ToString(),
             StatusCode = (int)HttpStatusCode.InternalServerError,
             ContentType = "text/plain"
         });
     }
 }