Exemplo n.º 1
0
        public async Task Delete_ShouldRedirectToTrainersIndex_GivenInvalidUser()
        {
            // Arrange
            var testModel = this.GetResource();

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(null);

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

            using (controller)
            {
                // Act
                var result = await controller.Delete(TestResourceId, testModel);

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

                this.AssertRedirectToTrainersIndex(result);

                userManager.Verify();
            }
        }
        public void DeleteTest()
        {
            // Arrange
            ResourcesController target   = new ResourcesController(_service);
            Resource            expected = _mockdata.DeleteResource1();
            // Act
            var actual = target.Delete(expected.Id) as NoContentResult;

            // Assert
            Assert.IsNotNull(actual);
        }
        public void DeleteTest_Exception()
        {
            // Arrange
            ResourcesController target = new ResourcesController(_errorService);

            // Act
            var actual = target.Delete(-1) as ObjectResult;

            // Assert
            Assert.IsNotNull(actual);
        }
Exemplo n.º 4
0
        public async void Delete_ReturnsOkDeletedResponse()
        {
            // 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);

            // Act
            var actionResult = await subjectResController.Delete(It.IsAny <int>());

            //Assert
            var okResult = Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsAssignableFrom <DateTime>(okResult.Value.GetType().GetProperty("DeletedTime")?.GetValue(okResult.Value, null));
            resServiceMock.Verify(mock => mock.Delete(It.IsAny <int>()), Times.Once());
        }
Exemplo n.º 5
0
        public async Task Delete_ShouldRedirectToTrainersResourcesWithSuccessMsg_GivenRemoveSuccess()
        {
            // Arrange
            var testModel = this.GetResource();

            var userManager = UserManagerMock.GetMock;

            userManager.GetUserId(TestUserId);

            var trainerService = TrainerServiceMock.GetMock;

            trainerService.IsTrainerForCourseAsync(true);

            var resourceService = ResourceServiceMock.GetMock;

            resourceService
            .Exists(true)
            .RemoveAsync(true);

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

            using (controller)
            {
                // Act
                var result = await controller.Delete(TestResourceId, testModel);

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

                this.AssertRedirectToTrainersResourcesWithRouteId(result);

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