Exemplo n.º 1
0
        public async Task Manufacturer_Repository_Should_Remove_Manufacturer_Async()
        {
            // Arrange
            var context        = TestSetUpHelper.CreateDbContext();
            var repository     = new ManufacturerRepository(context);
            var expectedEntity = new Manufacturer()
            {
                Id   = 4,
                Name = "TestName",
            };

            await repository.AddAsync(expectedEntity);

            await context.SaveChangesAsync();

            // Act
            await repository.RemoveAsync(expectedEntity.Id);

            await context.SaveChangesAsync();

            var actualEntity = await repository.GetByIdAsync(expectedEntity.Id);

            // Assert
            Assert.Null(actualEntity);
        }
Exemplo n.º 2
0
        public async Task Manufacturer_Repository_Should_Update_Manufacturer()
        {
            // Arrange
            var context         = TestSetUpHelper.CreateDbContext();
            var repository      = new ManufacturerRepository(context);
            var oldManufacturer = new Manufacturer()
            {
                Id   = 4,
                Name = "TestName",
            };

            var newManufacturer = new Manufacturer()
            {
                Id   = 4,
                Name = "NewTestName",
            };

            await repository.AddAsync(oldManufacturer);

            await context.SaveChangesAsync();

            // Act
            oldManufacturer.Name = newManufacturer.Name;
            repository.Update(oldManufacturer);
            await context.SaveChangesAsync();

            // Assert
            Assert.Equal(newManufacturer.Name, oldManufacturer.Name);
        }
Exemplo n.º 3
0
        public async Task Manufacturer_Repository_Should_Get_All_Async()
        {
            // Arrange
            var context        = TestSetUpHelper.CreateDbContext();
            var repository     = new ManufacturerRepository(context);
            var expectedEntity = new Manufacturer()
            {
                Id   = 4,
                Name = "TestName",
            };

            await repository.AddAsync(expectedEntity);

            await context.SaveChangesAsync();

            // Act
            var entities = await repository.GetAllAsync();

            // Assert
            Assert.Single(entities.ToList());
        }