public void TestStringDataTypesInsert()
        {
            // Setup
            var data = new Models.TypeMap
            {
                char_column        = "char text",
                nchar_column       = "nchar text",
                ntext_column       = "ntext text",
                nvarchar_column    = "nvarchar  text",
                nvarcharmax_column = "nvarcharmax text",
                text_column        = "text text",
                varchar_column     = "varchar text",
                varcharmax_column  = "varcharmax text",
                uniqueidentifier   = Guid.NewGuid()
            };

            // Act
            var sut    = new DbRepository <SqlConnection>(Constants.TestDatabase);
            var id     = sut.Insert(data);
            var result = sut.Query <Models.TypeMap>(top: 1).FirstOrDefault();

            // Assert
            result.ShouldNotBeNull();
            result.char_column.ShouldContain(data.char_column);;
            result.nchar_column.ShouldContain(data.nchar_column);
            result.ntext_column.ShouldBe(data.ntext_column);
            result.nvarchar_column.ShouldBe(data.nvarchar_column);
            result.nvarcharmax_column.ShouldBe(data.nvarcharmax_column);
            result.text_column.ShouldBe(data.text_column);
            result.varchar_column.ShouldBe(data.varchar_column);
            result.varcharmax_column.ShouldBe(data.varcharmax_column);
            result.uniqueidentifier.ShouldBe(data.uniqueidentifier);
        }
示例#2
0
        public void TestDateTimeDataTypes()
        {
            //arrange
            var baseTime = DateTime.UtcNow.Date.AddHours(10).AddMinutes(20).AddSeconds(30).AddMilliseconds(123456789);

            var dateTimeOffset = new DateTimeOffset(2007, 11, 22, 16, 0, 0, new TimeSpan(-5, 0, 0));
            var time           = baseTime.TimeOfDay;

            var fixtureData = new Models.TypeMap
            {
                date_column           = baseTime.Date,
                datetime_column       = baseTime,
                datetime2_column      = baseTime,
                datetimeoffset_column = dateTimeOffset,
                smalldatetime_column  = baseTime,
                time_column           = time
            };

            //act
            var sut        = new DbRepository <SqlConnection>(Constants.TestDatabase);
            var returnedId = sut.Insert(fixtureData);

            //TODO: support guid primary key

            //assert
            var saveData = sut.Query <Models.TypeMap>(top: 1).FirstOrDefault();

            saveData.ShouldNotBeNull();
            saveData.date_column.ShouldBe(fixtureData.date_column);
            saveData.datetime_column.ShouldBeEx(fixtureData.datetime_column);
            saveData.datetime2_column.ShouldBeEx(fixtureData.datetime2_column);
            saveData.datetimeoffset_column.ShouldBe(fixtureData.datetimeoffset_column);
            saveData.smalldatetime_column.ShouldBeEx(fixtureData.smalldatetime_column);
            saveData.time_column.Value.TotalMilliseconds.ShouldBe(fixtureData.time_column.Value.TotalMilliseconds);
        }
示例#3
0
        public void TestNumericDataTypesInsert()
        {
            //arrange
            var fixtureData = new Models.TypeMap
            {
                bigint_column     = 123456789,
                bit_column        = true,
                decimal_column    = 12345.6789m,
                float_column      = 12345.6789,
                int_column        = 123456789,
                money_column      = 12345.6789m,
                numeric_column    = 12345.6789m,
                real_column       = 12345,
                smallint_column   = 123,
                smallmoney_column = 12345.6789m,
                tinyint_column    = 12
            };

            //act
            var sut        = new DbRepository <SqlConnection>(Constants.TestDatabase);
            var returnedId = sut.Insert(fixtureData);

            //assert
            var saveData = sut.Query <Models.TypeMap>(top: 1).FirstOrDefault();

            saveData.ShouldNotBeNull();
            saveData.bigint_column.ShouldBe(fixtureData.bigint_column);
            saveData.bit_column.ShouldBe(fixtureData.bit_column);
            saveData.decimal_column.ShouldBe(fixtureData.decimal_column);
            saveData.float_column.ShouldBe(fixtureData.float_column);
            saveData.int_column.ShouldBe(fixtureData.int_column);
            saveData.money_column.ShouldBe(fixtureData.money_column);
            saveData.numeric_column.ShouldBe(fixtureData.numeric_column);
            saveData.real_column.ShouldBe(fixtureData.real_column);
            saveData.smallint_column.ShouldBe(fixtureData.smallint_column);
            saveData.smallmoney_column.ShouldBe(fixtureData.smallmoney_column);
            saveData.tinyint_column.ShouldBe(fixtureData.tinyint_column);
        }
示例#4
0
        public void TestStringDataTypesInsert()
        {
            //arrange
            var fixtureData = new Models.TypeMap
            {
                char_column        = "char text",
                nchar_column       = "nchar text",
                ntext_column       = "ntext text",
                nvarchar_column    = "nvarchar  text",
                nvarcharmax_column = "nvarcharmax text",
                text_column        = "text text",
                varchar_column     = "varchar text",
                varcharmax_column  = "varcharmax text",
                uniqueidentifier   = Guid.NewGuid()
            };

            //act
            var sut        = new DbRepository <SqlConnection>(Constants.TestDatabase);
            var returnedId = sut.Insert(fixtureData);

            //TODO: support guid primary key

            //assert
            var saveData = sut.Query <Models.TypeMap>(top: 1).FirstOrDefault();

            saveData.ShouldNotBeNull();
            saveData.char_column.ShouldContain(fixtureData.char_column);;
            saveData.nchar_column.ShouldContain(fixtureData.nchar_column);
            saveData.ntext_column.ShouldBe(fixtureData.ntext_column);
            saveData.nvarchar_column.ShouldBe(fixtureData.nvarchar_column);
            saveData.nvarcharmax_column.ShouldBe(fixtureData.nvarcharmax_column);
            saveData.text_column.ShouldBe(fixtureData.text_column);
            saveData.varchar_column.ShouldBe(fixtureData.varchar_column);
            saveData.varcharmax_column.ShouldBe(fixtureData.varcharmax_column);
            saveData.uniqueidentifier.ShouldBe(fixtureData.uniqueidentifier);
        }