public async Task WhenValidUrlPassed_ToRssFeedWebApi_ReturnSuccessResultWithFeeds() { //Arrage var rssFeed = JsonConvert.SerializeObject(TestDataGenerator.CreateFakeSuccessRssFeedModel()); var responseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(rssFeed, System.Text.Encoding.UTF8, "application/json"), }; var messageHandler = new FakeHttpMessageHandler(responseMessage); var _httpClientManager = new HttpClientManager(messageHandler); //Act var response = await _httpClientManager.GetRssFeeds(); // Assert Assert.IsTrue(response != null && response.Feeds != null); Assert.IsTrue(response.Feeds.Count > 0); Assert.IsTrue(response.Result != null && response.Result.ResultStatus == ResultStatus.Success); }
public async Task WhenSuccessfulHttpClientInvoked_ShouldReturn_SuccessResult() { //Arrage var mockHttpClientManager = new Mock <IHttpClientManager>(); mockHttpClientManager.Setup(m => m.GetRssFeeds()).Returns(Task.FromResult(TestDataGenerator.CreateFakeSuccessRssFeedModel())); var newsFeedManager = new NewsFeedManager(mockHttpClientManager.Object); //Act var response = await newsFeedManager.GetRssFeeds(); // Assert Assert.IsTrue(response != null && response.Feeds != null); Assert.IsTrue(response.Feeds.Count > 0); Assert.IsTrue(response.Result != null && response.Result.ResultStatus == ResultStatus.Success); }
public async Task WhenValid_RssFeedCallInvoked_ReturnSuccessResult() { // Arrange var mockedNewsFeedManager = new Mock <INewsFeedManager>(); NewsController newController = new NewsController(mockedNewsFeedManager.Object); mockedNewsFeedManager.Setup(m => m.GetRssFeeds()).Returns(Task.FromResult(TestDataGenerator.CreateFakeSuccessRssFeedModel())); // Act var result = await newController.Index() as ViewResult; // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Model != null); var model = (RssFeedViewModel)result.Model; Assert.IsTrue(model != null && model.Feeds != null && model.Feeds.Count > 0); Assert.IsTrue(model != null && model.Result != null && model.Result.ResultStatus == ResultStatus.Success); }