Esempio n. 1
0
        static void Main(string[] args)
        {
            var analyzer = new SiteAnalyzer(Client);
            var size     = analyzer.GetContentSize("http://microsoft.com").Result;

            Console.WriteLine($"Size: {size}");
        }
Esempio n. 2
0
        public async void GetContentSizeReturnsCorrectLength()
        {
            // Arrange
            const string testContent        = "test content";
            var          mockMessageHandler = new Mock <HttpMessageHandler>();

            mockMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(testContent)
            });
            var underTest = new SiteAnalyzer(new HttpClient(mockMessageHandler.Object));

            // Act
            var result = await underTest.GetContentSize("http://anyurl");

            // Assert
            Assert.Equal(testContent.Length, result);
        }