Inheritance: ChangeTrackingModelBase
Beispiel #1
0
        public void ChangeTrackingTest_NothingChanged(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new ChangeTrackingEmployee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var inserted = dataSource.Insert(EmployeeTableName, original).ToObject<ChangeTrackingEmployee>().Execute();
                Assert.IsFalse(inserted.IsChanged, "Accept changes wasn't called by the materializer");

                try
                {
                    var updated = dataSource.Update(EmployeeTableName, inserted, UpdateOptions.ChangedPropertiesOnly).ToObject<ChangeTrackingEmployee>().Execute();
                    Assert.Fail("Exception Expected");
                }
                catch (ArgumentException)
                {
                    //pass
                }
            }
            finally
            {
                Release(dataSource);
            }
        }
Beispiel #2
0
        public void ChangeTrackingTest(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new ChangeTrackingEmployee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var inserted = dataSource.Insert(EmployeeTableName, original).ToObject<ChangeTrackingEmployee>().Execute();
                Assert.IsFalse(inserted.IsChanged, "Accept changes wasn't called by the materializer");

                inserted.FirstName = "Changed";
                inserted.AcceptChanges(); //only properties changed AFTER this line should actually be updated in the database
                inserted.Title = "Also Changed";

                var updated = dataSource.Update(EmployeeTableName, inserted, UpdateOptions.ChangedPropertiesOnly).ToObject<ChangeTrackingEmployee>().Execute();
                Assert.AreEqual(original.FirstName, updated.FirstName, "FirstName shouldn't have changed");
                Assert.AreEqual(original.LastName, updated.LastName, "LastName shouldn't have changed");
                Assert.AreEqual(inserted.Title, updated.Title, "Title should have changed");

            }
            finally
            {
                Release(dataSource);
            }

        }
Beispiel #3
0
        public void UpsertTests_ChangeTrackingTest_Compiled()
        {
            var original = new ChangeTrackingEmployee()
            {
                FirstName = "Test",
                LastName = "Employee" + DateTime.Now.Ticks,
                Title = "Mail Room"
            };

            var inserted = DataSource.Upsert(EmployeeTableName, original, UpsertOptions.ChangedPropertiesOnly).Compile().ToObject<ChangeTrackingEmployee>().Execute();
            inserted.FirstName = "Changed";
            inserted.AcceptChanges(); //only properties changed AFTER this line should actually be updated in the database
            inserted.Title = "Also Changed";

            var updated = DataSource.Upsert(EmployeeTableName, inserted, UpsertOptions.ChangedPropertiesOnly).Compile().ToObject<ChangeTrackingEmployee>().Execute();
            Assert.AreEqual(original.FirstName, updated.FirstName, "FirstName shouldn't have changed");
            Assert.AreEqual(original.LastName, updated.LastName, "LastName shouldn't have changed");
            Assert.AreEqual(inserted.Title, updated.Title, "Title should have changed");


        }
Beispiel #4
0
        public void UpsertTests_ChangeTrackingTest_NothingChanged()
        {

            var original = new ChangeTrackingEmployee()
            {
                FirstName = "Test",
                LastName = "Employee" + DateTime.Now.Ticks,
                Title = "Mail Room"
            };

            var inserted = DataSource.Insert(EmployeeTableName, original).ToObject<ChangeTrackingEmployee>().Execute();

            try
            {
                var updated = DataSource.Upsert(EmployeeTableName, inserted, UpsertOptions.ChangedPropertiesOnly).ToObject<ChangeTrackingEmployee>().Execute();
                Assert.Fail("Exception Expected");
            }
            catch (ArgumentException)
            {
                //pass
            }
        }
Beispiel #5
0
        public void FailedUpdateTest(string assemblyName, string dataSourceName, DataSourceType mode)
        {

            var dataSource = DataSource(dataSourceName, mode);
            try
            {
                var original = new ChangeTrackingEmployee()
                {
                    FirstName = "Test",
                    LastName = "Employee" + DateTime.Now.Ticks,
                    Title = "Mail Room"
                };

                var inserted = dataSource.Insert(EmployeeTableName, original).ToObject<ChangeTrackingEmployee>().Execute();

                dataSource.Update(EmployeeTableName, inserted).Execute();
                dataSource.Delete(EmployeeTableName, inserted).Execute();

                try
                {
                    dataSource.Update(EmployeeTableName, inserted).Execute();
                    Assert.Fail("Expected a MissingDataException when trying to update a deleted row but didn't get one.");
                }
                catch (MissingDataException)
                {
                    //pass
                }

                dataSource.Update(EmployeeTableName, inserted, UpdateOptions.IgnoreRowsAffected).Execute(); //no error
            }
            finally
            {
                Release(dataSource);
            }
        }