Exemple #1
0
        public void CreateNews_IncorrectData_ShouldReturnBadRequest()
        {
            var mockContext = new Mock <INewsData>();

            mockContext.Setup(m => m.News)
            .Returns(this.mocks.NewsStoriesRepositoryMock.Object);

            var newsStoriesController = new NewsStoriesController(mockContext.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var createNewsStoryResponse = newsStoriesController.CreateNewsStory(new NewsStoryBindingModel()
            {
                Title       = "",
                Content     = "TestNewsStory20",
                PublishDate = DateTime.Now
            }).ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, createNewsStoryResponse.StatusCode);
        }
Exemple #2
0
        public void CreateNews_CorrectData_ShouldCreateAndReturnNewsStory()
        {
            var mockContext = new Mock <INewsData>();

            mockContext.Setup(m => m.News)
            .Returns(this.mocks.NewsStoriesRepositoryMock.Object);

            this.mocks.NewsStoriesRepositoryMock.Setup(m => m.Add(It.IsAny <NewsStory>()))
            .Callback((NewsStory newsStory) => this.mocks.newsStories.Add(newsStory));

            var newsStoriesController = new NewsStoriesController(mockContext.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var expectedNewsStory = new NewsStoryDTO()
            {
                Title       = "TestNewsStory20",
                Content     = "TestNewsStory20",
                PublishDate = DateTime.Now
            };

            var createNewsStoryResponse = newsStoriesController.CreateNewsStory(new NewsStoryBindingModel()
            {
                Title       = "TestNewsStory20",
                Content     = "TestNewsStory20",
                PublishDate = DateTime.Now
            }).ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(HttpStatusCode.Created, createNewsStoryResponse.StatusCode);

            var createdNewsStory = createNewsStoryResponse.Content.ReadAsAsync <NewsStoryDTO>().Result;

            Assert.AreEqual(expectedNewsStory, createdNewsStory);
        }