|
| 1 | +using System.Data; |
1 | 2 | using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert; |
2 | 3 |
|
3 | 4 | namespace SqlServerSimulator; |
@@ -122,4 +123,51 @@ public void ParameterValue(string commandText, string name, int value) |
122 | 123 |
|
123 | 124 | AreEqual(commandText.EndsWith("+ 1") ? value + 1 : value, result); |
124 | 125 | } |
| 126 | + |
| 127 | + [TestMethod] |
| 128 | + public void AtAtVersion_ReturnsSimulatorString() |
| 129 | + => AreEqual("SQL Server Simulator", ExecuteScalar("select @@version")); |
| 130 | + |
| 131 | + [TestMethod] |
| 132 | + [DataRow(DbType.Boolean, true)] |
| 133 | + [DataRow(DbType.Boolean, false)] |
| 134 | + [DataRow(DbType.Byte, (byte)0)] |
| 135 | + [DataRow(DbType.Byte, (byte)200)] |
| 136 | + [DataRow(DbType.Int16, (short)-1)] |
| 137 | + [DataRow(DbType.Int16, (short)32000)] |
| 138 | + [DataRow(DbType.AnsiString, "ansi")] |
| 139 | + [DataRow(DbType.String, "unicodeé")] |
| 140 | + public void TypedParameter_RoundTripsThroughPagesBackend(DbType dbType, object value) |
| 141 | + { |
| 142 | + using var connection = new Simulation(StorageBackend.Pages).CreateOpenConnection(); |
| 143 | + using var command = connection.CreateCommand(); |
| 144 | + command.CommandText = "select @p"; |
| 145 | + var parameter = command.CreateParameter(); |
| 146 | + parameter.ParameterName = "p"; |
| 147 | + parameter.DbType = dbType; |
| 148 | + parameter.Value = value; |
| 149 | + _ = command.Parameters.Add(parameter); |
| 150 | + |
| 151 | + AreEqual(value, command.ExecuteScalar()); |
| 152 | + } |
| 153 | + |
| 154 | + [TestMethod] |
| 155 | + [DataRow(DbType.Boolean)] |
| 156 | + [DataRow(DbType.Byte)] |
| 157 | + [DataRow(DbType.Int16)] |
| 158 | + [DataRow(DbType.AnsiString)] |
| 159 | + [DataRow(DbType.String)] |
| 160 | + public void TypedNullParameter_ReturnsDBNull(DbType dbType) |
| 161 | + { |
| 162 | + using var connection = new Simulation(StorageBackend.Pages).CreateOpenConnection(); |
| 163 | + using var command = connection.CreateCommand(); |
| 164 | + command.CommandText = "select @p"; |
| 165 | + var parameter = command.CreateParameter(); |
| 166 | + parameter.ParameterName = "p"; |
| 167 | + parameter.DbType = dbType; |
| 168 | + parameter.Value = null; |
| 169 | + _ = command.Parameters.Add(parameter); |
| 170 | + |
| 171 | + AreEqual(DBNull.Value, command.ExecuteScalar()); |
| 172 | + } |
125 | 173 | } |
0 commit comments