Esempio n. 1
0
        public async Task TestDelete()
        {
            var groupAppService = Substitute.For <IGroupAppService>();

            var target = new GroupController(
                CreateMemoryCache(),
                CreateMapper(),
                Substitute.For <IDepartmentAppService>(),
                Substitute.For <IPositionAppService>(),
                groupAppService);

            target.ControllerContext = CreateMockContext();

            groupAppService.DeleteAsync(Arg.Any <GroupInput>())
            .ReturnsForAnyArgs(RemotingResult.Success());
            var result = await target.Delete(Guid.NewGuid());

            result.Value.Should().NotBeNull();
            result.Value.Status.Should().Be(0);

            groupAppService.DeleteAsync(Arg.Any <GroupInput>())
            .ReturnsForAnyArgs(RemotingResult.Fail());
            result = await target.Delete(Guid.NewGuid());

            result.Value.Status.Should().NotBe(0);

            groupAppService.DeleteAsync(Arg.Any <GroupInput>())
            .ReturnsForAnyArgs(RemotingResult.Fail(FailedCodes.Group_NotCreatedBy));
            result = await target.Delete(Guid.NewGuid());

            result.Value.Status.Should().Be(FailedCodes.Group_NotCreatedBy);
        }
Esempio n. 2
0
        public void Delete_Group_ReturnsOkResult_Positive()
        {
            int groupId = 1;
            List <Enrollment> initialEnrollments = GetInitialEnrollments(groupId);

            _enrollmentService.Setup(x => x.GetByGroupId(groupId)).Returns(initialEnrollments);
            _wordProgressService.Setup(x => x.RemoveProgressesForEnrollment(
                                           It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null)));
            _wordsuiteService.Setup(x => x.RemoveWordSuitesForEnrollment(
                                        It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null)));
            _groupService.Setup(x => x.DeleteById(groupId));

            var actual = _controller.Delete(groupId);

            Assert.IsInstanceOf(typeof(OkResult), actual);
        }
        public void DeleteExistingGroup()
        {
            var groupName = "DeleteExistingGroup";

            var group = CreateGroup(groupName);

            var groups = _groupController.Get(groupName);

            Assert.Equal(groups.Count(), 1);
            Assert.Equal(groups.ElementAt(0).Name, groupName);

            _groupController.Delete(group.Id);
            groups = _groupController.Get(groupName);

            Assert.Empty(groups);
        }
        public void When_DeleteGroup_Expect_GroupDeletion()
        {
            var errorMessage = string.Empty;
            var guid         = Guid.NewGuid().ToString();
            var newGroup     = new CreateGroupCommand()
            {
                Group = new Group()
                {
                    Name = guid, CurrentCapacity = 100M
                }
            };
            var actionResult = _groupController.Create(newGroup);

            var createdGroup = ActionResultParser.ParseCreatedResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            if (createdGroup.Id == 0)
            {
                Assert.Fail();
            }

            actionResult = _groupController.Delete(createdGroup.Id);

            var deletedGroup = ActionResultParser.ParseObjectResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            Assert.AreEqual(createdGroup.Id, deletedGroup.Id);
        }
Esempio n. 5
0
        public async Task Group_Delete_Should_Return_Exception()
        {
            // Arrange
            int       id = 1;
            Exception expectedException        = null;
            string    expectedExceptionMessage = "Deleting a group failed on save.";

            moqRepository.Setup(g => g.Get(It.IsAny <Func <Group, bool> >())).Returns(groups.FirstOrDefault());
            moqUnitOfWork.Setup(x => x.Repository <Group>()).Returns(moqRepository.Object);
            moqUnitOfWork.Setup(x => x.SaveChangesAsyn()).ReturnsAsync(0);

            var controller = new GroupController(moqUnitOfWork.Object);

            // Act
            try
            {
                var actionResult = await controller.Delete(id);
            }
            catch (Exception ex)
            {
                expectedException = ex;
            }

            // Assert
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(expectedExceptionMessage, expectedException.Message);
        }
        public void DeletePost_FLow_RedirectToRouteResult()
        {
            // Arrange
            var mainUser = new User
            {
                Id        = 1,
                FirstName = "Unit",
                LastName  = "Test",
                UserName  = "******",
                Mail      = "*****@*****.**"
            };

            var users = new List <User>()
            {
                mainUser
            }.AsQueryable();

            var mainGroup = new Group
            {
                Id = 1,
            };

            var groups = new List <Group>()
            {
                mainGroup
            }.AsQueryable();

            var mockContext = new Mock <Context>();

            var mockGroups = MockHelper.MockDbSet(groups);

            mockContext.SetupGet(c => c.Groups).Returns(mockGroups.Object);

            var mockUserHelper = new Mock <IUserHelper>();

            mockUserHelper.Setup(x => x.GetCurrentUser().Id).Returns(mainUser.Id);

            var controller = new GroupController(mockContext.Object, mockUserHelper.Object);

            // Act
            RedirectToRouteResult resultGroupNotNull = controller.Delete(mainGroup.Id, "Deleted") as RedirectToRouteResult;
            RedirectToRouteResult resultGroupNull    = controller.Delete(0, "Deleted") as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(resultGroupNotNull);
            Assert.IsNotNull(resultGroupNull);
        }
        public void Delete_CalledWithId_ReturnStatusCode200()
        {
            //act
            var statusCode = ((OkObjectResult)_controller.Delete(2)).StatusCode;

            //assert
            statusCode.Should().Be(200);
        }
Esempio n. 8
0
        public void Delete_Group_ReturnsBadRequestResult_Negative()
        {
            int groupId = 1;
            List <Enrollment> initialEnrollments = new List <Enrollment>
            {
                new Enrollment
                {
                    Id      = 1,
                    GroupId = groupId,
                    UserId  = 1,
                    Date    = DateTime.Now
                },
                new Enrollment
                {
                    Id      = 2,
                    GroupId = groupId,
                    UserId  = 2,
                    Date    = DateTime.Now
                },
                new Enrollment
                {
                    Id      = 3,
                    GroupId = groupId,
                    UserId  = 3,
                    Date    = DateTime.Now
                }
            };

            GenerateData("1", new[] { "NoRoles" });
            Mock <IGroupForListingMapper> groupForListingMapper = new Mock <IGroupForListingMapper>();
            Mock <IGroupService>          groupService          = new Mock <IGroupService>();
            Mock <IEnrollmentService>     enrollmentService     = new Mock <IEnrollmentService>();
            Mock <IWordProgressService>   wordProgressService   = new Mock <IWordProgressService>();
            Mock <IWordSuiteService>      wordsuiteService      = new Mock <IWordSuiteService>();
            Mock <ICourseService>         courseService         = new Mock <ICourseService>();
            Mock <ICourseForGroupMapper>  courseMapper          = new Mock <ICourseForGroupMapper>();
            Mock <IGroupMapper>           groupMapper           = new Mock <IGroupMapper>();

            GroupController groupController = new GroupController(groupService.Object, groupForListingMapper.Object,
                                                                  enrollmentService.Object, wordProgressService.Object, wordsuiteService.Object, courseService.Object,
                                                                  courseMapper.Object, groupMapper.Object);

            enrollmentService.Setup(x => x.GetByGroupId(groupId)).Returns(initialEnrollments);
            wordProgressService.Setup(x => x.RemoveProgressesForEnrollment(
                                          It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null))).Returns(true);
            wordsuiteService.Setup(x => x.RemoveWordSuitesForEnrollment(
                                       It.Is <int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null))).Returns(true);
            groupService.Setup(x => x.DeleteById(groupId)).Returns(false);

            var actual = groupController.Delete(groupId);

            Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), actual);
        }
Esempio n. 9
0
        public void DeleteGroup()
        {
            var res = controller.Delete(1);

            Assert.IsInstanceOfType(res, typeof(RedirectToRouteResult));
            var redirectRes = res as RedirectToRouteResult;

            Assert.IsNull(redirectRes.RouteValues["controller"]);
            Assert.AreEqual("List", redirectRes.RouteValues["action"]);

            gMockRepository.Verify(r => r.Delete(groups[0]));
            gMockRepository.Verify(r => r.Save());
        }
Esempio n. 10
0
        public void Delete_SingleGroupNotNull_ViewResult()
        {
            // Arrange
            var mainUser = new User
            {
                Id        = 1,
                FirstName = "Unit",
                LastName  = "Test",
                UserName  = "******",
                Mail      = "*****@*****.**"
            };

            var users = new List <User>()
            {
                mainUser
            }.AsQueryable();

            var mainGroup = new Group
            {
                Id           = 1,
                Category     = "Unit Category",
                CreatedOn    = DateTime.Now,
                GroupName    = "Unit Group",
                GroupCreator = mainUser.Id,
            };

            var groups = new List <Group>()
            {
                mainGroup
            }.AsQueryable();


            var mockContext = new Mock <Context>();

            var mockGroups = MockHelper.MockDbSet(groups);

            mockContext.SetupGet(c => c.Groups).Returns(mockGroups.Object);

            var mockUserHelper = new Mock <IUserHelper>();

            mockUserHelper.Setup(x => x.GetCurrentUser().Id).Returns(mainUser.Id);

            var controller = new GroupController(mockContext.Object, mockUserHelper.Object);

            // Act
            ViewResult result = controller.Delete(mainGroup.Id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Esempio n. 11
0
        public async Task Group_Delete_Should_Return_InstanceOfTypeNoContentResultGroupDto()
        {
            // Arrange
            int id = 1;

            moqRepository.Setup(g => g.Get(It.IsAny <Func <Group, bool> >())).Returns(groups.FirstOrDefault());
            moqUnitOfWork.Setup(x => x.Repository <Group>()).Returns(moqRepository.Object);
            moqUnitOfWork.Setup(x => x.SaveChangesAsyn()).ReturnsAsync(1);

            var controller = new GroupController(moqUnitOfWork.Object);

            // Act
            var actionResult = await controller.Delete(id) as NoContentResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOfType(actionResult, typeof(NoContentResult));
        }
Esempio n. 12
0
        public async Task Group_Delete_Should_Return_InstanceOfTypeNotFound()
        {
            // Arrange
            int id = 1;

            moqRepository.Setup(g => g.Get(It.IsAny <Func <Group, bool> >())).Returns(null as Group);
            moqUnitOfWork.Setup(x => x.Repository <Group>()).Returns(moqRepository.Object);

            var controller = new GroupController(moqUnitOfWork.Object);

            // Act
            var actionResult = await controller.Delete(id);

            var createdResult = actionResult as NotFoundResult;

            // Assert
            Assert.IsNotNull(createdResult);
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
        public async Task Group_Delete_ShouldReturnData()
        {
            var results = await _controller.Delete(DefaultGroup);

            results.Should().BeOfType <OkResult>();
        }