public void SqlLocalDbInstance_CreateConnection_If_Instance_Is_Started_And_Returned_ConnectionStringBuilder_Is_Null() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { var mock = new Mock <SqlLocalDbInstance>(instanceName) { CallBase = true, }; mock.Setup((p) => p.CreateConnectionStringBuilder()) .Returns(null as SqlConnectionStringBuilder); SqlLocalDbInstance target = mock.Object; target.Start(); try { // Act SqlConnection result = target.CreateConnection(); try { // Assert Assert.IsNotNull(result, "CreateConnection() returned null."); Assert.AreEqual(ConnectionState.Closed, result.State, "SqlConnection.State is incorrect."); Assert.AreEqual(string.Empty, result.ConnectionString, "SqlConnection.ConnectionString is incorrect."); } finally { if (result != null) { result.Dispose(); } } } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }
public void SqlLocalDbInstance_CreateConnection_If_Instance_Is_Started() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); try { // Act SqlConnection result = target.CreateConnection(); try { // Assert Assert.IsNotNull(result, "CreateConnection() returned null."); Assert.AreEqual(ConnectionState.Closed, result.State, "SqlConnection.State is incorrect."); StringAssert.Contains(result.ConnectionString, target.NamedPipe, "SqlConnection.ConnectionString is incorrect."); } finally { if (result != null) { result.Dispose(); } } } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }
public void SqlLocalDbInstance_CreateConnection_If_Instance_Is_Started() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); try { // Act SqlConnection result = target.CreateConnection(); try { // Assert Assert.IsNotNull(result, "CreateConnection() returned null."); Assert.AreEqual(ConnectionState.Closed, result.State, "SqlConnection.State is incorrect."); StringAssert.Contains(result.ConnectionString, target.NamedPipe, "SqlConnection.ConnectionString is incorrect."); } finally { if (result != null) { result.Dispose(); } } } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }