Код: Выделить всё
public GenericResponse GetAuthenticationToken()
{
try
{
var authToken = Task.Run(async () =>
{
var token = await _authenticationService.AuthenticationUser();
return token;
});
return new GenericResponse()
{
ErrorMessage = string.Empty,
HasError = false,
ResponseObject = authToken.Result
};
}
catch (Exception ex) when (ex.InnerException.Message.StartsWith("Invalid credentials passed"))
{
// Set the HTTP status code
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Unauthorized;
return new GenericResponse
{
HasError = true,
ErrorMessage = "Invalid Credentials",
ResponseObject = ex.InnerException.Message
};
}
catch (Exception ex)
{
var fault = new GenericErrorResponse
{
ErrorMessage = $"An unknown error occured while authenticating",
ErrorCode = 500,
Details = $"An error occured while getting authentication token: {ex.Message}. {ex.InnerException?.Message ?? string.Empty}"
};
// Throw FaultException with custom fault
throw new FaultException(fault, new FaultReason(fault.ErrorMessage));
}
}
Код: Выделить всё
[TestMethod]
public void GetAuthenticationToken()
{
mockAuthService.Setup(i => i.AuthenticationUser())
.Returns(() => Task.Run(() => VALID_TOKEN));
var expectedResponse = new GenericResponse()
{
ErrorMessage = string.Empty,
HasError = false,
ResponseObject = VALID_TOKEN
};
var awsWcfFileStorageService = new AwsWcfFileStorageService(mockAuthService.Object,
mockS3FileService.Object);
var actualResponse = awsWcfFileStorageService.GetAuthenticationToken();
actualResponse.Should().BeEquivalentTo(expectedResponse);
}
Код: Выделить всё
System.TypeLoadException: 'Could not load type 'System.ServiceModel.Web.WebOperationContext' from assembly 'System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.'
Код: Выделить всё
at email_wcf_service.AwsWcfFileStorageService.GetAuthenticationToken() in D:\Projects\file-storage-windows-service\file-storage-wcf-service\FileStorageService.cs:line 89
at file_storage_wcf_service.Tests.FileStorageServiceTests.GetAuthenticationToken() in D:\Projects\file-storage-windows-service\file-storage-wcf-service.Tests\AwsWcfFileStorageServiceTests.cs:line 139
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Подробнее здесь: https://stackoverflow.com/questions/790 ... m-assembly