예제 #1
0
        public void CanFakeMyHttpClient()
        {
            // Arrange
            var fakeHttpClientWrapper = A.Fake <IHttpClientWrapper>();
            var TestResults           = "Fake Response Data for Test";

            A.CallTo(() => fakeHttpClientWrapper.Get(A <string> .That.Matches(s => s == Config.ApiEndpoint)))
            .Returns(Task.FromResult(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(TestResults)
            }));
            var client = new ClientClass(new ServiceClass(fakeHttpClientWrapper));

            // Act
            var result = client.GetStringFromApi();

            // Assert
            Assert.AreEqual(TestResults, result);
        }