public async Task Invalidate_when_invite_is_for_other_user()
        {
            var sut = new AcceptGroupInviteValidator(_dbContext);

            // Arrange
            string userSub = Guid.NewGuid().ToString();
            var    user    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "user",
                LastName  = "user",
                Sub       = userSub
            };

            string otherUserSub = Guid.NewGuid().ToString();
            var    otherUser    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "other",
                LastName  = "user",
                Sub       = otherUserSub
            };

            string adminSub = Guid.NewGuid().ToString();
            var    admin    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Admin",
                LastName  = "Test",
                Sub       = adminSub
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Users.AddAsync(admin);

            await _dbContext.Users.AddAsync(otherUser);

            var group = new Group
            {
                Admin = admin,
                Name  = "group"
            };

            await _dbContext.Groups.AddAsync(group);

            var groupInvite = new GroupInvite
            {
                InvitationReceiver = user,
                InvitationSender   = admin,
                Group = group
            };

            await _dbContext.GroupInvites.AddAsync(groupInvite);

            await _dbContext.SaveChangesAsync();

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

            // Assert
            isValid.ShouldBeFalse();
        }
        public async Task Validate_when_user_was_found_by_sub_and_location_exists()
        {
            var sut = new UpdateLocationValidator(_dbContext);

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

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

            var userLocation = new UserLocation
            {
                User      = user,
                Address   = "Splaiul Unirii 160, 040041 Bucharest, Romania",
                Type      = UserLocationType.Work,
                Longitude = 44.41184746891321m,
                Latitude  = 26.118310383230373m
            };
            await _dbContext.UserLocations.AddAsync(userLocation);

            await _dbContext.SaveChangesAsync();

            // Act
            bool isValid = await sut.IsValidAsync(new UpdateLocation(userSub, userLocation.Id, new UserLocationRequest()));

            // Assert
            isValid.ShouldBeTrue();
        }
Esempio n. 3
0
        public async Task CreateApplicationUserAsync(UserRegistrationDto user, string userSub)
        {
            var newUser = new DeUrgenta.Domain.Entities.User
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Sub       = userSub,
            };

            var userBackpack = new Backpack
            {
                Name = "Ruxacul tau personal"
            };

            var userToBackpack = new BackpackToUser
            {
                Backpack = userBackpack,
                User     = newUser,
                IsOwner  = true
            };

            await _context.Backpacks.AddAsync(userBackpack);

            await _context.Users.AddAsync(newUser);

            await _context.BackpacksToUsers.AddAsync(userToBackpack);

            await _context.SaveChangesAsync();
        }
Esempio n. 4
0
        public async Task Validate_when_an_invite_exists()
        {
            var sut = new RejectGroupInviteValidator(_dbContext);

            // Arrange
            string userSub = Guid.NewGuid().ToString();
            var    user    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            };

            string adminSub = Guid.NewGuid().ToString();
            var    admin    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Admin",
                LastName  = "Test",
                Sub       = adminSub
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Users.AddAsync(admin);

            var group = new Group
            {
                Admin = admin,
                Name  = "group"
            };

            var groupInvite = new GroupInvite
            {
                InvitationReceiver = user,
                InvitationSender   = admin,
                Group = group
            };
            await _dbContext.GroupInvites.AddAsync(groupInvite);

            await _dbContext.Groups.AddAsync(group);

            await _dbContext.SaveChangesAsync();

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

            // Assert
            isValid.ShouldBeTrue();
        }
Esempio n. 5
0
        public async Task Validate_when_an_invite_exists()
        {
            var sut = new AcceptBackpackInviteValidator(_dbContext);

            // Arrange
            string userSub = Guid.NewGuid().ToString();
            var    user    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            };

            string adminSub = Guid.NewGuid().ToString();
            var    admin    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Admin",
                LastName  = "Test",
                Sub       = adminSub
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Users.AddAsync(admin);

            var backpack = new Backpack
            {
                Name = "backpack"
            };

            var backpackInvite = new BackpackInvite
            {
                InvitationReceiver = user,
                InvitationSender   = admin,
                Backpack           = backpack
            };
            await _dbContext.BackpackInvites.AddAsync(backpackInvite);

            await _dbContext.Backpacks.AddAsync(backpack);

            await _dbContext.SaveChangesAsync();

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

            // Assert
            isValid.ShouldBeTrue();
        }
        public async Task Invalidate_when_invite_does_not_exist()
        {
            var sut = new AcceptGroupInviteValidator(_dbContext);

            // Arrange
            string userSub = Guid.NewGuid().ToString();
            var    user    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Integration",
                LastName  = "Test",
                Sub       = userSub
            };

            string adminSub = Guid.NewGuid().ToString();
            var    admin    = new DeUrgenta.Domain.Entities.User
            {
                FirstName = "Admin",
                LastName  = "Test",
                Sub       = adminSub
            };

            await _dbContext.Users.AddAsync(user);

            await _dbContext.Users.AddAsync(admin);

            var group = new Group
            {
                Admin = admin,
                Name  = "group"
            };

            await _dbContext.Groups.AddAsync(group);

            await _dbContext.SaveChangesAsync();

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

            // Assert
            isValid.ShouldBeFalse();
        }