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

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

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

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

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 2
0
        public async Task GetAsync_WithCorrectId_WorksCorrectly()
        {
            // Arrange
            const string testName = "TestName";

            var manufacturer = new CarManufacturer
            {
                Name = testName
            };

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

            context.CarManufacturers.AddRange(
                manufacturer,
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var actualResult = (await manufacturersService.GetAsync(manufacturer.Id)).Name;

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