Example #1
0
        public async Task DeletingProductionInformation()
        {
            var options = CreateInMemoryDbOptions("DeletingProductionInformation");

            // Run the test against one instance of the context
            await using (var context = new ApplicationDbContext(options))
            {
                var service = new ProductionInformationService(context);

                var productionInformations = GenerateManyProductionInformations(5);
                productionInformations.ForEach(async pi => await service.CreateAsync(pi));
            }

            await using (var context = new ApplicationDbContext(options))
            {
                var service = new ProductionInformationService(context);
                var productionInformations = await service.GetAsync();

                Assert.Equal(5, productionInformations.Count);
            }

            await using (var context = new ApplicationDbContext(options))
            {
                var service = new ProductionInformationService(context);
                var productionInformation = context.ProductionInformations.FirstOrDefault();
                var success = await service.DeleteAsync(productionInformation);

                Assert.True(success);
                var productionInformations = await service.GetAsync();

                Assert.Equal(4, productionInformations.Count);
            }
        }
Example #2
0
        public async Task Create_ProductionInformation()
        {
            var options = CreateInMemoryDbOptions("Create_ProductionInformation");

            // Run the test against one instance of the context
            await using (var context = new ApplicationDbContext(options))
            {
                var service = new ProductionInformationService(context);
                var productionInformation = GenerateProductionInformation();
                await service.CreateAsync(productionInformation);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            await using (var context = new ApplicationDbContext(options))
            {
                var service = new ProductionInformationService(context);
                Assert.Equal(1, context.ProductionInformations.Count());
                Assert.Equal("TestCompany0",
                             (await service.GetAsync())
                             .Single().Customer.CompanyName);
            }
        }