Exemple #1
0
        public async Task Invalidate_when_user_not_part_of_group()
        {
            // Arrange
            var    sut     = new LeaveGroupValidator(_dbContext);
            string userSub = Guid.NewGuid().ToString();

            var user = new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            };

            var group = new Domain.Entities.Group
            {
                Admin = user,
                Name  = "my group"
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Groups.AddAsync(group);

            await _dbContext.SaveChangesAsync();

            // Act
            bool isValid = await sut.IsValidAsync(new LeaveGroup(userSub, group.Id));

            // Assert
            isValid.ShouldBeFalse();
        }
Exemple #2
0
        public async Task Invalidate_request_when_no_user_found_by_sub(string sub)
        {
            // Arrange
            var sut = new LeaveGroupValidator(_dbContext);

            // Act
            bool isValid = await sut.IsValidAsync(new LeaveGroup(sub, Guid.NewGuid()));

            // Assert
            isValid.ShouldBeFalse();
        }
Exemple #3
0
        public async Task Validate_when_is_part_of_requested_group()
        {
            // Arrange
            var    sut      = new LeaveGroupValidator(_dbContext);
            string userSub  = Guid.NewGuid().ToString();
            string adminSub = Guid.NewGuid().ToString();

            var user = new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            };

            var admin = new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = adminSub
            };

            var group = new Domain.Entities.Group
            {
                Admin = admin,
                Name  = "my group"
            };

            var userToGroups = new UserToGroup {
                Group = group, User = user
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Groups.AddAsync(group);

            await _dbContext.UsersToGroups.AddAsync(userToGroups);

            await _dbContext.SaveChangesAsync();

            // Act
            bool isValid = await sut.IsValidAsync(new LeaveGroup(userSub, group.Id));

            // Assert
            isValid.ShouldBeTrue();
        }
Exemple #4
0
        public async Task Invalidate_when_no_group_found()
        {
            // Arrange
            var sut = new LeaveGroupValidator(_dbContext);

            string userSub = Guid.NewGuid().ToString();

            await _dbContext.Users.AddAsync(new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            });


            // Act
            bool isValid = await sut.IsValidAsync(new LeaveGroup(userSub, Guid.NewGuid()));

            // Assert
            isValid.ShouldBeFalse();
        }