Removing optional data property from Error response class (#325)

* Removing optional data property from Error response class

* Fixing broken unit tests
This commit is contained in:
Benjamin Russell
2017-04-24 13:45:33 -07:00
committed by GitHub
parent cf9a81aec9
commit e65699ef75
9 changed files with 26 additions and 57 deletions

View File

@@ -64,37 +64,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
return this;
}
public EventFlowValidator<TRequestContext> AddCompleteErrorValidation<TErrorObj>(Action<string, int> paramValidation,
Action<TErrorObj> dataValidation)
{
// Put together a validator that checks for null and adds the provided validators
Action<Error> validator = e =>
{
Assert.NotNull(e);
paramValidation(e.Message, e.Code);
Assert.IsType<TErrorObj>(e.Data);
dataValidation((TErrorObj) e.Data);
};
// Add the expected error
expectedEvents.Add(new ExpectedEvent
{
EventType = EventTypes.Error,
ParamType = typeof(Error),
Validator = validator
});
return this;
}
public EventFlowValidator<TRequestContext> AddSimpleErrorValidation(Action<string, int> paramValidation)
{
// Put together a validator that ensures a null data
Action<Error> validator = e =>
{
Assert.NotNull(e);
Assert.Null(e.Data);
paramValidation(e.Message, e.Code);
};
@@ -130,7 +105,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
.Returns(Task.FromResult(0));
// Add general handler for error event
requestContext.AddErrorHandling((msg, code, obj) =>
requestContext.AddErrorHandling((msg, code) =>
{
receivedEvents.Add(new ReceivedEvent
{

View File

@@ -48,14 +48,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public static Mock<RequestContext<TResponse>> AddErrorHandling<TResponse>(
this Mock<RequestContext<TResponse>> mock,
Action<string, int, object> errorCallback)
Action<string, int> errorCallback)
{
// Setup the mock for SendError
var sendErrorFlow = mock.Setup(rc => rc.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()))
var sendErrorFlow = mock.Setup(rc => rc.SendError(It.IsAny<string>(), It.IsAny<int>()))
.Returns(Task.FromResult(0));
if (errorCallback != null)
{
sendErrorFlow.Callback<string, int, object>(errorCallback);
sendErrorFlow.Callback<string, int>(errorCallback);
}
return mock;

View File

@@ -40,20 +40,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
public static void VerifyErrorSent<T>(Mock<RequestContext<T>> contextMock)
{
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Never);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Once);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
public static void VerifyResult<T, U>(Mock<RequestContext<T>> contextMock, U expected, U actual)
{
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Once);
Assert.Equal(expected, actual);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Never);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
public static void VerifyResult<T>(Mock<RequestContext<T>> contextMock, Action<T> verify, T actual)
{
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Once);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Never);
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>()), Times.Never);
verify(actual);
}