Beispiel #1
0
        public void UpdateStatementWithNoChanges()
        {
            var factory = new SqlCommandFactory(new StubAuditor());
            var changes = new Dictionary <string, PropertyChange>();

            Assert.Throws <InvalidOperationException>(() => factory.CreateUpdateStatement(changes, "[dbo].[Blog]", "Id", 4));
        }
Beispiel #2
0
        public void UpdateStatementTest()
        {
            var expectedSql        = @"UPDATE [dbo].[Blog] SET [Name] = @Name, [UpdatedBy] = @UpdatedBy, [UpdatedOn] = @UpdatedOn WHERE [Id] = @Id";
            var expectedUserId     = Guid.NewGuid();
            var expectedCreateDate = DateTime.Now;
            var auditor            = new StubAuditor(expectedUserId, () => expectedCreateDate);
            var factory            = new SqlCommandFactory(auditor);
            var changes            = new Dictionary <string, PropertyChange>()
            {
                { "Name", new PropertyChange("A", "B") }
            };
            var command = factory.CreateUpdateStatement(changes, "[dbo].[Blog]", "Id", 4);

            Assert.Equal(expectedSql, command.CommandText);
            Assert.Equal(expectedUserId, command.Parameters["UpdatedBy"].Value);
            Assert.Equal(expectedCreateDate, command.Parameters["UpdatedOn"].Value);
            Assert.Equal("B", command.Parameters["Name"].Value);
        }