Example #1
0
        public void DictionaryWithParametersValue_ReturnsCorrectlyComposedSqlParameters()
        {
            // Arrange
            var sqlServerProvider = new SqlServerProvider();
            var parametersDictionary = new Dictionary<string, object>
            {
                {"TestParameterInt", 123},
                {"TestParameterString", "TestStringValue"}
            };

            // Act
            IEnumerable<IDataParameter> parameters = sqlServerProvider.CreateParameters(parametersDictionary);

            // Assert
            var sqlParameterInt = parameters.ElementAt(0) as SqlParameter;
            var sqlParameterString = parameters.ElementAt(1) as SqlParameter;

            Assert.IsNotNull(sqlParameterInt);
            Assert.AreEqual("@TestParameterInt", sqlParameterInt.ParameterName);
            Assert.AreEqual(123, sqlParameterInt.Value);

            Assert.IsNotNull(sqlParameterString);
            Assert.AreEqual("@TestParameterString", sqlParameterString.ParameterName);
            Assert.AreEqual("TestStringValue", sqlParameterString.Value);
        }
Example #2
0
        public void ConnectionString_ReturnsSqlConnection()
        {
            // Arrange
            var sqlServerProvider = new SqlServerProvider(TestConnectionString);

            // Act
            var sqlConnection = sqlServerProvider.CreateConnection();

            // Assert
            Assert.IsInstanceOf<SqlConnection>(sqlConnection);
            Assert.AreEqual(TestConnectionString, sqlConnection.ConnectionString);
        }
Example #3
0
        public void QuerySqlConnectionAndCommandType_ReturnsCorrectlyComposedSqlCommand()
        {
            // Arrange
            var sqlServerProvider = new SqlServerProvider(TestConnectionString) {CommandTimeout = CommandTimeout};
            var mockSqlConnection = new SqlConnection(TestConnectionString);

            // Act
            var command = sqlServerProvider.CreateCommand(SelectQuery, mockSqlConnection, CommandType.Text);

            // Assert
            Assert.IsInstanceOf<SqlCommand>(command);
            Assert.AreEqual(SelectQuery, command.CommandText);
            Assert.AreEqual(mockSqlConnection, command.Connection);
            Assert.AreEqual(CommandType.Text, command.CommandType);
            Assert.AreEqual(CommandTimeout, command.CommandTimeout);
        }