Exemplo n.º 1
0
        public void Insert()
        {
            Database.CreateTable <TestModel>();

            // Populate the database with test data
            var newItems = new TestModel[10];

            for (int i = 0; i < newItems.Length; i++)
            {
                newItems[i] = new TestModel()
                {
                    Id          = i == 4 ? (int?)15 : null,
                    TextField   = "InsertTest",
                    NumberField = i
                };
            }
            Database.Insert <TestModel>(newItems);

            // Check if the primary keys have been replaced
            Assert.IsTrue(newItems.All(x => x.Id.HasValue), "The primary keys have not been updated.");

            // Check if the primary keys have the correct incrementing value
            Assert.IsTrue(newItems.Select((x, i) => x.Id == (i >= 4 ? i + 11 : i + 1)).All(x => x),
                          "The primary keys of the inserted items did not follow the expected sequence."
                          );

            // Verify inserted data with select
            var items = Database.Select <TestModel>().ToList();

            Assert.IsTrue(items.SequenceEqual(newItems), "The inserted items did not match the returned elements.");
        }