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_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); } }
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); } }
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); } }