Ejemplo n.º 1
0
        public void Test_GetPosts()
        {
            // Arrange
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(request =>
                                                                                request.RequestUri.ToString() == "http://baseurl.com/explore/tags/tag/?__a=1"),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{posts:[{Title: 'Title'}]}")
            });
            var httpClient = new HttpClient(handler.Object);

            var config = new Mock <IApiConfig>();

            config.Setup(x => x.BaseUrl).Returns("http://baseurl.com");

            var service = new PostService7(httpClient, config.Object, MapperContext.Map, new Mock <IFeatureConfig>().Object);

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

            // Assert
            new[] { new PostView {
                        Name = "Title"
                    } }.Should().BeEquivalentTo(posts);
        }
Ejemplo n.º 2
0
        public void Test_GetPosts()
        {
            var service = new PostService7(_httpClient, _config, MapperContext.Map, new Mock <IFeatureConfig>().Object);

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

            new[] { new PostView {
                        Name = "Title"
                    } }.Should().BeEquivalentTo(posts);
        }