Пример #1
0
        public void Test_GetPosts()
        {
            var restClient = new Mock <IRestClient>();

            restClient
            .Setup(x => x.Execute <GetPostResponseFull>(
                       It.Is <IRestRequest>(request =>
                                            request.Resource == "baseUrl/explore/tags/tag/"),
                       Method.GET))
            .Returns(
                new RestResponse <GetPostResponseFull>
            {
                Data = new GetPostResponseFull
                {
                    Posts = new[] { new PostFull {
                                        Title = "Title"
                                    }, }
                }
            });

            var config = new Mock <IApiConfig>();

            config.Setup(x => x.BaseUrl).Returns("baseUrl");

            var service = new PostService5(restClient.Object, config.Object,
                                           MapperContext.Map);

            var posts = service.GetPosts("tag");

            new[] { new PostView {
                        Name = "Title"
                    } }.Should().BeEquivalentTo(posts);
        }
Пример #2
0
        public void Test_GetCount_WhenHasDeletedRecords_CountOnlyActive()
        {
            var restClient = new Mock <IRestClient>();

            restClient
            .Setup(x => x.Execute <GetPostResponseFull>(
                       It.Is <IRestRequest>(request =>
                                            request.Resource == "baseUrl/explore/tags/tag/"),
                       Method.GET))
            .Returns(
                new RestResponse <GetPostResponseFull>
            {
                Data = new GetPostResponseFull
                {
                    Posts = new[] { new PostFull(), new PostFull {
                                        IsDeleted = true
                                    }, }
                }
            });

            var config = new Mock <IApiConfig>();

            config.Setup(x => x.BaseUrl).Returns("baseUrl");

            var service = new PostService5(restClient.Object, config.Object, MapperContext.Map);

            var postCount = service.GetPostsCount("tag");

            Assert.AreEqual(1, postCount);
        }