Exemplo n.º 1
0
        public void SqlServerInsertQuery_ShouldGenQuery()
        {
            // Arrange
            var command = new System.Data.SqlClient.SqlCommand();
            ColumnMapCollection columns = MapRepository.Instance.GetColumns(typeof(Person));
            MappingHelper mappingHelper = new MappingHelper(command);

            Person person = new Person();
            person.ID = 1;
            person.Name = "Jordan";
            person.Age = 33;
            person.IsHappy = true;
            person.BirthDate = new DateTime(1977, 1, 22);

            mappingHelper.CreateParameters<Person>(person, columns, false, true);

            IQuery query = new SqlServerInsertQuery(columns, command, "dbo.People");

            // Act
            string queryText = query.Generate();

            // Assert
            Assert.IsNotNull(queryText);
            Assert.IsTrue(queryText.Contains("INSERT INTO dbo.People"));
            Assert.IsFalse(queryText.Contains("[ID]"), "Should not contain [ID] column since it is marked as AutoIncrement");
            Assert.IsTrue(queryText.Contains("[Name]"), "Should contain the name column");
        }
Exemplo n.º 2
0
        public void SqlServerInsertQuery_ShouldGenQuery()
        {
            // Arrange
            var command = new System.Data.SqlClient.SqlCommand();
            ColumnMapCollection columns       = MapRepository.Instance.GetColumns(typeof(Person));
            MappingHelper       mappingHelper = new MappingHelper(command);

            Person person = new Person();

            person.ID        = 1;
            person.Name      = "Jordan";
            person.Age       = 33;
            person.IsHappy   = true;
            person.BirthDate = new DateTime(1977, 1, 22);

            mappingHelper.CreateParameters <Person>(person, columns, false, true);

            IQuery query = new SqlServerInsertQuery(columns, command, "dbo.People");

            // Act
            string queryText = query.Generate();

            // Assert
            Assert.IsNotNull(queryText);
            Assert.IsTrue(queryText.Contains("INSERT INTO dbo.People"));
            Assert.IsFalse(queryText.Contains("[ID]"), "Should not contain [ID] column since it is marked as AutoIncrement");
            Assert.IsTrue(queryText.Contains("[Name]"), "Should contain the name column");
        }