public void TestGetHotNewsReturns200Ok_WhenThereAreHotNews() { this.inputValidation.Setup(validation => validation.IsValidCity(It.IsAny <string>())).Returns(true); this.businessValidation.Setup(validation => validation.IsValidGetHotNews(this.hotNewsStorageMock.Object, It.IsAny <string>(), It.IsAny <DateTime>())).Returns(Task.FromResult(true)); this.hotNewsStorageMock.Setup(storage => storage.ListNews(It.IsAny <string>(), It.IsAny <DateTime>())).Returns(Task.FromResult(this.GenerateNews())); var hotNewsController = new HotNewsController(this.hotNewsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, GOUriBuilder.BuildAbsoluteDiaryEntryUri(Scheme, Host, Port, City, Date)); request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteDiaryEntryUri(Scheme, Host, Port, City, Date)); hotNewsController.ConfigureForTesting(request, "GetHotNews", new HttpRoute(GOUriBuilder.GetHotNewsTemplate)); HttpResponseMessage response = hotNewsController.Get(City).Result; HttpContent content = response.Content; string jsonContent = content.ReadAsStringAsync().Result; var actualHotNews = JsonConvert.DeserializeObject <List <NewsREST> >(jsonContent); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(1, actualHotNews.Count); Assert.IsTrue(actualHotNews.First().Links.Any(link => string.Equals("self", link.Rel))); Assert.AreEqual(new Uri(GOUriBuilder.BuildAbsoluteNewsUri(Scheme, Host, Port, City, Date, News.Id.ToString())), actualHotNews.First().Links.First(link => string.Equals("self", link.Rel)).Href); Assert.IsTrue(actualHotNews.First().Links.Any(link => string.Equals("author", link.Rel))); Assert.AreEqual(new Uri(GOUriBuilder.BuildAbsoluteUserUri(Scheme, Host, Port, News.Author)), actualHotNews.First().Links.First(link => string.Equals("author", link.Rel)).Href); }
private void AssertGetFails(string url, string city, HttpStatusCode resultCode) { HotNewsController hotNewsController = new HotNewsController(this.hotNewsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object); hotNewsController.ConfigureForTesting(HttpMethod.Get, url, "GetHotNews", new HttpRoute(GOUriBuilder.GetUserTemplate)); HttpResponseMessage response = hotNewsController.Get(city).Result; Assert.AreEqual(resultCode, response.StatusCode); this.hotNewsStorageMock.Verify(storage => storage.ListNews(It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never()); }