public void ExternalTransactionComplete()
        {
            using (var scope = Database.GetTransaction())
            {
                var user = new UserDecorated
                {
                    Name = "Name" + 16,
                    Age = 20 + 16,
                    DateOfBirth = new DateTime(1970, 1, 1).AddYears(16),
                    Savings = 50.00m + (1.01m * 16)
                };
                InMemoryUsers.Add(user);
                Database.Insert(user);

                var extra = new ExtraUserInfoDecorated
                {
                    UserId = user.UserId,
                    Email = "email" + 16 + "@email.com",
                    Children = 16
                };
                InMemoryExtraUserInfos.Add(extra);
                Database.Insert(extra);

                scope.Complete();
            }

            var count = Database.ExecuteScalar<long>("SELECT COUNT(*) FROM Users");
            Assert.AreEqual(count, 16);
        }
Example #2
0
        protected void InsertData()
        {
            InMemoryUsers            = new List <UserDecorated>();
            InMemoryExtraUserInfos   = new List <ExtraUserInfoDecorated>();
            InMemoryCompositeObjects = new List <CompositeObjectDecorated>();

            for (var i = 0; i < 15; i++)
            {
                var pos = i + 1;

                var user = new UserDecorated
                {
                    Name        = "Name" + (i + 1),
                    Age         = 20 + (i + 1),
                    DateOfBirth = new DateTime(1970, 1, 1).AddYears(i + 1),
                    Savings     = 50.00m + (1.01m * (i + 1)),
                    IsMale      = (i % 2 == 0)
                };
                Database.Insert(user);
                InMemoryUsers.Add(user);

                var extra = new ExtraUserInfoDecorated
                {
                    UserId   = user.UserId,
                    Email    = "email" + (i + 1) + "@email.com",
                    Children = (i + 1)
                };
                Database.Insert(extra);
                InMemoryExtraUserInfos.Add(extra);

                var composite = new CompositeObjectDecorated
                {
                    Key1ID      = pos,
                    Key2ID      = i + 2,
                    Key3ID      = i + 4,
                    TextData    = "This is some text data.",
                    DateEntered = DateTime.Now
                };
                Database.Insert(composite);
                InMemoryCompositeObjects.Add(composite);
            }

            // Verify DB record counts
            var userCount = Database.ExecuteScalar <int>("SELECT COUNT(UserId) FROM Users");

            Assert.AreEqual(InMemoryUsers.Count, userCount, "Test User Data not in sync db has " + userCount + " records, but the in memory copy has only " + InMemoryUsers.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userCount + " test users for the unit tests.");

            var userExtraInfoCount = Database.ExecuteScalar <int>("SELECT COUNT(ExtraUserInfoId) FROM ExtraUserInfos");

            Assert.AreEqual(InMemoryExtraUserInfos.Count, userExtraInfoCount, "Test User Extra Info Data not in sync db has " + userExtraInfoCount + " records, but the in memory copy has only " + InMemoryExtraUserInfos.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userExtraInfoCount + " test extra user info records for the unit tests.");

            var compositeObjectCount = Database.ExecuteScalar <int>("SELECT COUNT(Key1ID) FROM CompositeObjects");

            Assert.AreEqual(InMemoryCompositeObjects.Count, compositeObjectCount, "Test Composite Object Data not in sync db has " + compositeObjectCount + " records, but the in memory copy has only " + InMemoryCompositeObjects.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + compositeObjectCount + " test composite PK objects for the unit tests.");
        }
Example #3
0
        protected void InsertData()
        {
            InMemoryUsers            = new List <UserDecorated>();
            InMemoryExtraUserInfos   = new List <ExtraUserInfoDecorated>();
            InMemoryCompositeObjects = new List <CompositeObjectDecorated>();
            InMemoryHouses           = new List <HouseDecorated>();

            for (var i = 0; i < 5; i++)
            {
                var house = new HouseDecorated()
                {
                    Address = i + " Road Street, Suburb"
                };
                Database.Insert(house);
                InMemoryHouses.Add(house);
            }

            for (var i = 0; i < 15; i++)
            {
                var pos = i + 1;

                var user = new UserDecorated
                {
                    Name        = "Name" + (i + 1),
                    Age         = 20 + (i + 1),
                    DateOfBirth = new DateTime(1970, 1, 1).AddYears(i + 1),
                    Savings     = 50.00m + (1.01m * (i + 1)),
                    IsMale      = (i % 2 == 0),
                    HouseId     = i % 2 == 0 ? (int?)null : InMemoryHouses[i % 5].HouseId
                };
                Database.Insert(user);
                InMemoryUsers.Add(user);

                var extra = new ExtraUserInfoDecorated
                {
                    UserId   = user.UserId,
                    Email    = "email" + (i + 1) + "@email.com",
                    Children = (i + 1)
                };
                Database.Insert(extra);
                InMemoryExtraUserInfos.Add(extra);

                var composite = new CompositeObjectDecorated
                {
                    Key1ID      = pos,
                    Key2ID      = i + 2,
                    Key3ID      = i + 4,
                    TextData    = "This is some text data.",
                    DateEntered = DateTime.Now
                };
                Database.Insert(composite);
                InMemoryCompositeObjects.Add(composite);

                var recursionUser = new RecursionUser
                {
                    Name      = "Name" + (i + 1),
                    CreatedBy = new RecursionUser()
                    {
                        Id = 1
                    },
                    Supervisor = new RecursionUser()
                    {
                        Id = 2
                    }
                };
                Database.Insert(recursionUser);

                var one = new One()
                {
                    Name = "Name" + (i + 1),
                };
                Database.Insert(one);

                for (int j = 0; j < (i % 3); j++)
                {
                    var many = new Many()
                    {
                        OneId    = one.OneId,
                        Currency = "Cur" + (i + j + 1),
                        AValue   = (i + j + 1)
                    };
                    Database.Insert(many);
                }

                var userWithAddress = new UserWithAddress()
                {
                    Name    = "Name" + (i + 1),
                    Address = new UserWithAddress.MyAddress()
                    {
                        StreetNo           = i + 1,
                        StreetName         = "Street" + (i + 1),
                        MovedInOn          = new DateTime(1970, 1, 1).AddYears(i + 1),
                        AddressFurtherInfo = new UserWithAddress.MyAddress.AddressInfo()
                        {
                            PostCode = "99999"
                        }
                    }
                };

                Database.Insert(userWithAddress);
            }

            // Verify DB record counts
            var userCount = Database.ExecuteScalar <int>("SELECT COUNT(UserId) FROM Users");

            Assert.AreEqual(InMemoryUsers.Count, userCount, "Test User Data not in sync db has " + userCount + " records, but the in memory copy has only " + InMemoryUsers.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userCount + " test users for the unit tests.");

            var userExtraInfoCount = Database.ExecuteScalar <int>("SELECT COUNT(ExtraUserInfoId) FROM ExtraUserInfos");

            Assert.AreEqual(InMemoryExtraUserInfos.Count, userExtraInfoCount, "Test User Extra Info Data not in sync db has " + userExtraInfoCount + " records, but the in memory copy has only " + InMemoryExtraUserInfos.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userExtraInfoCount + " test extra user info records for the unit tests.");

            var compositeObjectCount = Database.ExecuteScalar <int>("SELECT COUNT(Key1_ID) FROM CompositeObjects");

            Assert.AreEqual(InMemoryCompositeObjects.Count, compositeObjectCount, "Test Composite Object Data not in sync db has " + compositeObjectCount + " records, but the in memory copy has only " + InMemoryCompositeObjects.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + compositeObjectCount + " test composite PK objects for the unit tests.");
        }
        public void NestedTransactionThatFailsAbortsWholeUsingBeginAbort()
        {
            Database.BeginTransaction();
            Database.BeginTransaction();


            var user1 = new UserDecorated
            {
                Name = "Name" + 16,
                Age = 20 + 16,
                DateOfBirth = new DateTime(1970, 1, 1).AddYears(16),
                Savings = 50.00m + (1.01m * 16)
            };
            InMemoryUsers.Add(user1);
            Database.Insert(user1);

            var extra1 = new ExtraUserInfoDecorated
            {
                UserId = user1.UserId,
                Email = "email" + 16 + "@email.com",
                Children = 16
            };
            InMemoryExtraUserInfos.Add(extra1);
            Database.Insert(extra1);

            Database.AbortTransaction();

            var user = new UserDecorated
            {
                Name = "Name" + 16,
                Age = 20 + 16,
                DateOfBirth = new DateTime(1970, 1, 1).AddYears(16),
                Savings = 50.00m + (1.01m * 16)
            };
            InMemoryUsers.Add(user);
            Database.Insert(user);

            var extra = new ExtraUserInfoDecorated
            {
                UserId = user.UserId,
                Email = "email" + 16 + "@email.com",
                Children = 16
            };
            InMemoryExtraUserInfos.Add(extra);
            Database.Insert(extra);

            Database.CompleteTransaction();

            var count = Database.ExecuteScalar<long>("SELECT COUNT(*) FROM Users");
            Assert.AreEqual(15, count);
        }
        protected void InsertData()
        {
            InMemoryUsers = new List<UserDecorated>();
            InMemoryExtraUserInfos = new List<ExtraUserInfoDecorated>();
            InMemoryCompositeObjects = new List<CompositeObjectDecorated>();

            for (var i = 0; i < 15; i++)
            {
                var pos = i + 1;

                var user = new UserDecorated
                {
                    Name = "Name" + (i + 1),
                    Age = 20 + (i + 1),
                    DateOfBirth = new DateTime(1970, 1, 1).AddYears(i + 1),
                    Savings = 50.00m + (1.01m * (i + 1)),
                    IsMale = (i%2==0)
                };
                Database.Insert(user);
                InMemoryUsers.Add(user);

                var extra = new ExtraUserInfoDecorated
                {
                    UserId = user.UserId,
                    Email = "email" + (i + 1) + "@email.com",
                    Children = (i + 1)
                };
                Database.Insert(extra);
                InMemoryExtraUserInfos.Add(extra);

                var composite = new CompositeObjectDecorated
                {
                    Key1ID = pos,
                    Key2ID = i + 2,
                    Key3ID = i + 4,
                    TextData = "This is some text data.",
                    DateEntered = DateTime.Now
                };
                Database.Insert(composite);
                InMemoryCompositeObjects.Add(composite);
            }

            // Verify DB record counts
            var userCount = Database.ExecuteScalar<int>("SELECT COUNT(UserId) FROM Users");
            Assert.AreEqual(InMemoryUsers.Count, userCount, "Test User Data not in sync db has " + userCount + " records, but the in memory copy has only " + InMemoryUsers.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userCount + " test users for the unit tests.");

            var userExtraInfoCount = Database.ExecuteScalar<int>("SELECT COUNT(ExtraUserInfoId) FROM ExtraUserInfos");
            Assert.AreEqual(InMemoryExtraUserInfos.Count, userExtraInfoCount, "Test User Extra Info Data not in sync db has " + userExtraInfoCount + " records, but the in memory copy has only " + InMemoryExtraUserInfos.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userExtraInfoCount + " test extra user info records for the unit tests.");

            var compositeObjectCount = Database.ExecuteScalar<int>("SELECT COUNT(Key1ID) FROM CompositeObjects");
            Assert.AreEqual(InMemoryCompositeObjects.Count, compositeObjectCount, "Test Composite Object Data not in sync db has " + compositeObjectCount + " records, but the in memory copy has only " + InMemoryCompositeObjects.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + compositeObjectCount + " test composite PK objects for the unit tests.");
        }
Example #6
0
        protected void InsertData()
        {
            InMemoryUsers = new List<UserDecorated>();
            InMemoryExtraUserInfos = new List<ExtraUserInfoDecorated>();
            InMemoryCompositeObjects = new List<CompositeObjectDecorated>();
            InMemoryHouses = new List<HouseDecorated>();

            for (var i = 0; i < 5; i++)
            {
                var house = new HouseDecorated()
                {
                    Address = i + " Road Street, Suburb"
                };
                Database.Insert(house);
                InMemoryHouses.Add(house);
            }

            for (var i = 0; i < 15; i++)
            {
                var pos = i + 1;

                var user = new UserDecorated
                {
                    Name = "Name" + (i + 1),
                    Age = 20 + (i + 1),
                    DateOfBirth = new DateTime(1970, 1, 1).AddYears(i + 1),
                    Savings = 50.00m + (1.01m * (i + 1)),
                    IsMale = (i%2==0),
                    HouseId = i % 2 == 0 ? (int?)null : InMemoryHouses[i % 5].HouseId
                };
                Database.Insert(user);
                InMemoryUsers.Add(user);

                var extra = new ExtraUserInfoDecorated
                {
                    UserId = user.UserId,
                    Email = "email" + (i + 1) + "@email.com",
                    Children = (i + 1)
                };
                Database.Insert(extra);
                InMemoryExtraUserInfos.Add(extra);

                var composite = new CompositeObjectDecorated
                {
                    Key1ID = pos,
                    Key2ID = i + 2,
                    Key3ID = i + 4,
                    TextData = "This is some text data.",
                    DateEntered = DateTime.Now
                };
                Database.Insert(composite);
                InMemoryCompositeObjects.Add(composite);

                var recursionUser = new RecursionUser
                {
                    Name = "Name" + (i + 1),
                    CreatedBy = new RecursionUser() {Id = 1},
                    Supervisor = new RecursionUser() {Id = 2}
                };
                Database.Insert(recursionUser);

                var one = new One()
                {
                    Name = "Name" + (i + 1),
                };
                Database.Insert(one);

                for (int j = 0; j < (i%3); j++)
                {
                    var many = new Many()
                    {
                        OneId = one.OneId,
                        Currency = "Cur" + (i + j + 1),
                        Value = (i + j + 1)
                    };
                    Database.Insert(many);
                }

                var userWithAddress = new UserWithAddress()
                {
                    Name = "Name" + (i + 1),
                    Address = new UserWithAddress.MyAddress()
                    {
                        StreetNo = i + 1,
                        StreetName = "Street" + (i + 1),
                        MovedInOn = new DateTime(1970, 1, 1).AddYears(i + 1),
                        AddressFurtherInfo = new UserWithAddress.MyAddress.AddressInfo()
                        {
                            PostCode = "99999"
                        }
                    }
                };

                Database.Insert(userWithAddress);
            }

            // Verify DB record counts
            var userCount = Database.ExecuteScalar<int>("SELECT COUNT(UserId) FROM Users");
            Assert.AreEqual(InMemoryUsers.Count, userCount, "Test User Data not in sync db has " + userCount + " records, but the in memory copy has only " + InMemoryUsers.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userCount + " test users for the unit tests.");

            var userExtraInfoCount = Database.ExecuteScalar<int>("SELECT COUNT(ExtraUserInfoId) FROM ExtraUserInfos");
            Assert.AreEqual(InMemoryExtraUserInfos.Count, userExtraInfoCount, "Test User Extra Info Data not in sync db has " + userExtraInfoCount + " records, but the in memory copy has only " + InMemoryExtraUserInfos.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + userExtraInfoCount + " test extra user info records for the unit tests.");

            var compositeObjectCount = Database.ExecuteScalar<int>("SELECT COUNT(Key1_ID) FROM CompositeObjects");
            Assert.AreEqual(InMemoryCompositeObjects.Count, compositeObjectCount, "Test Composite Object Data not in sync db has " + compositeObjectCount + " records, but the in memory copy has only " + InMemoryCompositeObjects.Count + " records.");
            System.Diagnostics.Debug.WriteLine("Created " + compositeObjectCount + " test composite PK objects for the unit tests.");
        }