Ejemplo n.º 1
0
        public void TestGetIndexAwаrds()
        {
            var request = new Mock <HttpRequestBase>();
            var context = new Mock <HttpContextBase>();

            context.Setup(ctx => ctx.Request).Returns(request.Object);

            var awardsController = new AwardsController();

            awardsController.ControllerContext = new ControllerContext(context.Object, new RouteData(), awardsController);
            var result = awardsController.Index();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("Index", ((ViewResult)result).ViewName);
            Console.WriteLine("Страница со списком наград сформирована");
        }
Ejemplo n.º 2
0
        public void TestGetIndexAwаrdsAjax()
        {
            var request = new Mock <HttpRequestBase>();

            request.SetupGet(req => req.Headers).Returns(new WebHeaderCollection()
            {
                { "X-Requested-With", "XMLHttpRequest" }
            });
            var context = new Mock <HttpContextBase>();

            context.Setup(ctx => ctx.Request).Returns(request.Object);

            var awardsController = new AwardsController();

            awardsController.ControllerContext = new ControllerContext(context.Object, new RouteData(), awardsController);
            var result = awardsController.Index();

            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
            Assert.AreEqual("ListAwardsPartial", ((PartialViewResult)result).ViewName);
            Console.WriteLine("Частичное представление для страницы со списком наград сформировано");
        }
Ejemplo n.º 3
0
        //[Fact]
        public async Task AwardsControllerGetAwardsListTest()
        {
            var responses = _fixture.Create <ApiObject <AwardResponse> >();

            var awardsService = new Mock <AwardsService>(null);

            awardsService.Setup(c => c.GetAwardsAsync(It.IsAny <AwardRequest>())).ReturnsAsync(responses);

            AwardsController controller = new AwardsController(awardsService.Object);

            IActionResult actionResult = await controller.Index(null);

            var contentResult = actionResult as ObjectResult;

            Assert.NotNull(contentResult);

            var content = contentResult.Value as IReadOnlyList <Award>;

            Assert.NotNull(content);
            Assert.Equal(3, content.Count);
            Assert.Equal(responses.Values[0].Name, content[0].Name);
            //Assert.Equal(200, contentResult.StatusCode);
        }