Skip to content

Commit

Permalink
Updates to vNext Unit Tests - to correct test failures.
Browse files Browse the repository at this point in the history
After discussion decided we only need one test for
DbProviderServicesExtensionsTests - the rest was for functionality that no
longer exists.

(cherry picked from commit 1a5b09e)
  • Loading branch information
lajones committed Jun 24, 2014
1 parent bc291f7 commit af5cbcf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 68 deletions.
18 changes: 9 additions & 9 deletions src/EntityFramework/Properties/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,6 @@ internal static string MultiplePropertiesMatchedAsKeys(object p0, object p1)
return EntityRes.GetString(EntityRes.MultiplePropertiesMatchedAsKeys, p0, p1);
}

// <summary>
// A string like "Connection to the database failed. The connection string is configured with an invalid LocalDB server name. This may have been set in 'global.asax' by a pre-release version of MVC4. The default connection factory is now set in web.config so the line in 'global.asax' starting with 'Database.DefaultConnectionFactory = ' should be removed. See http://go.microsoft.com/fwlink/?LinkId=243166 for details."
// </summary>
internal static string BadLocalDBDatabaseName
{
get { return EntityRes.GetString(EntityRes.BadLocalDBDatabaseName); }
}

// <summary>
// A string like "An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure."
// </summary>
Expand Down Expand Up @@ -14005,6 +13997,14 @@ internal static string TransactionDisposedLog(object p0, object p1)
{
return EntityRes.GetString(EntityRes.TransactionDisposedLog, p0, p1);
}

// <summary>
// A string like "Unable to load embedded resource '{1}' from assembly '{0}'."
// </summary>
internal static string UnableToLoadEmbeddedResource(object p0, object p1)
{
return EntityRes.GetString(EntityRes.UnableToLoadEmbeddedResource, p0, p1);
}
}

// <summary>
Expand Down Expand Up @@ -15757,7 +15757,6 @@ internal sealed class EntityRes
internal const string DuplicateConfiguredColumnOrder = "DuplicateConfiguredColumnOrder";
internal const string UnsupportedUseOfV3Type = "UnsupportedUseOfV3Type";
internal const string MultiplePropertiesMatchedAsKeys = "MultiplePropertiesMatchedAsKeys";
internal const string BadLocalDBDatabaseName = "BadLocalDBDatabaseName";
internal const string FailedToGetProviderInformation = "FailedToGetProviderInformation";
internal const string DbPropertyEntry_CannotGetCurrentValue = "DbPropertyEntry_CannotGetCurrentValue";
internal const string DbPropertyEntry_CannotSetCurrentValue = "DbPropertyEntry_CannotSetCurrentValue";
Expand Down Expand Up @@ -17395,6 +17394,7 @@ internal sealed class EntityRes
internal const string TransactionHandler_AlreadyInitialized = "TransactionHandler_AlreadyInitialized";
internal const string ConnectionDisposedLog = "ConnectionDisposedLog";
internal const string TransactionDisposedLog = "TransactionDisposedLog";
internal const string UnableToLoadEmbeddedResource = "UnableToLoadEmbeddedResource";

private static EntityRes loader;
private readonly ResourceManager resources;
Expand Down
3 changes: 0 additions & 3 deletions src/EntityFramework/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,6 @@
<value>Multiple potential primary key properties named '{0}' but differing only by case were found on entity type '{1}'. Configure the primary key explicitly using the HasKey fluent API or the KeyAttribute data annotation.</value>
<comment>## ExceptionType=InvalidOperationException</comment>
</data>
<data name="BadLocalDBDatabaseName" xml:space="preserve">
<value>Connection to the database failed. The connection string is configured with an invalid LocalDB server name. This may have been set in 'global.asax' by a pre-release version of MVC4. The default connection factory is now set in web.config so the line in 'global.asax' starting with 'Database.DefaultConnectionFactory = ' should be removed. See http://go.microsoft.com/fwlink/?LinkId=243166 for details.</value>
</data>
<data name="FailedToGetProviderInformation" xml:space="preserve">
<value>An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.</value>
</data>
Expand Down
7 changes: 0 additions & 7 deletions src/EntityFramework/Utilities/DbProviderServicesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public static string GetProviderManifestTokenChecked(
}
catch (ProviderIncompatibleException ex)
{
var dataSource = DbInterception.Dispatch.Connection.GetDataSource(connection, new DbInterceptionContext());
if (@"(localdb)\v11.0".Equals(dataSource, StringComparison.OrdinalIgnoreCase)
|| @"(localdb)\mssqllocaldb".Equals(dataSource, StringComparison.OrdinalIgnoreCase))
{
throw new ProviderIncompatibleException(Strings.BadLocalDBDatabaseName, ex);
}

throw new ProviderIncompatibleException(Strings.FailedToGetProviderInformation, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace System.Data.Entity.Utilities
{
using System.Data.Common;
using System.Data.Entity.Core;
using System.Data.Entity.Core.Common;
using System.Data.Entity.Infrastructure.Interception;
using System.Data.Entity.Resources;
using System.Data.SqlClient;
using Moq;
Expand All @@ -15,53 +13,9 @@ namespace System.Data.Entity.Utilities
public class DbProviderServicesExtensionsTests
{
[Fact]
public void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_MVC4_connection_string_is_used()
public void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked()
{
Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_connection_string_is_used(
"Data Source=(localdb)\v11.0", Strings.BadLocalDBDatabaseName);
}

[Fact]
public void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_general_bad_connection_string_is_used()
{
Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_connection_string_is_used(
"Data Source=WotNoServer", Strings.FailedToGetProviderInformation);
}

[Fact]
public void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_correct_LocalDB_name_is_used_but_it_still_fails()
{
Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_connection_string_is_used(
"Data Source=(localdb)\\v11.0", Strings.FailedToGetProviderInformation);
}

[Fact]
public void GetProviderManifestTokenChecked_uses_interception()
{
var dbConnectionInterceptorMock = new Mock<IDbConnectionInterceptor>();
DbInterception.Add(dbConnectionInterceptorMock.Object);
try
{
Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_connection_string_is_used(
"Data Source=WotNoServer", Strings.FailedToGetProviderInformation);
}
finally
{
DbInterception.Remove(dbConnectionInterceptorMock.Object);
}

dbConnectionInterceptorMock.Verify(
m => m.DataSourceGetting(It.IsAny<DbConnection>(), It.IsAny<DbConnectionInterceptionContext<string>>()),
Times.Once());
dbConnectionInterceptorMock.Verify(
m => m.DataSourceGot(It.IsAny<DbConnection>(), It.IsAny<DbConnectionInterceptionContext<string>>()),
Times.Once());
}

private void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_bad_connection_string_is_used(
string connectionString, string expectedMessage)
{
var fakeConnection = new SqlConnection(connectionString);
var fakeConnection = new SqlConnection("Data Source=AnyConnectionString");
var innerException = new ProviderIncompatibleException();

var mockProviderServices = new Mock<DbProviderServices>();
Expand All @@ -73,7 +27,7 @@ private void Useful_exception_is_thrown_by_GetProviderManifestTokenChecked_if_ba
var ex =
Assert.Throws<ProviderIncompatibleException>(
() => mockProviderServices.Object.GetProviderManifestTokenChecked(fakeConnection));
Assert.Equal(expectedMessage, ex.Message);
Assert.Equal(Strings.FailedToGetProviderInformation, ex.Message);
Assert.Same(innerException, ex.InnerException);
}
}
Expand Down

0 comments on commit af5cbcf

Please sign in to comment.