예제 #1
0
        public async Task GetAllAsync_WithNoInvitations_ReturnsEmptyEnumerable()
        {
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var invitationsService = new InvitationsService(new EfRepository <Invitation>(context),
                                                            null, null, null, null, null);

            // Act
            var actualResult = (await invitationsService.GetAllAsync()).Count();

            // Assert
            Assert.Equal(0, actualResult);
        }
예제 #2
0
        public async Task GetAllAsync_WithInvitations_WorksCorrectly()
        {
            const int expectedResult = 2;

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

            var ride = new Ride
            {
                Car = new Car
                {
                    Model = new CarModel
                    {
                        Manufacturer = new CarManufacturer()
                    },
                    Owner = new PoolItUser()
                },
                Conversation = new Conversation()
            };

            await context.Invitations.AddRangeAsync(
                new Invitation
            {
                Key  = "key001",
                Ride = ride
            },
                new Invitation
            {
                Key  = "key002",
                Ride = ride
            });

            context.SaveChanges();

            var invitationsService = new InvitationsService(new EfRepository <Invitation>(context),
                                                            null, null, null, null, null);

            // Act
            var actualResult = (await invitationsService.GetAllAsync()).Count();

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }