public void SqlLocalDbInstance_CreateConnectionStringBuilder_If_Instance_Started() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); try { // Act SqlConnectionStringBuilder result = target.CreateConnectionStringBuilder(); // Assert Assert.IsNotNull(result, "CreateConnection() returned null."); StringAssert.Contains(result.ConnectionString, target.NamedPipe, "SqlConnection.ConnectionString is incorrect."); } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }
public void SqlLocalDbInstance_Start_Throws_If_An_Error_Occurs() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); SqlLocalDbInstance target; try { target = new SqlLocalDbInstance(instanceName); } finally { SqlLocalDbApi.DeleteInstance(instanceName); } // Act SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>( () => target.Start()); // Assert Assert.AreEqual(SqlLocalDbErrors.UnknownInstance, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect."); Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect."); throw error; }
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_Unshare_If_Instance_Is_Started() { // Arrange Helpers.EnsureLocalDBInstalled(); Helpers.EnsureUserIsAdmin(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); try { string sharedName = Guid.NewGuid().ToString(); target.Share(sharedName); ISqlLocalDbInstanceInfo info = SqlLocalDbApi.GetInstanceInfo(instanceName); Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null."); Assert.IsTrue(info.IsShared, "ISqlLocalDbInstanceInfo.IsShared is incorrect."); Assert.AreEqual(sharedName, info.SharedName, "ISqlLocalDbInstanceInfo.SharedName is incorrect."); // Act target.Unshare(); // Assert info = SqlLocalDbApi.GetInstanceInfo(instanceName); Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null."); Assert.IsFalse(info.IsShared, "ISqlLocalDbInstanceInfo.IsShared is incorrect."); Assert.AreEqual(string.Empty, info.SharedName, "ISqlLocalDbInstanceInfo.SharedName is incorrect."); } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }
public void SqlLocalDbInstance_Stop_Stops_Instance() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); ISqlLocalDbInstanceInfo info = SqlLocalDbApi.GetInstanceInfo(instanceName); Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null."); Assert.IsTrue(info.IsRunning, "The SQL LocalDB instance was not started."); Assert.IsTrue(target.IsRunning, "SqlLocalDbInstance.IsRunning is incorrect."); Assert.AreNotEqual(string.Empty, target.NamedPipe, "SqlLocalDbInstance.NamedPipe is incorrect."); // Act target.Stop(); try { // Assert info = SqlLocalDbApi.GetInstanceInfo(instanceName); Assert.IsNotNull(info, "SqlLocalDbApi.GetInstanceInfo() returned null."); Assert.IsFalse(info.IsRunning, "ISqlLocalDbInstanceInfo.IsRunning is incorrect."); Assert.IsFalse(target.IsRunning, "SqlLocalDbInstance.IsRunning is incorrect."); Assert.AreEqual(string.Empty, target.NamedPipe, "SqlLocalDbInstance.NamedPipe is incorrect."); } 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_Unshare_Throws_If_An_Error_Occurs() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); target.Start(); try { // Act SqlLocalDbException error = ErrorAssert.Throws<SqlLocalDbException>( () => target.Unshare()); // Assert Assert.AreEqual(SqlLocalDbErrors.InstanceNotShared, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect."); Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect."); throw error; } finally { SqlLocalDbApi.StopInstance(instanceName); } } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }