Example #1
0
        public async Task Index_Send_Request()
        {
            var result = await controller.Index(Guid.NewGuid()) as ViewResult;

            A.CallTo(() => mediator.SendAsync(A <GetMovementRulesSummary> .Ignored))
            .MustHaveHappened(Repeated.Exactly.Once);

            A.CallTo(() => mediator.SendAsync(A <GetShipmentInfo> .Ignored))
            .MustHaveHappened(Repeated.Exactly.Once);

            Assert.NotNull(result);
            Assert.True(result.ViewName == "Index");
        }
        public void Index_TestIndexView_ViewResult()
        {
            //Arrange
            CreateController controller = new CreateController();

            //Act
            ViewResult result = controller.Index() as ViewResult;

            //Assert
            Assert.AreEqual("Index", result.ViewName);
        }
        public void Forum_CreateController_Index_Post_ShouldCallRedirectToActionWithCorrectRouteParams()
        {
            //Arrange
            var data             = new Mock <IUowData>();
            var threadRepository = new Mock <IRepository <Thread> >();
            var mappingService   = new Mock <IMappingService>();

            data.Setup(d => d.Threads).Returns(threadRepository.Object);

            var claim = new Claim("test", "asd-123");

            var identity = new Mock <ClaimsIdentity>();

            identity.Setup(i => i.FindFirst(It.IsAny <string>())).Returns(claim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity.Object);

            var context = new Mock <ControllerContext>();

            context.Setup(c => c.HttpContext.User).Returns(principal.Object);

            mappingService.Setup(m => m.Map <Thread>(It.IsAny <CreateThreadViewModel>())).Returns(new Thread()
            {
                Id = 3
            });

            CreateController controller = new CreateController(data.Object, mappingService.Object)
            {
                ControllerContext = context.Object
            };

            var thread = new CreateThreadViewModel();

            //Act
            RedirectToRouteResult redirectResult = controller.Index(thread) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual(3, redirectResult.RouteValues["id"]);
        }
        public void Forum_CreateController_Index_Post_ShouldAddInstanceOfAThread()
        {
            //Arrange
            var data           = new Mock <IUowData>();
            var mappingService = new Mock <IMappingService>();

            var threadRepository = new Mock <IRepository <Thread> >();

            data.Setup(d => d.Threads).Returns(threadRepository.Object);

            var claim = new Claim("test", "asd-123");

            var identity = new Mock <ClaimsIdentity>();

            identity.Setup(i => i.FindFirst(It.IsAny <string>())).Returns(claim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity.Object);

            var context = new Mock <ControllerContext>();

            context.Setup(c => c.HttpContext.User).Returns(principal.Object);

            mappingService.Setup(m => m.Map <Thread>(It.IsAny <CreateThreadViewModel>())).Returns(new Thread());

            CreateController controller = new CreateController(data.Object, mappingService.Object)
            {
                ControllerContext = context.Object
            };

            var thread = new CreateThreadViewModel();

            //Act
            var result = controller.Index(thread) as ViewResult;

            //Assert
            threadRepository.Verify(d => d.Add(It.IsAny <Thread>()));
        }