public void Decorate_But_Not_Recreate_PushConfiguration() { // Arrange var smpResponse = new SmpConfiguration { Url = "http://some/url" }; var push = new PushConfiguration { TlsConfiguration = new TlsConfiguration { CertificateType = TlsCertificateChoiceType.PrivateKeyCertificate, ClientCertificateInformation = new ClientCertificateReference() } }; var fixture = new SendingProcessingMode { PushConfiguration = push }; // Act SendingProcessingMode result = ExerciseDecorate(fixture, smpResponse); // Assert Assert.Same(push, result.PushConfiguration); Assert.Equal(smpResponse.Url, push.Protocol.Url); Assert.Same( push.TlsConfiguration.ClientCertificateInformation, result.PushConfiguration.TlsConfiguration.ClientCertificateInformation); }
/// <summary> /// Send the <see cref="AS4Message" /> /// </summary> /// <param name="messagingContext"></param> /// <returns></returns> public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext) { if (messagingContext == null) { throw new ArgumentNullException(nameof(messagingContext)); } if (messagingContext.ReceivedMessage == null && messagingContext.AS4Message == null) { throw new InvalidOperationException( $"{nameof(SendAS4MessageStep)} requires a MessagingContext with a ReceivedStream or an AS4Message to correctly send the message"); } if (messagingContext.ReceivedMessage == null && messagingContext.AS4Message.IsPullRequest == false) { throw new InvalidOperationException( $"{nameof(SendAS4MessageStep)} expects a PullRequest AS4Message when the MessagingContext does not contain a ReceivedStream"); } PushConfiguration pushConfig = GetPushConfiguration(messagingContext.SendingPMode, messagingContext.ReceivingPMode); if (pushConfig?.Protocol?.Url == null) { throw new ConfigurationErrorsException( "Message cannot be send because neither the Sending or Receiving PMode has a Protocol.Url child in a <PushConfiguration/> or <ResponseConfiguration/> element"); } AS4Message as4Message = await DeserializeUnderlyingStreamIfPresentAsync( messagingContext.ReceivedMessage, otherwise : messagingContext.AS4Message); try { string contentType = messagingContext.ReceivedMessage?.ContentType ?? messagingContext.AS4Message.ContentType; HttpWebRequest request = CreateWebRequest(pushConfig, contentType.Replace("charset=\"utf-8\"", "")); await WriteToHttpRequestStreamAsync(request, messagingContext).ConfigureAwait(false); messagingContext.ModifyContext(as4Message); return(await HandleHttpResponseAsync(request, messagingContext).ConfigureAwait(false)); } catch { await UpdateRetryStatusForMessageAsync(messagingContext, SendResult.RetryableFail); return(StepResult.Failed(messagingContext).AndStopExecution()); } }
private HttpWebRequest CreateWebRequest(PushConfiguration pushConfig, string contentType) { string url = pushConfig.Protocol.Url; Logger.Trace($"Creating WebRequest to {url}"); HttpWebRequest request = _httpClient.Request(url, contentType); X509Certificate2 clientCert = RetrieveClientCertificate(pushConfig.TlsConfiguration); if (clientCert != null) { request.ClientCertificates.Add(clientCert); } return(request); }
public void Decorate_Not_Recreate_PushConfiguration_Protocol() { // Arrange var protocol = new Protocol(); var push = new PushConfiguration() { Protocol = protocol, TlsConfiguration = { IsEnabled = true } }; var fixture = new SendingProcessingMode { PushConfiguration = push }; // Act SendingProcessingMode result = ExercisePModeDecorationWithCompleteSmp(fixture); // Assert Assert.Same(protocol, result.PushConfiguration.Protocol); Assert.True(result.PushConfiguration.TlsConfiguration.IsEnabled); }
public T GetDataFromWorksheet(Worksheet worksheet) { if (worksheet == null) { return(null); } T res = new T(); //FIXME: we need to keep track of data evolution => generating new uuid each times fails the comparison at server side PropertyInfo[] properties = typeof(T).GetProperties().OrderBy(p => p.MetadataToken).ToArray(); //properties[0].SetValue(res, System.Guid.NewGuid().ToString()); properties[0].SetValue(res, typeof(T).Name.ToLower()); //temporary PropertyInfo property; for (int i = 1; i < properties.Length; i++) { property = properties[i]; PushConfiguration cellConfiguration = property.GetCustomAttribute <PushConfiguration>(); int[] position = cellConfiguration.Position; Range range = worksheet.Cells[position[0], position[1]]; string value = range.Value.ToString(); Type propertyType = property.PropertyType; if (propertyType.Name.Equals("Double")) { //var dvalue = Double.Parse(value, new CultureInfo("en-US")); var dvalue = Double.Parse(value, CultureInfo.CurrentUICulture); property.SetValue(res, dvalue); } else if (propertyType.Name.Equals("Boolean")) { var bvalue = Boolean.Parse(value); property.SetValue(res, bvalue); } else { property.SetValue(res, Convert.ChangeType(value, property.PropertyType)); } } return(res); }
public async Task UpdatePushRegistrationAsync(PushConfiguration pushConfiguration) { await ExecuteAsync<PushConfiguration, object>("registration/push", HttpMethod.Put, pushConfiguration); }