Ejemplo n.º 1
0
        public void SetUp()
        {
            _precautionService     = new Mock <IPrecautionService>();
            _userPrecautionService = new Mock <IUserPrecautionService>();
            var store = new Mock <IUserStore <User> >();

            _userManager = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null);

            _PrecautionController = new PrecautionController(
                _precautionService.Object,
                _userPrecautionService.Object,
                _userManager.Object
                );
        }
        public async Task DeletePrecaution_ReturnsNoContentResult()
        {
            //Arrange
            _PrecautionController.ControllerContext = _context;
            _precautionService
            .Setup(x => x.DeletePrecautionAsync(It.IsAny <int>(), It.IsAny <User>()));
            PrecautionController precautionController = _PrecautionController;
            //Act
            var result = await precautionController.DeletePrecaution(It.IsAny <int>());

            //Assert
            _precautionService.Verify();
            Assert.IsNotNull(result);
            Assert.IsInstanceOf <NoContentResult>(result);
        }
        public async Task GetPrecaution_PrecautionById_ReturnsNotFoundResult()
        {
            //Arrange
            _precautionService
            .Setup(x => x.GetPrecautionAsync(It.IsAny <int>()))
            .ReturnsAsync((PrecautionDTO)null);
            PrecautionController precautionController = _PrecautionController;
            //Act
            var result = await precautionController.GetPrecaution(It.IsAny <int>());

            //Assert
            _precautionService.Verify();
            Assert.IsNotNull(result);
            Assert.IsInstanceOf <NotFoundResult>(result);
        }
        public void SetUp()
        {
            _precautionService     = new Mock <IPrecautionService>();
            _userPrecautionService = new Mock <IUserPrecautionService>();
            var store = new Mock <IUserStore <User> >();

            _userManager = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null);
            _httpContext = new Mock <HttpContext>();
            _httpContext
            .Setup(m => m.User.IsInRole(Roles.Admin))
            .Returns(true);

            _PrecautionController = new PrecautionController(
                _precautionService.Object,
                _userPrecautionService.Object,
                _userManager.Object
                );
            _context = new ControllerContext(
                new ActionContext(
                    _httpContext.Object, new RouteData(),
                    new ControllerActionDescriptor()));
        }