예제 #1
0
        public async Task Invalidate_when_backpack_does_not_exist()
        {
            // Arrange
            var sut = new RemoveContributorValidator(_dbContext);

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

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

            var contributor = new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = contributorUserSub
            };

            await _dbContext.Users.AddAsync(owner);

            await _dbContext.Users.AddAsync(contributor);

            await _dbContext.SaveChangesAsync();

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

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

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

            // Assert
            isValid.ShouldBeFalse();
        }
예제 #3
0
        public async Task Validate_when_user_is_owner_of_backpack_and_removes_a_member()
        {
            // Arrange
            var sut = new RemoveContributorValidator(_dbContext);

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

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

            var backpackContributor = new User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = backpackContributorSub
            };

            var backpack = new Domain.Entities.Backpack
            {
                Name = "my backpack"
            };

            await _dbContext.Users.AddAsync(owner);

            await _dbContext.Users.AddAsync(backpackContributor);

            await _dbContext.Backpacks.AddAsync(backpack);

            await _dbContext.BackpacksToUsers.AddAsync(new BackpackToUser { Backpack = backpack, User = owner, IsOwner = true });

            await _dbContext.BackpacksToUsers.AddAsync(new BackpackToUser { Backpack = backpack, User = backpackContributor, IsOwner = false });

            await _dbContext.SaveChangesAsync();

            // Act
            bool isValid = await sut.IsValidAsync(new RemoveContributor(userSub, backpack.Id, backpackContributor.Id));

            // Assert
            isValid.ShouldBeTrue();
        }
예제 #4
0
        public async Task Invalidate_when_target_user_does_not_exists()
        {
            // Arrange
            var sut = new RemoveContributorValidator(_dbContext);

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

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

            var backpack = new Domain.Entities.Backpack()
            {
                Name = "my backpack"
            };

            await _dbContext.Users.AddAsync(owner);

            await _dbContext.Backpacks.AddAsync(backpack);

            await _dbContext.BackpacksToUsers.AddAsync(new BackpackToUser()
            {
                Backpack = backpack, User = owner
            });

            await _dbContext.SaveChangesAsync();

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

            // Assert
            isValid.ShouldBeFalse();
        }