public void Updating_Data_Without_Filter_Works()
        {
            using (_Connection)
            {
                Person person = new Person()
                {
                    Name = "UpdateTest", DateOfBirth = DateTime.Today,
                };

                UpdateCommand <Person> cmd = new UpdateCommand <Person>(_Connection, "People");
                cmd.CreateDynamicMappings();
                cmd.RemoveMapping("Id");
                cmd.Execute(person);

                // get expected value
                var expectedCmd = _Connection.CreateCommand();
                expectedCmd.CommandText = @"
SELECT COUNT(*) FROM People";

                // check
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"
SELECT COUNT(*) FROM People WHERE Name = 'UpdateTest'";

                Assert.AreEqual(expectedCmd.ExecuteScalar(), checkCmd.ExecuteScalar());
            }
        }
        public void Updating_Data_With_Key_Filter_Works()
        {
            using (_Connection)
            {
                Person person = new Person()
                {
                    Id = 2, Name = "UpdateTest", DateOfBirth = DateTime.Today,
                };

                UpdateCommand <Person> cmd = new UpdateCommand <Person>(_Connection, "People");
                cmd.CreateDynamicMappings();
                cmd.MapKey("Id", p => p.Id);
                cmd.Execute(person);

                // check whether the right record was updated
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"
SELECT COUNT(*) FROM People WHERE Name = 'UpdateTest' AND Id = 2";

                Assert.AreEqual(1, checkCmd.ExecuteScalar());

                // check whether only one record was updated
                var check2Cmd = _Connection.CreateCommand();
                check2Cmd.CommandText = @"
SELECT COUNT(*) FROM People WHERE Name = 'UpdateTest'";

                Assert.AreEqual(1, check2Cmd.ExecuteScalar());
            }
        }
        public void Updating_Data_With_Filter_Condition_Works()
        {
            using (_Connection)
            {
                // get expected value
                var expectedCmd = _Connection.CreateCommand();
                expectedCmd.CommandText = @"
SELECT COUNT(*) FROM People WHERE IsMarried = 1";

                int numberOfPeopleBeforeUpdate = Convert.ToInt32(expectedCmd.ExecuteScalar());

                Person person = new Person()
                {
                    Name = "UpdateTest", IsMarried = true, DateOfBirth = DateTime.Today,
                };

                UpdateCommand <Person> cmd = new UpdateCommand <Person>(_Connection, "People");
                cmd.CreateDynamicMappings();
                cmd.RemoveMapping("Id");
                cmd.Filter = new FilterComparison("IsMarried", FilterComparisonOperatorEnum.ExactlyEqual, true);
                cmd.Execute(person);

                // check
                var checkCmd = _Connection.CreateCommand();
                checkCmd.CommandText = @"
SELECT COUNT(*) FROM People WHERE Name = 'UpdateTest'";

                Assert.AreEqual(numberOfPeopleBeforeUpdate, checkCmd.ExecuteScalar());
            }
        }