Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Dec 11, 2014
2 parents 41ce9b5 + 9ea1624 commit 089a785
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 76 deletions.
14 changes: 10 additions & 4 deletions NBi.Core/ConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ public IDbConnection Get(string connectionString)
var csb = new DbConnectionStringBuilder();
csb.ConnectionString = connectionString;

string providerName=
csb.ContainsKey("Provider") ? providerName = InterpretProviderName(csb["Provider"].ToString()) : providerName = "SqlClient";
string providerName = string.Empty;
if (csb.ContainsKey("Provider"))
providerName = InterpretProviderName(csb["Provider"].ToString());

if (string.IsNullOrEmpty(providerName) && csb.ContainsKey("Driver"))
providerName= "Odbc";

if (string.IsNullOrEmpty(providerName))
providerName="SqlClient";

if (string.IsNullOrEmpty(providerName))
throw new ArgumentException(string.Format("No provider found for connectionString '{0}'", connectionString));
Expand All @@ -29,9 +36,8 @@ public IDbConnection Get(string connectionString)
protected string InterpretProviderName(string provider)
{
if (provider.ToLowerInvariant().StartsWith("msolap")) return "Adomd";
if (provider.ToLowerInvariant().StartsWith("sqlncli")) return "OleDb";
if (provider.ToLowerInvariant().StartsWith("sqlncli")) return "OleDb"; //Indeed OleDb it's not a mistake!
if (provider.ToLowerInvariant().StartsWith("oledb")) return "OleDb";
if (provider.StartsWith("Driver={")) return "Odbc";

return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<testSuite name="Acceptance Testing: query equalTo with parameters" xmlns="http://NBi/TestSuite">
<settings>
<default apply-to="system-under-test">
<connectionString>Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly</connectionString>
<parameter name="@CurrencyCode" sql-type="varchar">AED</parameter>
</default>
</settings>
<test name="Test">
<system-under-test>
<execution>
<query>
<![CDATA[SELECT COUNT(*) From [Sales].[Currency] WHERE CurrencyCode = @CurrencyCode]]>
</query>
</execution>
</system-under-test>
<assert>
<equalTo>
<resultSet>
<row>
<cell>1</cell>
</row>
</resultSet>
</equalTo>
</assert>
</test>
</testSuite>
1 change: 1 addition & 0 deletions NBi.Testing/Acceptance/RuntimeOverrider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void SetupMethods()
//By Acceptance Test Suite (file) create a Test Case
[Test]
[TestCase("AssemblyEqualToResultSet.nbits")]
[TestCase("QueryEqualToWithParameter.nbits")]
[TestCase("QueryEqualToCsv.nbits")]
[TestCase("QueryEqualToQuery.nbits")]
[TestCase("QueryEqualToResultSet.nbits")]
Expand Down
3 changes: 3 additions & 0 deletions NBi.Testing/NBi.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@
<EmbeddedResource Include="Acceptance\GenbiL\Resources\CaseCross-TestSuiteBuild.genbil">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Acceptance\Resources\Positive\QueryEqualToWithParameter.nbits">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Acceptance\Resources\Reports\EmployeeSalesDetail.rsd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
100 changes: 28 additions & 72 deletions NBi.Testing/Unit/Core/ConnectionFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,131 +43,99 @@ public void TearDownTest()
#endregion

[Test]
public void Get_OleDbMsOlap_OleDbConnection()
public void Get_MsOlap_OleDbConnection()
{
//Call the method to test
var connStr = "Provider=MSOLAP;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get("OleDb", connStr);
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual, Is.InstanceOf<AdomdConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_OleDbWithIncorrectCase_OledbConnection()
public void Get_MsOlapDot4_OledbConnection()
{
//Call the method to test
var connStr = "Provider=MSOLAP;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get("OleDb", connStr);
var connStr = "Provider=msOlaP.4;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual, Is.InstanceOf<AdomdConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_SystemDataOleDb_OledbConnection()
public void Get_OleDb_OledbConnection()
{
//Call the method to test
var connStr = "Provider=MSOLAP;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get("System.Data.OleDb", connStr);
var connStr = "Provider=OledB;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_OleDbSqlNCli_OledbConnection()
public void Get_SqlNCli_OleDbConnection()
{
//Call the method to test
var connStr = "Provider=SQLNCLI;Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get("OleDb", connStr);
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_Odbc_OdbcConnection()
{
//Call the method to test
var connStr = "Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";
var actual = new ConnectionFactory().Get("Odbc", connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OdbcConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_SqlClient_SqlConnection()
public void Get_SqlNCli10Dot1_OleDbConnection()
{
var connStr = "Data Source=ds;Initial Catalog=ic";

//Call the method to test
var actual = new ConnectionFactory().Get("SqlClient", connStr);
var connStr = "Provider=SQLNCLI10.1;Data Source=ds;Initial Catalog=ic;Integrated Security=SSPI;";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<SqlConnection>());
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}


[Test]
public void Get_Adomd_SqlConnection()
public void Get_SqlNCli11Dot1_OleDbConnection()
{
var connStr = "Data Source=ds;Initial Catalog=ic";

//Call the method to test
var actual = new ConnectionFactory().Get("Adomd", connStr);
var connStr = "Provider=SQLNCLI11.1;Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=SSPI";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<AdomdConnection>());
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_SqlIsAmbiguousWithSqlClientAndSqlServerCe_ThrowsArgumentException()
{
var connStr = "Data Source=ds;Initial Catalog=ic";

//Call the method to test and Assert
Assert.Throws<ArgumentException>(delegate { new ConnectionFactory().Get("Sql", connStr); });
}

[Test]
public void Get_NotExistingProvider_ThrowsArgumentException()
{
var connStr = "Data Source=ds;Initial Catalog=ic";

//Call the method to test and Assert
Assert.Throws<ArgumentException>(delegate { new ConnectionFactory().Get("NotExistingProvider", connStr); });
}

[Test]
public void Get_ConnectionStringMsOlapProvider_AdomdConnection()
public void Get_Odbc_OdbcConnection()
{
//Call the method to test
var connStr = "Provider=MSOLAP;Data Source=ds;Initial Catalog=ic";
var connStr = "Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<AdomdConnection>());
Assert.That(actual, Is.InstanceOf<OdbcConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_ConnectionStringSqlClientNativeProvider_OleDbConnection()
public void Get_NoProviderDefined_SqlConnection()
{
var connStr = "Data Source=ds;Initial Catalog=ic";

//Call the method to test
var connStr = "Provider=SQLNCLI10.1;Data Source=ds;Initial Catalog=ic;Integrated Security=SSPI;";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<OleDbConnection>());
Assert.That(actual, Is.InstanceOf<SqlConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

Expand All @@ -183,17 +151,5 @@ public void Get_ConnectionStringOleDbProvider_OleDbConnection()
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

[Test]
public void Get_ConnectionStringEmptypProvider_SqlConnection()
{
//Call the method to test
var connStr = "Data Source=ds;Initial Catalog=ic";
var actual = new ConnectionFactory().Get(connStr);

//Assertion
Assert.That(actual, Is.InstanceOf<SqlConnection>());
Assert.That(actual.ConnectionString, Is.EqualTo(connStr));
}

}
}

0 comments on commit 089a785

Please sign in to comment.