public void SqlLocalDbInstance_Share_Throws_If_SharedName_Is_Invalid() { // Arrange Helpers.EnsureLocalDBInstalled(); string instanceName = Guid.NewGuid().ToString(); string sharedName = "\\\\"; SqlLocalDbApi.CreateInstance(instanceName); try { SqlLocalDbInstance target = new SqlLocalDbInstance(instanceName); // Act SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>( () => target.Share(sharedName)); // Assert Assert.AreEqual(SqlLocalDbErrors.InvalidInstanceName, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect."); Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect."); throw error; } finally { SqlLocalDbApi.DeleteInstance(instanceName); } }
public void SqlLocalDbInstance_Stop_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.Stop()); // Assert Assert.AreEqual(SqlLocalDbErrors.UnknownInstance, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect."); Assert.AreEqual(instanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect."); throw error; }
public void SqlLocalDbException_Constructor_For_Serialization_Can_Be_Serialized() { // Arrange InvalidOperationException innerException = new InvalidOperationException(); const int ErrorCode = 337519; string instanceName = Guid.NewGuid().ToString(); string message = Guid.NewGuid().ToString(); // Act SqlLocalDbException target = new SqlLocalDbException(message, ErrorCode, instanceName, innerException); BinaryFormatter formatter = new BinaryFormatter(); SqlLocalDbException deserialized; using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, target); stream.Seek(0L, SeekOrigin.Begin); deserialized = formatter.Deserialize(stream) as SqlLocalDbException; } // Assert Assert.IsNotNull(deserialized, "The exception was not deserialized."); Assert.AreEqual(deserialized.ErrorCode, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreEqual(deserialized.InstanceName, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(deserialized.Message, target.Message, "The Message property is incorrect."); }
public void SqlLocalDbException_Constructor_Default_Sets_Properties() { // Act SqlLocalDbException target = new SqlLocalDbException(); // Assert Assert.AreEqual(-2147467259, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreEqual(null, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(SR.SqlLocalDbException_DefaultMessage, target.Message, "The Message property is incorrect."); }
public void SqlLocalDbException_Constructor_With_Message_Sets_Properties() { // Arrange string message = Guid.NewGuid().ToString(); // Act SqlLocalDbException target = new SqlLocalDbException(message); // Assert Assert.AreEqual(-2147467259, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreEqual(null, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(message, target.Message, "The Message property is incorrect."); }
public void SqlLocalDbException_GetObjectData_Throws_If_Info_Is_Null() { // Arrange SqlLocalDbException target = new SqlLocalDbException(); SerializationInfo info = null; StreamingContext context = new StreamingContext(); // Act and Assert throw ErrorAssert.Throws <ArgumentNullException>( () => target.GetObjectData(info, context), "info"); }
public void SqlLocalDbException_Constructor_With_Message_ErrorCode_And_InstanceName_Sets_Properties() { // Arrange const int ErrorCode = 337519; string instanceName = Guid.NewGuid().ToString(); string message = Guid.NewGuid().ToString(); // Act SqlLocalDbException target = new SqlLocalDbException(message, ErrorCode, instanceName); // Assert Assert.AreEqual(ErrorCode, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreEqual(instanceName, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(message, target.Message, "The Message property is incorrect."); }
public void SqlLocalDbInstance_Delete_Throws_If_Instance_Is_Invalid() { // Arrange Helpers.EnsureLocalDBInstalled(); const string InstanceName = "\\\\"; Mock <ISqlLocalDbInstance> mock = new Mock <ISqlLocalDbInstance>(); mock.Setup((p) => p.Name).Returns(InstanceName); ISqlLocalDbInstance instance = mock.Object; // Act SqlLocalDbException error = ErrorAssert.Throws <SqlLocalDbException>( () => SqlLocalDbInstance.Delete(instance)); // Assert Assert.AreEqual(SqlLocalDbErrors.InvalidInstanceName, error.ErrorCode, "SqlLocalDbException.ErrorCode is incorrect."); Assert.AreEqual(InstanceName, error.InstanceName, "SqlLocalDbException.InstanceName is incorrect."); throw error; }
public void SqlLocalDbException_Constructor_With_Message_And_ErrorCode_Sets_Properties() { // Arrange const int ErrorCode = 337519; string message = Guid.NewGuid().ToString(); // Act SqlLocalDbException target = new SqlLocalDbException(message, ErrorCode); // Assert Assert.AreEqual(ErrorCode, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreEqual(null, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(message, target.Message, "The Message property is incorrect."); }
public void SqlLocalDbException_GetObjectData_Throws_If_Info_Is_Null() { // Arrange SqlLocalDbException target = new SqlLocalDbException(); SerializationInfo info = null; StreamingContext context = new StreamingContext(); // Act and Assert throw ErrorAssert.Throws<ArgumentNullException>( () => target.GetObjectData(info, context), "info"); }
public void SqlLocalDbException_Constructor_With_Message_ErrorCode_InstanceName_And_InnerException_Sets_Properties() { // Arrange InvalidOperationException innerException = new InvalidOperationException(); const int ErrorCode = 337519; string instanceName = Guid.NewGuid().ToString(); string message = Guid.NewGuid().ToString(); // Act SqlLocalDbException target = new SqlLocalDbException(message, ErrorCode, instanceName, innerException); // Assert Assert.AreEqual(ErrorCode, target.ErrorCode, "The ErrorCode property is incorrect."); Assert.AreSame(innerException, target.InnerException, "The InnerException property is incorrect."); Assert.AreEqual(instanceName, target.InstanceName, "The InstanceName property is incorrect."); Assert.AreEqual(message, target.Message, "The Message property is incorrect."); }