Ejemplo n.º 1
0
            public async Task WhenNewsNotFoundReturnsNotFound()
            {
                MockNewsService.Setup(ns => ns.FindNewsByIdAsync(It.IsAny <int>())).ReturnsAsync((Data.Models.News)null);

                var result = await Controller.SaveNews(1, new AddNewsRequest());

                Assert.IsInstanceOfType(result, typeof(NotFoundResult));
            }
Ejemplo n.º 2
0
            public async Task WhenErrorSavingReturnsErrorResponse()
            {
                MockNewsService.Setup(ns => ns.FindNewsByIdAsync(It.IsAny <int>())).ReturnsAsync(new Data.Models.News());

                var result = await Controller.SaveNews(1, new AddNewsRequest());

                var response = TestUtils.GetResponseFromResult <ApiResponse>(result);

                Assert.IsFalse(response.Success);
            }
Ejemplo n.º 3
0
            public async Task WhenAddNewsFailsReturnsFailureResponse()
            {
                MockUserService.Setup(us => us.GetUserFromUsernameAsync(It.IsAny <string>())).ReturnsAsync(TestUtils.GetRandomUser());
                MockNewsService.Setup(ns => ns.AddNewsAsync(It.IsAny <Data.Models.News>())).ReturnsAsync(false);

                var result = await Controller.AddNews(new AddNewsRequest());

                var response = TestUtils.GetResponseFromResult <ApiResponse>(result);

                Assert.IsFalse(response.Success);
            }
Ejemplo n.º 4
0
            public async Task WhenAddNewsSucceedsReturnsSuccessResponse()
            {
                MockUserService.Setup(us => us.GetUserFromUsernameAsync(It.IsAny <string>())).ReturnsAsync(TestUtils.GetRandomUser());
                MockNewsService.Setup(ns => ns.AddNewsAsync(It.IsAny <Data.Models.News>())).ReturnsAsync(true);

                var result = await Controller.AddNews(new AddNewsRequest { Text = "Test News" });

                var response = TestUtils.GetResponseFromResult <AddNewsResponse>(result);

                Assert.IsTrue(response.Success);
                Assert.AreEqual("Test News", response.NewsItem.Text);
            }
Ejemplo n.º 5
0
            public async Task WhenCalledReturnsNewsResponse()
            {
                MockNewsService.Setup(ns => ns.GetAllNewsAsync()).ReturnsAsync(new List <Data.Models.News> {
                    new Data.Models.News()
                });

                var result = await Controller.GetAllNews();

                var response = TestUtils.GetResponseFromResult <GetNewsResponse>(result);

                Assert.IsTrue(response.Success);
                Assert.AreEqual(1, response.News.Count);
            }
Ejemplo n.º 6
0
            public async Task WhenSaveSucceedsReturnsSuccessResponse()
            {
                MockNewsService.Setup(ns => ns.FindNewsByIdAsync(It.IsAny <int>())).ReturnsAsync(new Data.Models.News {
                    Id = 1
                });
                MockNewsService.Setup(ns => ns.UpdateNewsAsync(It.IsAny <Data.Models.News>())).ReturnsAsync(true);

                var result = await Controller.SaveNews(1, new AddNewsRequest());

                var response = TestUtils.GetResponseFromResult <AddNewsResponse>(result);

                Assert.IsTrue(response.Success);
                Assert.AreEqual(1, response.NewsItem.Id);
            }