Example #1
0
        public async void Constructed_update_statement_uses_default_commandTimeout_can_override_not_configured_in_context_async()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFramework()
                                  .AddSqlServer()
                                  .ServiceCollection()
                                  .AddSingleton <IModificationCommandBatchFactory, TestSqlServerModificationCommandBatchFactory>()
                                  .BuildServiceProvider();

            using (var context = new ChipsContext(serviceProvider))
            {
                context.Database.EnsureCreated();

                context.Chips.Add(new KettleChips {
                    BestBuyDate = DateTime.Now, Name = "Doritos Locos Tacos"
                });
                await context.SaveChangesAsync();

                Assert.Null(GlobalCommandTimeout);

                context.Database.SetCommandTimeout(88);

                context.Chips.Add(new KettleChips {
                    BestBuyDate = DateTime.Now, Name = "Doritos Locos Tacos"
                });
                await context.SaveChangesAsync();

                Assert.Equal(88, GlobalCommandTimeout);
            }
        }
        public async void Constructed_update_statement_uses_default_commandTimeout_can_override_not_configured_in_context_async()
        {
            var serviceProvider = new ServiceCollection()
                .AddEntityFramework()
                .AddSqlServer()
                .ServiceCollection()
                .AddSingleton<SqlServerModificationCommandBatchFactory, TestSqlServerModificationCommandBatchFactory>()
                .BuildServiceProvider();

            using (var context = new ChipsContext(serviceProvider, "KettleChips"))
            {
                context.Database.EnsureCreated();

                context.Chips.Add(new KettleChips { BestBuyDate = DateTime.Now, Name = "Doritos Locos Tacos" });
                await context.SaveChangesAsync();
                Assert.Null(globalCommandTimeout);

                context.Database.AsRelational().Connection.CommandTimeout = 88;

                context.Chips.Add(new KettleChips { BestBuyDate = DateTime.Now, Name = "Doritos Locos Tacos" });
                await context.SaveChangesAsync();
                Assert.Equal(88, globalCommandTimeout);
            }
        }