Пример #1
0
        public async Task BulkInsertDefaultValuesForPropertiesAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                if (p % 2 == 0)
                {
                    result.StoreValue("Description_de", $"Description Value {0}");
                    result.ModificationDate = DateTime.Now;
                }
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items, p => p.ShadowPropertyAccessor(ShadowPropertyAccessor.Current));

            var defaultItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") == "Default").ToListAsync();

            var otherItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") != "Default").ToListAsync();

            Assert.AreEqual(50, defaultItems.Count);
            Assert.AreEqual(50, otherItems.Count);

            otherItems.ForEach(p => ((string)ctx.Entry(p).Property("Description_de").CurrentValue).StartsWith("Description Value "));
            defaultItems.ForEach(p => Assert.AreEqual(p.ModificationDate, DateTime.MinValue));
            otherItems.ForEach(p => Assert.True(p.ModificationDate > DateTime.Now.AddHours(-1)));
        }
Пример #2
0
        public async Task BulkInsertNoDefaultValueHandlingAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                if (p % 2 == 0)
                {
                    result.ModificationDate = DateTime.Now;
                }
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items, p => p.IgnoreDefaultValues());

            var defaultItems = await ctx.SimpleTableWithShadowProperty.Where(p => p.ModificationDate == null).ToListAsync();

            var otherItems = await ctx.SimpleTableWithShadowProperty.Where(p => p.ModificationDate != null).ToListAsync();

            Assert.AreEqual(50, defaultItems.Count);
            Assert.AreEqual(50, otherItems.Count);

            defaultItems.ForEach(p => Assert.False(p.ModificationDate.HasValue));
            otherItems.ForEach(p => Assert.True(p.ModificationDate > DateTime.Now.AddHours(-1)));
        }
Пример #3
0
        public async Task BulkInsertShadowPropertyEntityIncludeShadowPropertyAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                result.StoreValue("Description_de", $"Description Value {0}");
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items, p => p.ShadowPropertyAccessor(ShadowPropertyAccessor.Current));

            var allItems = await ctx.SimpleTableWithShadowProperty.ToListAsync();

            allItems.ForEach(p => ((string)ctx.Entry(p).Property("Description_de").CurrentValue).StartsWith("Description Value "));
        }
Пример #4
0
        public async Task BulkInsertShadowPropertyEntityIgnoreShadowPropertyAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            var items = Enumerable.Range(1, 100)
                        .Select(p =>
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {p}"
                };
                result.StoreValue("Description_de", $"Description Value {0}");
                return(result);
            })
                        .ToList();

            await ctx.BulkInsertAsync(items);

            var allItems = await ctx.SimpleTableWithShadowProperty.ToListAsync();

            allItems.ForEach(p => Assert.AreEqual("DEFAULT", ctx.Entry(p).Property("Description_de").CurrentValue));
        }
Пример #5
0
        public async Task SaveChanges_InsertWithDefaultValuesAsync()
        {
            var prov = GetServiceProvider();
            var ctx  = prov.GetService <TestContext>();

            for (int i = 1; i <= 100; i++)
            {
                var result = new SimpleTableWithShadowProperty
                {
                    Title = $"Title {i}"
                };

                await ctx.SimpleTableWithShadowProperty.AddAsync(result);

                var entry = ctx.Entry(result);

                if (i % 2 == 0)
                {
                    entry.Property("Description_de").CurrentValue = $"Description Value {i}";
                    result.ModificationDate = DateTime.Now;
                }
            }

            await ctx.SaveChangesAsync();

            var defaultItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") == "Default").ToListAsync();

            var otherItems = await ctx.SimpleTableWithShadowProperty.Where(p => EF.Property <string>(p, "Description_de") != "Default").ToListAsync();

            Assert.AreEqual(50, defaultItems.Count);
            Assert.AreEqual(50, otherItems.Count);

            otherItems.ForEach(p => Assert.True(((string)ctx.Entry(p).Property("Description_de").CurrentValue).StartsWith("Description Value ")));
            defaultItems.ForEach(p => Assert.AreEqual(p.ModificationDate, DateTime.MinValue));
            otherItems.ForEach(p => Assert.True(p.ModificationDate > DateTime.Now.AddHours(-1)));
        }