public async Task AcceptAsync_WithNonExistentInvitation_ReturnsFalse()
        {
            // Arrange
            const string testKey = "key111";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride();

            await context.Rides.AddAsync(ride);

            var user = new PoolItUser
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            var invitationsService = new InvitationsService(
                new EfRepository <Invitation>(context),
                new EfRepository <Ride>(context),
                new EfRepository <JoinRequest>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <UserRide>(context),
                null);

            // Act
            var result = await invitationsService.AcceptAsync(user.UserName, testKey);

            // Assert
            Assert.False(result);
        }
        public async Task AcceptAsync_WithNullInvitationKey_ReturnsFalse()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var user = new PoolItUser
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var invitationsService = new InvitationsService(
                new EfRepository <Invitation>(context),
                new EfRepository <Ride>(context),
                new EfRepository <JoinRequest>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <UserRide>(context),
                null);

            // Act
            var result = await invitationsService.AcceptAsync(user.UserName, null);

            // Assert
            Assert.False(result);
        }
        public async Task AcceptAsync_WithNullUserName_ReturnsFalse()
        {
            // Arrange
            const string testKey = "key111";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride();

            await context.Rides.AddAsync(ride);

            await context.Invitations.AddAsync(new Invitation
            {
                Key  = testKey,
                Ride = ride
            });

            context.SaveChanges();

            var invitationsService = new InvitationsService(
                new EfRepository <Invitation>(context),
                new EfRepository <Ride>(context),
                new EfRepository <JoinRequest>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <UserRide>(context),
                null);

            // Act
            var result = await invitationsService.AcceptAsync(null, testKey);

            // Assert
            Assert.False(result);

            var invitationExists = await context.Invitations.AnyAsync();

            Assert.True(invitationExists);
        }
        public async Task AcceptAsync_WithCorrectUserAndInvitation_WorksCorrectly()
        {
            // Arrange
            const string testKey = "key111";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride();

            await context.Rides.AddAsync(ride);

            var user = new PoolItUser
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            var joinRequest = new JoinRequest
            {
                User = user,
                Ride = ride
            };

            await context.JoinRequests.AddAsync(joinRequest);

            await context.Invitations.AddAsync(new Invitation
            {
                Key  = testKey,
                Ride = ride
            });

            context.SaveChanges();

            var invitationsService = new InvitationsService(
                new EfRepository <Invitation>(context),
                new EfRepository <Ride>(context),
                new EfRepository <JoinRequest>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <UserRide>(context),
                null);

            // Act
            var result = await invitationsService.AcceptAsync(user.UserName, testKey);

            // Assert
            Assert.True(result);

            // - Check for UserRide creation
            var userRideExists = await context.UserRides.AnyAsync(u => u.UserId == user.Id && u.RideId == ride.Id);

            Assert.True(userRideExists);

            // - Check JoinRequest is removed
            var joinRequestExists = await context.JoinRequests.AnyAsync();

            Assert.False(joinRequestExists);

            // - Check invitation is removed
            var invitationExists = await context.Invitations.AnyAsync();

            Assert.False(invitationExists);
        }