Exemple #1
0
        public async Task GetAsync_WithNullId_ReturnsNull()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            // Act
            var result = await ridesService.GetAsync(null);

            // Assert
            Assert.Null(result);
        }
Exemple #2
0
        public async Task GetAsync_WithCorrectId_WorksCorrectly()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var ride = new Ride
            {
                Title = "TestRide",
                Car   = new Car
                {
                    Model = new CarModel
                    {
                        Model        = "Test Model",
                        Manufacturer = new CarManufacturer()
                    },
                    Owner = new PoolItUser
                    {
                        UserName = "******"
                    }
                },
                Conversation = new Conversation()
            };

            await context.Rides.AddAsync(ride);

            await context.SaveChangesAsync();

            var ridesService = new RidesService(new EfRepository <Ride>(context), null, null, null);

            // Act
            var result = await ridesService.GetAsync(ride.Id);

            // Assert
            Assert.NotNull(result);

            Assert.Equal(ride.Title, result.Title);
        }