public void TestDbBulkInserter_NoNullCheck()
        {
            //init db
            Database.SetInitializer(new DropCreateDatabaseAlways<InsertContext>());
            var connectString = TestUtils.GetLocalDBConnectionString();
            var context = new InsertContext(connectString);
            context.Inits.Add(new Init2());
            context.SaveChanges();

            var inserter = new DbBulkInserter<Entity3>(
                connectString,
                "dbo.Seods",
                DataflowOptions.Default,
                GSProduct.SEOD);

            var guid = Guid.NewGuid();
            var entities = new Entity3[]
                               {
                                   new Entity3(1) { Key = "a", Value = 0.5f, MyLeg = new Leg() {}},
                                   new Entity3(2) { Key = "b", MyLeg = new Leg() { LegInt = 5, LegString = "bleg" } }
                               };

            var entities2 = new[]
                                {
                                    new Entity3(3)
                                        {
                                            Value = 0.7f,
                                            MyLeg = new Leg(),
                                            UID = guid,
                                            RawData = Encoding.ASCII.GetBytes("abc")
                                        }
                                };

            inserter.ProcessMultipleAsync(true, entities, entities2).Wait();

            //test result
            Assert.AreEqual(3, context.Seods.Count());
            Assert.AreEqual("b", context.Seods.Find(2).Name);
            Assert.AreEqual("b", context.Seods.Find(2).Name2);
            Assert.AreEqual(5, context.Seods.Find(2).LegInt);
            Assert.AreEqual("bleg", context.Seods.Find(2).LegString);
            Assert.AreEqual("LegString2", context.Seods.Find(2).LegString2);
            Assert.AreEqual(-2f, context.Seods.First(s => s.Id == 2).Price);
            Assert.AreEqual("default", context.Seods.First(s => s.Id == 3).Name);
            Assert.AreEqual(0.7f, context.Seods.First(s => s.Id == 3).Price);
            Assert.AreEqual(2, context.Seods.Find(3).LegInt);
            Assert.AreEqual("LegString", context.Seods.Find(3).LegString);
            Assert.AreEqual("LegString2", context.Seods.Find(3).LegString2);
            Assert.AreEqual(guid, context.Seods.Find(3).Uid);
            Assert.AreEqual("abc", Encoding.ASCII.GetString(context.Seods.Find(3).RawData));
        }
示例#2
0
        public void TestDbBulkInserter_NoNullCheck()
        {
            //init db
            var connectString = TestUtils.GetLocalDBConnectionString();
            var context       = new InsertContext(connectString);

            context.Inits.Add(new Init2());
            context.SaveChanges();

            var inserter = new DbBulkInserter <Entity3>(
                connectString,
                "dbo.Seods",
                DataflowOptions.Default,
                GSProduct.SEOD);

            var guid     = Guid.NewGuid();
            var entities = new Entity3[]
            {
                new Entity3(1)
                {
                    Key = "a", Value = 0.5f, MyLeg = new Leg()
                    {
                    }
                },
                new Entity3(2)
                {
                    Key = "b", MyLeg = new Leg()
                    {
                        LegInt = 5, LegString = "bleg"
                    }
                }
            };

            var entities2 = new[]
            {
                new Entity3(3)
                {
                    Value   = 0.7f,
                    MyLeg   = new Leg(),
                    UID     = guid,
                    RawData = Encoding.ASCII.GetBytes("abc")
                }
            };

            inserter.ProcessMultipleAsync(true, entities, entities2).Wait();

            //test result
            Assert.AreEqual(3, context.Seods.Count());
            Assert.AreEqual("b", context.Seods.Find(2).Name);
            Assert.AreEqual("b", context.Seods.Find(2).Name2);
            Assert.AreEqual(5, context.Seods.Find(2).LegInt);
            Assert.AreEqual("bleg", context.Seods.Find(2).LegString);
            Assert.AreEqual("LegString2", context.Seods.Find(2).LegString2);
            Assert.AreEqual(-2f, context.Seods.First(s => s.Id == 2).Price);
            Assert.AreEqual("default", context.Seods.First(s => s.Id == 3).Name);
            Assert.AreEqual(0.7f, context.Seods.First(s => s.Id == 3).Price);
            Assert.AreEqual(2, context.Seods.Find(3).LegInt);
            Assert.AreEqual("LegString", context.Seods.Find(3).LegString);
            Assert.AreEqual("LegString2", context.Seods.Find(3).LegString2);
            Assert.AreEqual(guid, context.Seods.Find(3).Uid);
            Assert.AreEqual("abc", Encoding.ASCII.GetString(context.Seods.Find(3).RawData));
        }