Esempio n. 1
0
        public void TestGetNewsReturns200OkWhenTheNewsIsInTheDatabase()
        {
            this.businessValidation.Setup(validation => validation.IsValidGetNews(this.newsStorageMock.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true));
            this.newsStorageMock.Setup(storage => storage.GetNews(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(News.ToNewsBll(Id, DefaultNews, City, DefaultUser.Nickname, DateTime.Parse(Date))));

            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            var request = new HttpRequestMessage(HttpMethod.Get, GOUriBuilder.BuildAbsoluteNewsUri(Scheme, Host, Port, City, Date, Id.ToString()));

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteNewsUri(Scheme, Host, Port, City, Date, Id.ToString()));

            newsController.ConfigureForTesting(request, "ListNews", new HttpRoute(GOUriBuilder.GetNewsTemplate));

            HttpResponseMessage response = newsController.Get(City, Date, Id.ToString()).Result;

            HttpContent content     = response.Content;
            string      jsonContent = content.ReadAsStringAsync().Result;
            var         actualNews  = JsonConvert.DeserializeObject <NewsREST>(jsonContent);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsTrue(new NewsCompleteEqualityComparer().Equals(DefaultNews, NewsREST.ToNews(actualNews)));
            Assert.IsTrue(actualNews.Links.Any(link => string.Equals("self", link.Rel)));
            Assert.AreEqual(new Uri(GOUriBuilder.BuildAbsoluteNewsUri(Scheme, Host, Port, City, Date, Id.ToString())), actualNews.Links.First(link => string.Equals("self", link.Rel)).Href);
            Assert.IsTrue(actualNews.Links.Any(link => string.Equals("author", link.Rel)));
            Assert.AreEqual(new Uri(GOUriBuilder.BuildAbsoluteUserUri(Scheme, Host, Port, NewsControllerTest.DefaultUser.Nickname)), actualNews.Links.First(link => string.Equals("author", link.Rel)).Href);
        }
Esempio n. 2
0
        private void GetNewsFails(HttpStatusCode code)
        {
            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            newsController.ConfigureForTesting(HttpMethod.Get, string.Format("{0}/{1}/{2}/{3}", NewsUriRoot, City, Date, Id));

            HttpResponseMessage response = newsController.Get(City, Date, Id.ToString()).Result;

            Assert.AreEqual(code, response.StatusCode);
        }
Esempio n. 3
0
        private void DeleteNewsFails(HttpStatusCode code)
        {
            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            newsController.ConfigureForTesting(HttpMethod.Delete, string.Format("{0}/{1}/{2}/{3}", NewsUriRoot, City, Date, Id));
            newsController.User = new GenericPrincipal(new GenericIdentity(DefaultUser.Nickname), null);

            HttpResponseMessage response = newsController.Delete(City, Date, Id.ToString()).Result;

            Assert.AreEqual(code, response.StatusCode);
            this.newsStorageMock.Verify(storage => storage.DeleteNews(City, DateTime.Parse(Date), Id), Times.Never());
        }
Esempio n. 4
0
        private void PostNewsFails(HttpStatusCode code)
        {
            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            newsController.ConfigureForTesting(HttpMethod.Post, string.Format("{0}/{1}/{2}", NewsUriRoot, City, Date));
            newsController.User = new GenericPrincipal(new GenericIdentity(DefaultUser.Nickname), null);

            HttpResponseMessage response = newsController.Post(City, Date, DefaultNews).Result;

            Assert.AreEqual(code, response.StatusCode);
            this.newsStorageMock.Verify(storage => storage.AddNews(It.IsAny <NewsBll>()), Times.Never());
        }
Esempio n. 5
0
        public void TestDeleteNewsReturns204NoContentWhenDeletesUser()
        {
            this.businessValidation.Setup(validation => validation.IsValidGetNews(this.newsStorageMock.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true));
            this.businessValidation.Setup(validation => validation.IsValidModifyNews(this.newsStorageMock.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>())).Returns(Task.FromResult(true));

            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            newsController.ConfigureForTesting(HttpMethod.Delete, string.Format("{0}/{1}/{2}/{3}", NewsUriRoot, City, Date, Id));
            newsController.User = new GenericPrincipal(new GenericIdentity(DefaultUser.Nickname), null);

            HttpResponseMessage response = newsController.Delete(City, Date, Id.ToString()).Result;

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
            this.newsStorageMock.Verify(storage => storage.DeleteNews(City, DateTime.Parse(Date), Id), Times.Once());
        }
Esempio n. 6
0
        public void TestPostUserReturns200OkWhenCreatesNews()
        {
            this.inputValidation.Setup(validation => validation.IsValidNews(It.IsAny <News>())).Returns(true);
            this.businessValidation.Setup(validation => validation.IsValidCreateNews(this.newsStorageMock.Object, It.IsAny <News>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())).Returns(Task.FromResult(true));

            var newsController = new NewsController(this.newsStorageMock.Object, this.inputValidation.Object, this.businessValidation.Object);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, GOUriBuilder.BuildAbsoluteDiaryEntryUri(Scheme, Host, Port, City, Date));

            request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteDiaryEntryUri(Scheme, Host, Port, City, Date));

            newsController.ConfigureForTesting(request, "PostNews", new HttpRoute(GOUriBuilder.PostNewsTemplate));
            newsController.User = new GenericPrincipal(new GenericIdentity(DefaultUser.Nickname), null);

            HttpResponseMessage response = newsController.Post(City, Date, DefaultNews).Result;

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.IsTrue(new Uri(NewsUriRoot).IsBaseOf(response.Headers.Location));
            this.newsStorageMock.Verify(storage => storage.AddNews(It.IsAny <NewsBll>()), Times.Once());
        }