public void Then_Error_Detail_Is_Present_When_Defined() { // Arrange var error = new Error( $"error-{Guid.NewGuid()}", $"user-{Guid.NewGuid()}", ErrorLine.FromErrorResult(new ErrorResult("sample error", ErrorAlias.ConnectionFailure))); // Act XmlDocument doc = SerializeSoapMessage(AS4Message.Create(error)); // Assert XmlNode errorTag = doc.SelectEbmsNode( "/s12:Envelope/s12:Header/eb:Messaging/eb:SignalMessage/eb:Error"); const string expected = "<eb:Error " + "category=\"Communication\" " + "errorCode=\"EBMS:0005\" " + "severity=\"FAILURE\" " + "shortDescription=\"ConnectionFailure\" " + "xmlns:eb=\"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/\">" + "<eb:ErrorDetail>sample error</eb:ErrorDetail>" + "</eb:Error>"; Assert.Equal(expected, errorTag.OuterXml); }
private static AS4Message CreateAS4ErrorMessage(string refToMessageId) { Error error = Error.FromErrorResult( $"error-{Guid.NewGuid()}", refToMessageId, new ErrorResult("An error occurred", ErrorAlias.NonApplicable)); return(AS4Message.Create(error, CreateSendingPMode())); }
private static AS4Message CreateAS4ErrorWithPossibleMultihop( AS4Message received, ErrorResult occurredError) { Error ToError(UserMessage u) { return(Error.CreateFor(IdentifierFactory.Instance.Create(), u, occurredError, received?.IsMultiHopMessage == true)); } IEnumerable <Error> errors = received?.UserMessages.Select(ToError) ?? new Error[0]; AS4Message errorMessage = AS4Message.Create(errors); errorMessage.SigningId = received?.SigningId; return(errorMessage); }
public async Task CanReceiveErrorSignalWithoutRefToMessageId() { var as4Message = AS4Message.Create( Error.FromErrorResult( messageId: $"error-{Guid.NewGuid()}", refToMessageId: null, result: new ErrorResult("An Error occurred", ErrorAlias.NonApplicable))); string id = as4Message.GetPrimaryMessageId(); var response = await StubSender.SendAS4Message(_receiveAgentUrl, as4Message); Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); Assert.True(String.IsNullOrWhiteSpace(await response.Content.ReadAsStringAsync())); var inMessage = _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == id); Assert.NotNull(inMessage); Assert.Equal(Operation.NotApplicable, inMessage.Operation); }
public async Task ErrorMessageForMultihopUserMessageIsMultihop() { // Arrange AS4Message expectedAS4Message = await CreateReceivedAS4Message(CreateMultiHopPMode()); var error = Error.CreateFor($"error-{Guid.NewGuid()}", expectedAS4Message.FirstUserMessage, userMessageSendViaMultiHop: true); // Act XmlDocument document = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(error), CancellationToken.None); // Following elements should be present: // - To element in the wsa namespace // - Action element in the wsa namespace // - UserElement in the multihop namespace. AssertToElement(document); Assert.True(ContainsActionElement(document)); Assert.True(ContainsUserMessageElement(document)); AssertMessagingElement(document); AssertIfSenderAndReceiverAreReversed(expectedAS4Message, document); }
/// <summary> /// Maps from a domain model representation to a XML representation of an AS4 error. /// </summary> /// <param name="model">The domain model to convert.</param> internal static SignalMessage Convert(Error model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } Xml.Error MapErrorLine(ErrorLine l) { return(new Xml.Error { errorCode = l.ErrorCode.GetString(), severity = l.Severity.ToString(), origin = l.Origin.GetOrElse(() => null), category = l.Category.GetOrElse(() => null), refToMessageInError = l.RefToMessageInError.GetOrElse(() => null), shortDescription = l.ShortDescription.ToString(), ErrorDetail = l.Detail.GetOrElse(() => null), Description = l.Description .Select(d => new Description { lang = d.Language, Value = d.Value }) .GetOrElse(() => null) }); } return(new SignalMessage { MessageInfo = new MessageInfo { MessageId = model.MessageId, RefToMessageId = model.RefToMessageId, Timestamp = model.Timestamp.LocalDateTime }, Error = model.ErrorLines.Select(MapErrorLine).ToArray() }); }