using System.ServiceModel; using System.Text; using ServiceReference; namespace PristupnaTockaSoapClient.Tests; public class SoapClientTests { private BackendInterfaceClient backendInterfaceClient; private String url; private String from; private String to; private String password; public SoapClientTests() { url = Environment.GetEnvironmentVariable("PT.URL") ?? "https://jpt99901.test.pristupnatocka.hr/ws"; from = Environment.GetEnvironmentVariable("PT.FROM"); to = Environment.GetEnvironmentVariable("PT.TO"); password = Environment.GetEnvironmentVariable("PT.PASSWORD"); if (url == null || from == null || to == null || password == null) { throw new ArgumentException("Please provide all required environment variables"); } SoapClientBuilder soapClientBuilder = new SoapClientBuilder(); backendInterfaceClient = soapClientBuilder.BuildClient(this.url, this.from, this.password); Console.WriteLine(this.url); } [Fact] public void Test_SubmitMessage_With_ASICE_Payload_Call() { PartyId partyIdFrom = new PartyId(); partyIdFrom.type = "urn:oasis:names:tc:ebcore:partyid-type:unregistered:pristupnatocka:jpt"; partyIdFrom.Value = this.from; From from = new From(); from.Role = "http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/initiator"; from.PartyId = partyIdFrom; PartyId partyIdTo = new PartyId(); partyIdTo.type = "urn:oasis:names:tc:ebcore:partyid-type:unregistered:pristupnatocka:jpt"; partyIdTo.Value = this.to; To to = new To(); to.Role = "http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/responder"; to.PartyId = partyIdTo; PartyInfo partyInfo = new PartyInfo(); partyInfo.From = from; partyInfo.To = to; Service srv = new Service(); srv.Value = "bdx:noprocess"; srv.type = "tc1"; CollaborationInfo collaborationInfo = new CollaborationInfo(); collaborationInfo.Service = srv; collaborationInfo.Action = "TC1Leg1"; Property originalSender = new Property(); originalSender.name = "originalSender"; originalSender.Value = "urn:oasis:names:tc:ebcore:partyid-type:unregistered:pristupnatocka:user:" + partyIdFrom.Value; Property finalRecipient = new Property(); finalRecipient.name = "finalRecipient"; finalRecipient.Value = "urn:oasis:names:tc:ebcore:partyid-type:unregistered:pristupnatocka:user:" + partyIdTo.Value; Property[] messageProperties = new Property[] { originalSender, finalRecipient }; Property mimeType = new Property(); mimeType.name = "MimeType"; mimeType.Value = "application/vnd.etsi.asic-e+zip"; Property[] partProperties = new Property[] { mimeType }; PartInfo partInfo = new PartInfo(); partInfo.href = "cid:message"; partInfo.PartProperties = partProperties; PartInfo[] payloadInfo = new PartInfo[] { partInfo }; UserMessage userMessage = new UserMessage(); userMessage.PartyInfo = partyInfo; userMessage.CollaborationInfo = collaborationInfo; userMessage.MessageProperties = messageProperties; userMessage.PayloadInfo = payloadInfo; Messaging messaging = new Messaging(); messaging.UserMessage = userMessage; LargePayloadType messagePayloadPayload = new LargePayloadType(); messagePayloadPayload.contentType = "application/vnd.etsi.asic-e+zip"; messagePayloadPayload.payloadId = "cid:message"; string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; byte[] bytes = File.ReadAllBytes("./resources/asice-sample.asice"); messagePayloadPayload.value = bytes; submitRequest submitRequest = new submitRequest(); submitRequest.payload = new LargePayloadType[] { messagePayloadPayload }; Task<submitMessageResponse> submitMessageTask = backendInterfaceClient.submitMessageAsync(messaging, submitRequest); submitMessageResponse submitMessageResponse = submitMessageTask.GetAwaiter().GetResult(); Assert.NotEmpty(submitMessageResponse.submitResponse); } [Fact] public void Test_GetStatus_Call() { statusRequest statusRequest = new statusRequest(); statusRequest.messageID = Guid.NewGuid().ToString(); Task<getStatusResponse> statusRequestTask = backendInterfaceClient.getStatusAsync(statusRequest); getStatusResponse getStatusResponse = statusRequestTask.GetAwaiter().GetResult(); Assert.Equal(messageStatus.NOT_FOUND, getStatusResponse.getStatusResponse1); } [Fact] public void Test_RetrieveMessage() { retrieveMessageRequest retrieveMessageRequest = new retrieveMessageRequest(); retrieveMessageRequest.messageID = Guid.NewGuid().ToString(); FaultException e = Assert.Throws<FaultException<FaultDetail>>(() => backendInterfaceClient.retrieveMessageAsync(retrieveMessageRequest) .GetAwaiter() .GetResult()); Assert.Equal(String.Format("Message not found, id [{0}]", retrieveMessageRequest.messageID), e.Message); } [Fact] public void Test_GetErrorMessages_Call() { getErrorsRequest getErrorsRequest = new getErrorsRequest(); getErrorsRequest.messageID = Guid.NewGuid().ToString(); FaultException e = Assert.Throws<FaultException>(() => backendInterfaceClient.getMessageErrorsAsync(getErrorsRequest) .GetAwaiter() .GetResult()); Assert.Equal(String.Format("[DOM_009]:Message [{0}] does not exist", getErrorsRequest.messageID), e.Message); } [Fact] public void Test_ListPendingMessages_Call() { Task<listPendingMessagesResponse> listPendingMessagesTask = backendInterfaceClient.listPendingMessagesAsync(""); listPendingMessagesResponse listPendingMessagesResponse = listPendingMessagesTask.GetAwaiter().GetResult(); Assert.True(listPendingMessagesResponse.listPendingMessagesResponse1.Length >= 0); } }