Ejemplo n.º 1
0
        public async Task Create_ShouldRedirectToTrainersIndex_GivenMismatchingCourseAndModel()
        {
            // Arrange
            var testModel = GetResourceCreateModel();

            var courseService = CourseServiceMock.GetMock;

            var controller = new ResourcesController(
                userManager: null,
                cloudinaryService: null,
                courseService.Object,
                resourceService: null,
                trainerService: null)
            {
                TempData = TempDataMock.GetMock
            };

            using (controller)
            {
                // Act
                var result = await controller.Create(TestCourseId + 1, testModel);

                // Assert
                controller.TempData.AssertErrorMsg(WebConstants.CourseInvalidMsg);

                this.AssertRedirectToTrainersIndex(result);

                courseService.Verify();
            }
        }
Ejemplo n.º 2
0
        public async Task Create_ShouldRedirectToTrainersResources_GivenInvalidFormModel()
        {
            // Arrange
            var controller = new ResourcesController(
                userManager: null,
                cloudinaryService: null,
                courseService: null,
                resourceService: null,
                trainerService: null)
            {
                TempData = TempDataMock.GetMock
            };

            using (controller)
            {
                controller.ModelState.AddModelError(string.Empty, "Error");

                // Act
                var result = await controller.Create(TestCourseId, null);

                // Assert
                controller.TempData.AssertErrorMsg(WebConstants.FileInvalidMsg);

                this.AssertRedirectToTrainersResourcesWithRouteId(result);
            }
        }
Ejemplo n.º 3
0
        public async Task Create_ShouldRedirectToTrainersResourcesWithSuccessMsg_GivenCreateSuccess()
        {
            // Arrange
            var testModel = GetResourceCreateModel();

            var courseService = CourseServiceMock.GetMock;

            courseService.Exists(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService.IsTrainerForCourseAsync(true);

            var cloudinaryService = CloudinaryServiceMock.GetMock;

            cloudinaryService.UploadFile(FileUrl);

            var resourceService = ResourceServiceMock.GetMock;

            resourceService.CreateAsync(true);

            var controller = new ResourcesController(
                userManager.Object,
                cloudinaryService.Object,
                courseService.Object,
                resourceService.Object,
                trainerService.Object)
            {
                TempData = TempDataMock.GetMock
            };

            using (controller)
            {
                // Act
                var result = await controller.Create(TestCourseId, testModel);

                // Assert
                controller.TempData.AssertSuccessMsg(WebConstants.ResourceCreatedMsg);

                this.AssertRedirectToTrainersResourcesWithRouteId(result);

                cloudinaryService.Verify();
                courseService.Verify();
                userManager.Verify();
                trainerService.Verify();
                resourceService.Verify();
            }
        }
Ejemplo n.º 4
0
        public async void Create_ReturnsBadRequest_OnInvalidModel()
        {
            // Arrange
            var resServiceMock  = new Mock <IResourcesService>();
            var bookServiceMock = new Mock <IBookingsService>();
            var mappServiceMock = new Mock <IMapperService>();

            var subjectResController = new ResourcesController(resServiceMock.Object, bookServiceMock.Object, mappServiceMock.Object);

            subjectResController.ModelState.AddModelError("blah", "blah");

            // Act
            var actionResult = await subjectResController.Create(It.IsAny <ResourceDetailedDto>());

            //Assert
            Assert.IsType <BadRequestObjectResult>(actionResult);
            resServiceMock.Verify(mock => mock.Create(It.IsAny <Resource>()), Times.Never());
        }
Ejemplo n.º 5
0
        public async Task Create_ShouldRedirectToTrainersIndex_GivenInvalidTrainer()
        {
            // Arrange
            var testModel = GetResourceCreateModel();

            var courseService = CourseServiceMock.GetMock;

            courseService.Exists(true);

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService.IsTrainerForCourseAsync(false);

            var controller = new ResourcesController(
                userManager.Object,
                cloudinaryService: null,
                courseService.Object,
                resourceService: null,
                trainerService.Object)
            {
                TempData = TempDataMock.GetMock
            };

            using (controller)
            {
                // Act
                var result = await controller.Create(TestCourseId, testModel);

                // Assert
                controller.TempData.AssertErrorMsg(WebConstants.NotTrainerForCourseMsg);

                this.AssertRedirectToTrainersIndex(result);

                courseService.Verify();
                userManager.Verify();
                trainerService.Verify();
            }
        }