Exemplo n.º 1
0
        public async Task GetAsync_WithNonExistentRequest_ReturnsNull()
        {
            // Arrange
            var testId = Guid.NewGuid().ToString();

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

            await context.JoinRequests.AddAsync(
                new JoinRequest
            {
                Ride = new Ride
                {
                    Title = "Test Ride",
                    Car   = new Car
                    {
                        Owner = new PoolItUser
                        {
                            UserName = "******"
                        },
                        Model = new CarModel
                        {
                            Manufacturer = new CarManufacturer()
                        }
                    },
                    Conversation = new Conversation()
                },
                User = new PoolItUser
                {
                    UserName = "******"
                },
                Message = "Test Message"
            }
                );

            await context.SaveChangesAsync();

            var joinRequestsService = new JoinRequestsService(new EfRepository <JoinRequest>(context), null, null, null);

            // Act
            var result = await joinRequestsService.GetAsync(testId);

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 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 = "Test Ride",
                Car   = new Car
                {
                    Owner = new PoolItUser
                    {
                        UserName = "******"
                    },
                    Model = new CarModel
                    {
                        Manufacturer = new CarManufacturer()
                    }
                },
                Conversation = new Conversation()
            };

            await context.Rides.AddAsync(ride);

            var request = new JoinRequest
            {
                Ride = ride,
                User = new PoolItUser
                {
                    UserName = "******"
                },
                Message = "Test Message 1"
            };

            await context.JoinRequests.AddRangeAsync(
                request,
                new JoinRequest
            {
                Ride = ride,
                User = new PoolItUser
                {
                    UserName = "******"
                },
                Message = "Test Message 2"
            }
                );

            await context.SaveChangesAsync();

            var joinRequestsService = new JoinRequestsService(new EfRepository <JoinRequest>(context), null, null, null);

            // Act
            var result = await joinRequestsService.GetAsync(request.Id);

            // Assert
            Assert.NotNull(result);

            Assert.Equal(request.Message, result.Message);
        }