Ejemplo n.º 1
0
        public async void DeleteExistingGroupTest()
        {
            var group = new Group()
            {
                Id          = 4,
                Name        = "john",
                Memberships = new List <Membership>()
            };
            var mem = new Membership()
            {
                Group   = group,
                User    = new User(),
                GroupId = 4,
                UserId  = 2,
            };

            group.Memberships.Add(mem);
            Memberships.Add(mem);
            Groups.Add(group);

            var command = new DeleteGroupCommand()
            {
                Id = 4
            };
            var handler = new DeleteGroupCommandHandler(Context);

            await handler.Handle(command, CancellationToken.None);

            Assert.Empty(Memberships);
            Assert.Empty(Groups);
        }
        public async Task ThrowNotFoundException_WhenGroupIsNotExists()
        {
            var request = new DeleteGroupCommand
            {
                Id = 100
            };

            var handler = new DeleteGroupCommandHandler(Context);

            var exception = Assert.ThrowsAsync <NotFoundException>(async() => await handler.Handle(request, CancellationToken.None));

            Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetNotFoundExceptionMessage(nameof(Group), request.Id));
        }
        public async Task DeleteGroup()
        {
            var request = new DeleteGroupCommand
            {
                Id = 1
            };

            var handler = new DeleteGroupCommandHandler(Context);

            var result = await handler.Handle(request, CancellationToken.None);

            Assert.IsFalse(Context.Groups.Any(x => x.Id == request.Id));
        }
Ejemplo n.º 4
0
        public async Task Delete_InvalidId_BadRequestException(int id)
        {
            await ExecuteWithDb((db) =>
            {
                var handler = new DeleteGroupCommandHandler(
                    MockMediator.Object,
                    db,
                    Mapper,
                    MockAuthorizationService.Object);

                return(handler.Handle(new DeleteGroupCommand()
                {
                    GroupId = id
                }, default(CancellationToken)));
            });
        }
Ejemplo n.º 5
0
        public async Task Delete_IdNotFound_EntityNotFoundException()
        {
            await ExecuteWithDb((db) =>
            {
                var handler = new DeleteGroupCommandHandler(
                    MockMediator.Object,
                    db,
                    Mapper,
                    MockAuthorizationService.Object);

                var lastGroup = db.Groups.OrderBy(o => o.Id).Last();

                return(handler.Handle(new DeleteGroupCommand()
                {
                    GroupId = (lastGroup.Id + 1)
                }, default(CancellationToken)));
            });
        }
Ejemplo n.º 6
0
        public void DeleteNonExistingGroupTest()
        {
            Groups.Add(new Group()
            {
                Id          = 1,
                Name        = "La pedrera",
                Memberships = new List <Membership>()
            });
            Context.SaveChanges();
            var command = new DeleteGroupCommand()
            {
                Id = 4
            };
            var handler = new DeleteGroupCommandHandler(Context);

            Assert.Throws <AggregateException>(() => handler.Handle(command, CancellationToken.None).Result);
            Assert.Single(Groups);
        }
        public async Task ThrowDeleteFailureException_WhenLessonWithGroupExists()
        {
            var request = new DeleteGroupCommand
            {
                Id = 2
            };

            var handler = new DeleteGroupCommandHandler(Context);

            var exception = Assert.ThrowsAsync <DeleteFailureException>(async() => await handler.Handle(request, CancellationToken.None));

            Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetDeleteFailureExceptionMessage(nameof(Group), request.Id, "There are lesson(s) with this group"));
        }