public async void AddModuleContent_CalledWithValidModuleContent_ReturnsOk()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            var testId            = 1;
            var testModule        = new Module();
            var testModuleContent = new ModuleContentViewModel()
            {
                ModuleId = testId
            };

            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());
            unitOfWork.Modules.GetById(testId).Returns(testModule);
            unitOfWork.ModuleContents.GetLastModuleContentByModuleId(testModuleContent.ModuleId).Returns(1);

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.AddModuleContent(testModuleContent);

            var okResult = Assert.IsType <OkResult>(result);

            Assert.Equal(200, okResult.StatusCode);
        }
        public async void AddModuleContent_CalledWithNull_ReturnsBadRequestWithError()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            ModuleContentViewModel nullModuleContent = null;
            string error = "Module content cannot be null.";

            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.AddModuleContent(nullModuleContent);

            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var returnValue            = Assert.IsType <string>(badRequestObjectResult.Value);

            Assert.Equal(error, returnValue);
        }
        public async void AddModuleContent_CalledAndRoleIsNotAdmin_ReturnsBadRequestWithError()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            var    testModuleContent = new ModuleContentViewModel();
            string error             = "Only Admins can add new module contents.";

            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString());

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.AddModuleContent(testModuleContent);

            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var returnValue            = Assert.IsType <string>(badRequestObjectResult.Value);

            Assert.Equal(error, returnValue);
        }
        public async void AddModuleContent_CalledWithInvalidValidModuleContent_ReturnsNotFoundWithModuleId()
        {
            IUnitOfWork    unitOfWork    = Substitute.For <IUnitOfWork>();
            ICookieManager cookieManager = Substitute.For <ICookieManager>();
            var            context       = Substitute.For <HttpContext>();

            var    notValidId        = 1;
            Module nullModule        = null;
            var    testModuleContent = new ModuleContentViewModel()
            {
                ModuleId = notValidId
            };

            cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString());
            unitOfWork.Modules.GetById(notValidId).Returns(nullModule);
            unitOfWork.ModuleContents.GetLastModuleContentByModuleId(testModuleContent.ModuleId).Returns(0);

            var moduleContentsController = new ModuleContentsController(unitOfWork, cookieManager);

            moduleContentsController.ControllerContext = new ControllerContext()
            {
                HttpContext = context
            };

            var result = await moduleContentsController.AddModuleContent(testModuleContent);

            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);
            var returnValue          = Assert.IsType <long>(notFoundObjectResult.Value);

            Assert.Equal(notValidId, returnValue);
        }