diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Data.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Data.cs index 0b72bdb..5fa3d75 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Data.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Data.cs @@ -3,30 +3,16 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + /// /// /// [ExcludeFromCodeCoverage] public class Data { - /// - /// Gets or sets the count. - /// - /// - /// The count. - /// - [JsonProperty("count")] + public Int32 Count { get; set; } - /// - /// Gets or sets the email details. - /// - /// - /// The email details. - /// - [JsonProperty("emails")] public List EmailDetails { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/EmailDetails.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/EmailDetails.cs index c5a8f45..0ce1a2d 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/EmailDetails.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/EmailDetails.cs @@ -2,66 +2,20 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - /// - /// - /// [ExcludeFromCodeCoverage] public class EmailDetails { - /// - /// Gets or sets the subject. - /// - /// - /// The subject. - /// - [JsonProperty("subject")] public String Subject { get; set; } - /// - /// Gets or sets the delivered at. - /// - /// - /// The delivered at. - /// - [JsonProperty("delivered_at")] public DateTime DeliveredAt { get; set; } - /// - /// Gets or sets the email status date. - /// - /// - /// The email status date. - /// - [JsonProperty("email_ts")] public DateTime EmailStatusDate { get; set; } - /// - /// Gets or sets the process status. - /// - /// - /// The process status. - /// - [JsonProperty("process_status")] public String ProcessStatus { get; set; } - /// - /// Gets or sets the email identifier. - /// - /// - /// The email identifier. - /// - [JsonProperty("email_id")] public String EmailId { get; set; } - /// - /// Gets or sets the status. - /// - /// - /// The status. - /// - [JsonProperty("status")] public String Status { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoAttachment.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoAttachment.cs index 95ca1a5..9a6a7f7 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoAttachment.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoAttachment.cs @@ -2,23 +2,14 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - - + [ExcludeFromCodeCoverage] public class Smtp2GoAttachment { - #region Properties - - [JsonProperty("fileblob")] public String FileBlob { get; set; } - [JsonProperty("filename")] public String FileName { get; set; } - [JsonProperty("mimetype")] public String MimeType { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchRequest.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchRequest.cs index c00d60d..31a01e6 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchRequest.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchRequest.cs @@ -3,48 +3,16 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - - /// - /// - /// + [ExcludeFromCodeCoverage] public class Smtp2GoEmailSearchRequest { - /// - /// Gets or sets the email identifier. - /// - /// - /// The email identifier. - /// - [JsonProperty("email_id")] public List EmailId { get; set; } - /// - /// Gets or sets the API key. - /// - /// - /// The API key. - /// - [JsonProperty("api_key")] public String ApiKey { get; set; } - /// - /// Gets or sets the start date. - /// - /// - /// The start date. - /// - [JsonProperty("start_date")] public String StartDate { get; set; } - /// - /// Gets or sets the end date. - /// - /// - /// The end date. - /// - [JsonProperty("end_date")] public String EndDate { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchResponse.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchResponse.cs index 81763a7..0019271 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchResponse.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoEmailSearchResponse.cs @@ -2,34 +2,12 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - - /// - /// - /// + [ExcludeFromCodeCoverage] public class Smtp2GoEmailSearchResponse { - #region Properties - - /// - /// Gets or sets the data. - /// - /// - /// The data. - /// - [JsonProperty("data")] public Data Data { get; set; } - /// - /// Gets or sets the request identifier. - /// - /// - /// The request identifier. - /// - [JsonProperty("request_id")] public String RequestId { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs index 3048ef0..4811d63 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoProxy.cs @@ -1,16 +1,15 @@ -namespace MessagingService.BusinessLogic.Services.EmailServices.Smtp2Go +using Shared.Serialisation; + +namespace MessagingService.BusinessLogic.Services.EmailServices.Smtp2Go { using Models; - using Newtonsoft.Json; using Service.Services.Email.Smtp2Go; - using Shared.General; using Shared.Logger; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Net.Http; - using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -73,7 +72,7 @@ public async Task SendEmail(Guid messageId, attachments.ForEach(a => apiRequest.Attachments.Add(new Smtp2GoAttachment { FileBlob = a.FileData, FileName = a.Filename, MimeType = this.ConvertFileType(a.FileType) })); } - String requestSerialised = JsonConvert.SerializeObject(apiRequest, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None }); + String requestSerialised = StringSerialiser.Serialise(apiRequest, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase, WriteIndented:true)); Logger.LogDebug($"Request Message Sent to Email Provider [SMTP2Go] {requestSerialised}"); @@ -86,12 +85,11 @@ public async Task SendEmail(Guid messageId, HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken); Smtp2GoSendEmailResponse apiResponse = httpResponse.IsSuccessStatusCode switch { - true => JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(cancellationToken)), + true => StringSerialiser.Deserialise(await httpResponse.Content.ReadAsStringAsync(cancellationToken)), _ => new Smtp2GoSendEmailResponse { Data = new Smtp2GoSendEmailResponseData { Error = httpResponse.StatusCode.ToString(), ErrorCode = ((Int32)httpResponse.StatusCode).ToString() } } }; - Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}"); - + Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {StringSerialiser.Serialise(apiResponse)}"); // Translate the Response return new EmailServiceProxyResponse { ApiCallSuccessful = httpResponse.IsSuccessStatusCode && String.IsNullOrEmpty(apiResponse.Data.ErrorCode), @@ -119,7 +117,7 @@ public async Task GetMessageStatus(String providerReferen ApiKey = Configuration.APIKey, EmailId = new List { providerReference }, StartDate = startDate.ToString("yyyy-MM-dd"), EndDate = endDate.ToString("yyyy-MM-dd"), }; - String requestSerialised = JsonConvert.SerializeObject(apiRequest, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None }); + String requestSerialised = StringSerialiser.Serialise(apiRequest, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase, WriteIndented: true)); Logger.LogDebug($"Request Message Sent to Email Provider [SMTP2Go] {requestSerialised}"); @@ -131,9 +129,9 @@ public async Task GetMessageStatus(String providerReferen HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(requestMessage, cancellationToken); - Smtp2GoEmailSearchResponse apiResponse = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); + Smtp2GoEmailSearchResponse apiResponse = StringSerialiser.Deserialise(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); - Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {JsonConvert.SerializeObject(apiResponse)}"); + Logger.LogDebug($"Response Message Received from Email Provider [SMTP2Go] {StringSerialiser.Serialise(apiResponse)}"); // Translate the Response return new MessageStatusResponse { ApiStatusCode = httpResponse.StatusCode, MessageStatus = this.TranslateMessageStatus(apiResponse.Data.EmailDetails.Single().Status), ProviderStatusDescription = apiResponse.Data.EmailDetails.Single().Status, Timestamp = apiResponse.Data.EmailDetails.Single().EmailStatusDate }; diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailRequest.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailRequest.cs index 0687ede..f4e4e35 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailRequest.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailRequest.cs @@ -1,5 +1,4 @@ using System; -using Newtonsoft.Json; namespace MessagingService.Service.Services.Email.Smtp2Go { @@ -9,95 +8,24 @@ namespace MessagingService.Service.Services.Email.Smtp2Go [ExcludeFromCodeCoverage] public class Smtp2GoSendEmailRequest { - /// - /// Gets or sets the API key. - /// - /// - /// The API key. - /// - [JsonProperty("api_key")] public String ApiKey { get; set; } - /// - /// Gets or sets a value indicating whether [test mode]. - /// - /// - /// true if [test mode]; otherwise, false. - /// - [JsonProperty("test")] public Boolean TestMode { get; set; } - /// - /// Gets or sets the sender. - /// - /// - /// The sender. - /// - [JsonProperty("sender")] public String Sender { get; set; } - /// - /// Gets or sets to. - /// - /// - /// To. - /// - [JsonProperty("to")] public String[] To { get; set; } - /// - /// Gets or sets the cc. - /// - /// - /// The cc. - /// - [JsonProperty("cc")] public String[] CC { get; set; } - /// - /// Gets or sets the BCC. - /// - /// - /// The BCC. - /// - [JsonProperty("bcc")] public String[] BCC { get; set; } - /// - /// Gets or sets the subject. - /// - /// - /// The subject. - /// - [JsonProperty("subject")] public String Subject { get; set; } - /// - /// Gets or sets the HTML body. - /// - /// - /// The HTML body. - /// - [JsonProperty("html_body")] public String HTMLBody { get; set; } - /// - /// Gets or sets the text body. - /// - /// - /// The text body. - /// - [JsonProperty("text_body")] public String TextBody { get; set; } - /// - /// Gets or sets the attachments. - /// - /// - /// The attachments. - /// - [JsonProperty("attachments")] public List Attachments { get; set; } - } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponse.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponse.cs index e54fa5d..80a5d8f 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponse.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponse.cs @@ -1,5 +1,4 @@ using System; -using Newtonsoft.Json; namespace MessagingService.Service.Services.Email.Smtp2Go { @@ -8,22 +7,8 @@ namespace MessagingService.Service.Services.Email.Smtp2Go [ExcludeFromCodeCoverage] public class Smtp2GoSendEmailResponse { - /// - /// Gets or sets the request identifier. - /// - /// - /// The request identifier. - /// - [JsonProperty("request_id")] public String RequestId { get; set; } - /// - /// Gets or sets the data. - /// - /// - /// The data. - /// - [JsonProperty("data")] public Smtp2GoSendEmailResponseData Data { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponseData.cs b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponseData.cs index 90b0c51..d577a81 100644 --- a/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponseData.cs +++ b/MessagingService.BusinessLogic/Services/EmailServices/Smtp2Go/Smtp2GoSendEmailResponseData.cs @@ -1,5 +1,4 @@ using System; -using Newtonsoft.Json; namespace MessagingService.Service.Services.Email.Smtp2Go { @@ -8,58 +7,16 @@ namespace MessagingService.Service.Services.Email.Smtp2Go [ExcludeFromCodeCoverage] public class Smtp2GoSendEmailResponseData { - /// - /// Gets or sets the failed. - /// - /// - /// The failed. - /// - [JsonProperty("failed")] public Int32 Failed { get; set; } - /// - /// Gets or sets the failures. - /// - /// - /// The failures. - /// - [JsonProperty("failures")] public String[] Failures { get; set; } - /// - /// Gets or sets the email identifier. - /// - /// - /// The email identifier. - /// - [JsonProperty("email_id")] public String EmailId { get; set; } - /// - /// Gets or sets the succeesful. - /// - /// - /// The succeesful. - /// - [JsonProperty("succeeded")] public Int32 Succeesful { get; set; } - /// - /// Gets or sets the error. - /// - /// - /// The error. - /// - [JsonProperty("error")] public String Error { get; set; } - /// - /// Gets or sets the error code. - /// - /// - /// The error code. - /// - [JsonProperty("error_code")] public String ErrorCode { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksFailureReason.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksFailureReason.cs index 8d3e7a9..c0375c4 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksFailureReason.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksFailureReason.cs @@ -2,39 +2,14 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - - /// - /// - /// + [ExcludeFromCodeCoverage] public class TheSMSWorksFailureReason { - /// - /// Gets or sets the code. - /// - /// - /// The code. - /// - [JsonProperty("code")] public Int32 Code { get; set; } - /// - /// Gets or sets the details. - /// - /// - /// The details. - /// - [JsonProperty("details")] public String Details { get; set; } - /// - /// Gets or sets a value indicating whether this is permanent. - /// - /// - /// true if permanent; otherwise, false. - /// - [JsonProperty("permanent")] public Boolean Permanent { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksGetMessageResponse.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksGetMessageResponse.cs index 87e340f..05ce890 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksGetMessageResponse.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSMSWorksGetMessageResponse.cs @@ -2,156 +2,39 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - /// - /// - /// [ExcludeFromCodeCoverage] public class TheSMSWorksGetMessageResponse { - /// - /// Gets or sets the batch identifier. - /// - /// - /// The batch identifier. - /// - [JsonProperty("batchid")] public String BatchId { get; set; } - /// - /// Gets or sets the content. - /// - /// - /// The content. - /// - [JsonProperty("content")] public String Content { get; set; } - /// - /// Gets or sets the created. - /// - /// - /// The created. - /// - [JsonProperty("created")] public String Created { get; set; } - /// - /// Gets or sets the customerid. - /// - /// - /// The customerid. - /// - [JsonProperty("customerid")] public String Customerid { get; set; } - /// - /// Gets or sets the deliveryreporturl. - /// - /// - /// The deliveryreporturl. - /// - [JsonProperty("deliveryreporturl")] public String Deliveryreporturl { get; set; } - /// - /// Gets or sets the destination. - /// - /// - /// The destination. - /// - [JsonProperty("destination")] public String Destination { get; set; } - /// - /// Gets or sets the failurereason. - /// - /// - /// The failurereason. - /// - [JsonProperty("failurereason")] public TheSMSWorksFailureReason Failurereason { get; set; } - /// - /// Gets or sets the identifier. - /// - /// - /// The identifier. - /// - [JsonProperty("id")] public String Id { get; set; } - /// - /// Gets or sets the identifier. - /// - /// - /// The identifier. - /// - [JsonProperty("identifier")] public String Identifier { get; set; } - /// - /// Gets or sets the keyword. - /// - /// - /// The keyword. - /// - [JsonProperty("keyword")] public String Keyword { get; set; } - /// - /// Gets or sets the messageid. - /// - /// - /// The messageid. - /// - [JsonProperty("messageid")] public String Messageid { get; set; } - /// - /// Gets or sets the modified. - /// - /// - /// The modified. - /// - [JsonProperty("modified")] public String Modified { get; set; } - /// - /// Gets or sets the schedule. - /// - /// - /// The schedule. - /// - [JsonProperty("schedule")] public String Schedule { get; set; } - /// - /// Gets or sets the status. - /// - /// - /// The status. - /// - [JsonProperty("status")] public String Status { get; set; } - - /// - /// Gets or sets the sender. - /// - /// - /// The sender. - /// - [JsonProperty("sender")] public String Sender { get; set; } - /// - /// Gets or sets the tag. - /// - /// - /// The tag. - /// - [JsonProperty("tag")] public String Tag { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModel.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModel.cs index 346ff45..cb3768d 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModel.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModel.cs @@ -2,27 +2,12 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; [ExcludeFromCodeCoverage] public class TheSmsWorksExtendedErrorModel { - /// - /// Gets or sets the message. - /// - /// - /// The message. - /// - [JsonProperty("message")] public String Message { get; set; } - /// - /// Gets or sets the errors. - /// - /// - /// The errors. - /// - [JsonProperty("errors")] public TheSmsWorksExtendedErrorModelError[] Errors { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelError.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelError.cs index dc52657..b65f59d 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelError.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelError.cs @@ -2,63 +2,20 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; [ExcludeFromCodeCoverage] public class TheSmsWorksExtendedErrorModelError { - /// - /// Gets or sets the code. - /// - /// - /// The code. - /// - [JsonProperty("code")] public String Code { get; set; } - /// - /// Gets or sets the field errors. - /// - /// - /// The field errors. - /// - [JsonProperty("errors")] public TheSmsWorksExtendedErrorModelFieldError[] FieldErrors { get; set; } - /// - /// Gets or sets the in. - /// - /// - /// The in. - /// - [JsonProperty("in")] public String In { get; set; } - /// - /// Gets or sets the message. - /// - /// - /// The message. - /// - [JsonProperty("message")] public String Message { get; set; } - /// - /// Gets or sets the name. - /// - /// - /// The name. - /// - [JsonProperty("name")] public String Name { get; set; } - /// - /// Gets or sets the path. - /// - /// - /// The path. - /// - [JsonProperty("path")] public String[] Path { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelFieldError.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelFieldError.cs index 1ea2eb5..a9e675e 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelFieldError.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksExtendedErrorModelFieldError.cs @@ -2,48 +2,18 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class TheSmsWorksExtendedErrorModelFieldError { - [JsonProperty("code")] public String Code { get; set; } - /// - /// Gets or sets the parameters. - /// - /// - /// The parameters. - /// - [JsonProperty("params")] public String[] Params { get; set; } - /// - /// Gets or sets the message. - /// - /// - /// The message. - /// - [JsonProperty("message")] public String Message { get; set; } - /// - /// Gets or sets the path. - /// - /// - /// The path. - /// - [JsonProperty("path")] public String[] Path { get; set; } - /// - /// Gets or sets the description. - /// - /// - /// The description. - /// - [JsonProperty("description")] public String Description { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs index be2dbe8..e2b379b 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs @@ -1,7 +1,7 @@ using System; -using System.Collections.Generic; using System.Security.Authentication; using System.Text; +using Shared.Serialisation; namespace MessagingService.BusinessLogic.Services.SMSServices.TheSMSWorks { @@ -10,11 +10,8 @@ namespace MessagingService.BusinessLogic.Services.SMSServices.TheSMSWorks using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Newtonsoft.Json; - using Requests; using Shared.Exceptions; using Shared.Extensions; - using Shared.General; public record SmsWorksConfig { public String BaseAddress { get; set; } @@ -53,14 +50,14 @@ public async Task SendSMS(Guid messageId, // Create the Auth Request TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = Configuration.CustomerId, Key = Configuration.Key, Secret = Configuration.Secret }; - String apiTokenRequestSerialised = JsonConvert.SerializeObject(apiTokenRequest).ToLower(); + String apiTokenRequestSerialised = StringSerialiser.Serialise(apiTokenRequest).ToLower(); StringContent content = new(apiTokenRequestSerialised, Encoding.UTF8, "application/json"); // First do the authentication HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{Configuration.BaseAddress}auth/token", content, cancellationToken); if (apiTokenHttpResponse.IsSuccessStatusCode) { - TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject(await apiTokenHttpResponse.Content.ReadAsStringAsync(cancellationToken)); + TheSmsWorksTokenResponse apiTokenResponse = StringSerialiser.Deserialise(await apiTokenHttpResponse.Content.ReadAsStringAsync(cancellationToken)); // Now do the actual send TheSmsWorksSendSMSRequest apiSendSmsRequest = new() { @@ -72,7 +69,7 @@ public async Task SendSMS(Guid messageId, Ttl = 0 }; - String apiSendSMSMessageRequestSerialised = JsonConvert.SerializeObject(apiSendSmsRequest).ToLower(); + String apiSendSMSMessageRequestSerialised = StringSerialiser.Serialise(apiSendSmsRequest).ToLower(); content = new StringContent(apiSendSMSMessageRequestSerialised, Encoding.UTF8, "application/json"); this.HttpClient.DefaultRequestHeaders.Add("Authorization", apiTokenResponse.Token); @@ -80,7 +77,7 @@ public async Task SendSMS(Guid messageId, if (apiSendSMSMessageHttpResponse.IsSuccessStatusCode) { // Message has been sent - TheSmsWorksSendSMSResponse apiTheSmsWorksSendSmsResponse = JsonConvert.DeserializeObject(await apiSendSMSMessageHttpResponse.Content.ReadAsStringAsync(cancellationToken)); + TheSmsWorksSendSMSResponse apiTheSmsWorksSendSmsResponse = StringSerialiser.Deserialise(await apiSendSMSMessageHttpResponse.Content.ReadAsStringAsync(cancellationToken)); response = new SMSServiceProxyResponse { ApiCallSuccessful = true, SMSIdentifier = apiTheSmsWorksSendSmsResponse.MessageId, }; } @@ -102,21 +99,21 @@ public async Task GetMessageStatus(String providerReferen // Create the Auth Request TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = Configuration.CustomerId, Key = Configuration.Key, Secret = Configuration.Secret }; - String apiTokenRequestSerialised = JsonConvert.SerializeObject(apiTokenRequest).ToLower(); + String apiTokenRequestSerialised = StringSerialiser.Serialise(apiTokenRequest).ToLower(); StringContent content = new(apiTokenRequestSerialised, Encoding.UTF8, "application/json"); // First do the authentication HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{Configuration.BaseAddress}auth/token", content, cancellationToken); if (apiTokenHttpResponse.IsSuccessStatusCode) { - TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject(await apiTokenHttpResponse.Content.ReadAsStringAsync(cancellationToken)); + TheSmsWorksTokenResponse apiTokenResponse = StringSerialiser.Deserialise(await apiTokenHttpResponse.Content.ReadAsStringAsync(cancellationToken)); this.HttpClient.DefaultRequestHeaders.Add("Authorization", apiTokenResponse.Token); HttpResponseMessage apiGetSMSMessageHttpResponse = await this.HttpClient.GetAsync($"{Configuration.BaseAddress}messages/{providerReference}", cancellationToken); if (apiGetSMSMessageHttpResponse.IsSuccessStatusCode) { // Message has been sent - TheSMSWorksGetMessageResponse apiSmsWorksGetMessageResponse = JsonConvert.DeserializeObject(await apiGetSMSMessageHttpResponse.Content.ReadAsStringAsync(cancellationToken)); + TheSMSWorksGetMessageResponse apiSmsWorksGetMessageResponse = StringSerialiser.Deserialise(await apiGetSMSMessageHttpResponse.Content.ReadAsStringAsync(cancellationToken)); response = new MessageStatusResponse { ApiStatusCode = apiGetSMSMessageHttpResponse.StatusCode, MessageStatus = this.TranslateMessageStatus(apiSmsWorksGetMessageResponse.Status), ProviderStatusDescription = apiSmsWorksGetMessageResponse.Status, Timestamp = DateTime.Parse(apiSmsWorksGetMessageResponse.Modified) }; } diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSRequest.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSRequest.cs index 5064558..a1895f0 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSRequest.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSRequest.cs @@ -2,63 +2,20 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; [ExcludeFromCodeCoverage] public class TheSmsWorksSendSMSRequest { - /// - /// Gets or sets the sender. - /// - /// - /// The sender. - /// - [JsonProperty("sender")] public String Sender { get; set; } - /// - /// Gets or sets the destination. - /// - /// - /// The destination. - /// - [JsonProperty("destination")] public String Destination { get; set; } - /// - /// Gets or sets the content. - /// - /// - /// The content. - /// - [JsonProperty("content")] public String Content { get; set; } - /// - /// Gets or sets the schedule. - /// - /// - /// The schedule. - /// - [JsonProperty("schedule")] public String Schedule { get; set; } - /// - /// Gets or sets the tag. - /// - /// - /// The tag. - /// - [JsonProperty("tag")] public String Tag { get; set; } - /// - /// Gets or sets the TTL. - /// - /// - /// The TTL. - /// - [JsonProperty("ttl")] public Int32 Ttl { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSResponse.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSResponse.cs index 81d1ea6..7d67882 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSResponse.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksSendSMSResponse.cs @@ -2,36 +2,14 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class TheSmsWorksSendSMSResponse { - /// - /// Gets or sets the message identifier. - /// - /// - /// The message identifier. - /// - [JsonProperty("messageid")] public String MessageId { get; set; } - /// - /// Gets or sets the status. - /// - /// - /// The status. - /// - [JsonProperty("status")] public String Status { get; set; } - /// - /// Gets or sets the credits. - /// - /// - /// The credits. - /// - [JsonProperty("credits")] public Int32 Credits { get; set; } } } \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksTokenRequest.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksTokenRequest.cs index 28ac393..52fb94e 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksTokenRequest.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksTokenRequest.cs @@ -2,36 +2,14 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class TheSmsWorksTokenRequest { - /// - /// Gets or sets the customer identifier. - /// - /// - /// The customer identifier. - /// - [JsonProperty("customerid")] public String CustomerId { get; set; } - /// - /// Gets or sets the key. - /// - /// - /// The key. - /// - [JsonProperty("key")] public String Key { get; set; } - /// - /// Gets or sets the secret. - /// - /// - /// The secret. - /// - [JsonProperty("secret")] public String Secret { get; set; } } } \ No newline at end of file diff --git a/MessagingService.Client/MessagingService.Client.csproj b/MessagingService.Client/MessagingService.Client.csproj index ba49f2d..c5ab6c1 100644 --- a/MessagingService.Client/MessagingService.Client.csproj +++ b/MessagingService.Client/MessagingService.Client.csproj @@ -6,9 +6,8 @@ - - - + + diff --git a/MessagingService.Client/MessagingServiceClient.cs b/MessagingService.Client/MessagingServiceClient.cs index 62c29f0..16b469a 100644 --- a/MessagingService.Client/MessagingServiceClient.cs +++ b/MessagingService.Client/MessagingServiceClient.cs @@ -4,13 +4,10 @@ namespace MessagingService.Client { using System; using System.Net.Http; - using System.Net.Http.Headers; - using System.Text; using System.Threading; using System.Threading.Tasks; using ClientProxyBase; using DataTransferObjects; - using Newtonsoft.Json; using SimpleResults; public class MessagingServiceClient : ClientProxyBase, IMessagingServiceClient @@ -26,7 +23,9 @@ public class MessagingServiceClient : ClientProxyBase, IMessagingServiceClient #region Constructors public MessagingServiceClient(Func baseAddressResolver, - HttpClient httpClient) : base(httpClient) + HttpClient httpClient, + Func serialise, + Func deserialise) : base(httpClient, serialise, deserialise) { this.BaseAddressResolver = baseAddressResolver; } @@ -43,7 +42,7 @@ public async Task SendEmail(String accessToken, try { - Result> result = await this.SendHttpPostRequest>(requestUri, sendEmailRequest, accessToken, cancellationToken); + Result result = await this.Post(requestUri, sendEmailRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -65,7 +64,7 @@ public async Task ResendEmail(String accessToken, String requestUri = this.BuildRequestUrl("/api/email/resend"); try { - Result> result = await this.SendHttpPostRequest>(requestUri, resendEmailRequest, accessToken, cancellationToken); + Result result = await this.Post(requestUri, resendEmailRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -88,7 +87,7 @@ public async Task SendSMS(String accessToken, try { - Result> result = await this.SendHttpPostRequest>(requestUri, sendSMSRequest, accessToken, cancellationToken); + Result result = await this.Post(requestUri, sendSMSRequest, accessToken, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); diff --git a/MessagingService.DataTransferObjects/EmailAttachment.cs b/MessagingService.DataTransferObjects/EmailAttachment.cs index e8a4074..28052da 100644 --- a/MessagingService.DataTransferObjects/EmailAttachment.cs +++ b/MessagingService.DataTransferObjects/EmailAttachment.cs @@ -2,7 +2,6 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; /// /// @@ -10,35 +9,10 @@ [ExcludeFromCodeCoverage] public class EmailAttachment { - #region Properties - - /// - /// Gets or sets the file data. - /// - /// - /// The file data. - /// - [JsonProperty("file_data")] public String FileData { get; set; } - /// - /// Gets or sets the filename. - /// - /// - /// The filename. - /// - [JsonProperty("file_name")] public String Filename { get; set; } - /// - /// Gets or sets the type of the file. - /// - /// - /// The type of the file. - /// - [JsonProperty("file_type")] public FileType FileType { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/MessagingService.DataTransferObjects.csproj b/MessagingService.DataTransferObjects/MessagingService.DataTransferObjects.csproj index bb14ca7..e3cccf9 100644 --- a/MessagingService.DataTransferObjects/MessagingService.DataTransferObjects.csproj +++ b/MessagingService.DataTransferObjects/MessagingService.DataTransferObjects.csproj @@ -9,7 +9,7 @@ - + diff --git a/MessagingService.DataTransferObjects/ResendEmailRequest.cs b/MessagingService.DataTransferObjects/ResendEmailRequest.cs index cd2a89f..e99e302 100644 --- a/MessagingService.DataTransferObjects/ResendEmailRequest.cs +++ b/MessagingService.DataTransferObjects/ResendEmailRequest.cs @@ -2,15 +2,11 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class ResendEmailRequest { - [JsonProperty("message_id")] public Guid MessageId { get; set; } - - [JsonProperty("connection_identifier")] public Guid ConnectionIdentifier { get; set; } } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/ResendSMSRequest.cs b/MessagingService.DataTransferObjects/ResendSMSRequest.cs index 4c16575..5756e36 100644 --- a/MessagingService.DataTransferObjects/ResendSMSRequest.cs +++ b/MessagingService.DataTransferObjects/ResendSMSRequest.cs @@ -2,14 +2,11 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class ResendSMSRequest{ - [JsonProperty("message_id")] public Guid MessageId{ get; set; } - [JsonProperty("connection_identifier")] public Guid ConnectionIdentifier{ get; set; } } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/SendEmailRequest.cs b/MessagingService.DataTransferObjects/SendEmailRequest.cs index b74ec3b..b9381c4 100644 --- a/MessagingService.DataTransferObjects/SendEmailRequest.cs +++ b/MessagingService.DataTransferObjects/SendEmailRequest.cs @@ -3,8 +3,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - + [ExcludeFromCodeCoverage] public class SendEmailRequest { @@ -13,80 +12,20 @@ public SendEmailRequest() this.EmailAttachments = new List(); } - #region Properties - - /// - /// Gets or sets the message identifier. - /// - /// - /// The message identifier. - /// - [JsonProperty("message_id")] public Guid? MessageId { get; set; } - /// - /// Gets or sets the body. - /// - /// - /// The body. - /// - [JsonProperty("body")] public String Body { get; set; } - /// - /// Gets or sets the connection identifier. - /// - /// - /// The connection identifier. - /// - [JsonProperty("connection_identifier")] public Guid ConnectionIdentifier { get; set; } - /// - /// Gets or sets from address. - /// - /// - /// From address. - /// - [JsonProperty("from_address")] public String FromAddress { get; set; } - /// - /// Gets or sets a value indicating whether this instance is HTML. - /// - /// - /// true if this instance is HTML; otherwise, false. - /// - [JsonProperty("is_html")] public Boolean IsHtml { get; set; } - /// - /// Gets or sets the subject. - /// - /// - /// The subject. - /// - [JsonProperty("subject")] public String Subject { get; set; } - /// - /// Gets or sets to addresses. - /// - /// - /// To addresses. - /// - [JsonProperty("to_addresses")] public List ToAddresses { get; set; } - /// - /// Gets or sets the email attachments. - /// - /// - /// The email attachments. - /// - [JsonProperty("email_attachements")] public List EmailAttachments { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/SendEmailResponse.cs b/MessagingService.DataTransferObjects/SendEmailResponse.cs index 737b780..5d4d0bf 100644 --- a/MessagingService.DataTransferObjects/SendEmailResponse.cs +++ b/MessagingService.DataTransferObjects/SendEmailResponse.cs @@ -2,25 +2,10 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; - - /// - /// - /// + [ExcludeFromCodeCoverage] public class SendEmailResponse { - #region Properties - - /// - /// Gets or sets the message identifier. - /// - /// - /// The message identifier. - /// - [JsonProperty("message_id")] public Guid MessageId { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/SendSMSRequest.cs b/MessagingService.DataTransferObjects/SendSMSRequest.cs index eb6b15e..274b18f 100644 --- a/MessagingService.DataTransferObjects/SendSMSRequest.cs +++ b/MessagingService.DataTransferObjects/SendSMSRequest.cs @@ -1,59 +1,19 @@ namespace MessagingService.DataTransferObjects { - using Newtonsoft.Json; using System; using System.Diagnostics.CodeAnalysis; [ExcludeFromCodeCoverage] public class SendSMSRequest { - #region Properties - - /// - /// Gets or sets the connection identifier. - /// - /// - /// The connection identifier. - /// - [JsonProperty("connection_identifier")] public Guid ConnectionIdentifier { get; set; } - /// - /// Gets or sets the destination. - /// - /// - /// The destination. - /// - [JsonProperty("destination")] public String Destination { get; set; } - /// - /// Gets or sets the message. - /// - /// - /// The message. - /// - [JsonProperty("message")] public String Message { get; set; } - /// - /// Gets or sets the message identifier. - /// - /// - /// The message identifier. - /// - [JsonProperty("message_id")] public Guid? MessageId { get; set; } - /// - /// Gets or sets the sender. - /// - /// - /// The sender. - /// - [JsonProperty("sender")] public String Sender { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.DataTransferObjects/SendSMSResponse.cs b/MessagingService.DataTransferObjects/SendSMSResponse.cs index 9649a57..280c17d 100644 --- a/MessagingService.DataTransferObjects/SendSMSResponse.cs +++ b/MessagingService.DataTransferObjects/SendSMSResponse.cs @@ -2,22 +2,10 @@ { using System; using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; [ExcludeFromCodeCoverage] public class SendSMSResponse { - #region Properties - - /// - /// Gets or sets the message identifier. - /// - /// - /// The message identifier. - /// - [JsonProperty("message_id")] public Guid MessageId { get; set; } - - #endregion } } \ No newline at end of file diff --git a/MessagingService.EmailAggregate.Tests/MessagingService.EmailAggregate.Tests.csproj b/MessagingService.EmailAggregate.Tests/MessagingService.EmailAggregate.Tests.csproj index af7d75a..6f073d9 100644 --- a/MessagingService.EmailAggregate.Tests/MessagingService.EmailAggregate.Tests.csproj +++ b/MessagingService.EmailAggregate.Tests/MessagingService.EmailAggregate.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/MessagingService.EmailMessage.DomainEvents/MessagingService.EmailMessage.DomainEvents.csproj b/MessagingService.EmailMessage.DomainEvents/MessagingService.EmailMessage.DomainEvents.csproj index 37f7a6d..efde085 100644 --- a/MessagingService.EmailMessage.DomainEvents/MessagingService.EmailMessage.DomainEvents.csproj +++ b/MessagingService.EmailMessage.DomainEvents/MessagingService.EmailMessage.DomainEvents.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/MessagingService.EmailMessageAggregate/MessagingService.EmailMessageAggregate.csproj b/MessagingService.EmailMessageAggregate/MessagingService.EmailMessageAggregate.csproj index af53454..c6a57a8 100644 --- a/MessagingService.EmailMessageAggregate/MessagingService.EmailMessageAggregate.csproj +++ b/MessagingService.EmailMessageAggregate/MessagingService.EmailMessageAggregate.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/MessagingService.IntegrationTesting.Helpers/MessagingService.IntegrationTesting.Helpers.csproj b/MessagingService.IntegrationTesting.Helpers/MessagingService.IntegrationTesting.Helpers.csproj index e5bd871..cdf00f0 100644 --- a/MessagingService.IntegrationTesting.Helpers/MessagingService.IntegrationTesting.Helpers.csproj +++ b/MessagingService.IntegrationTesting.Helpers/MessagingService.IntegrationTesting.Helpers.csproj @@ -7,7 +7,7 @@ - + diff --git a/MessagingService.IntegrationTests/Common/DockerHelper.cs b/MessagingService.IntegrationTests/Common/DockerHelper.cs index 85835e3..fdb46e9 100644 --- a/MessagingService.IntegrationTests/Common/DockerHelper.cs +++ b/MessagingService.IntegrationTests/Common/DockerHelper.cs @@ -10,6 +10,7 @@ namespace MessagingService.IntegrationTests.Common using Ductus.FluentDocker.Services.Extensions; using global::Shared.IntegrationTesting; using global::Shared.Logger; + using global::Shared.Serialisation; using IntegrationTesting.Helpers; using Microsoft.AspNetCore.Http; using SecurityService.Client; @@ -82,11 +83,21 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do HttpClient httpClient = CreateHttpClient(); - this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); - this.MessagingServiceClient = new MessagingServiceClient(MessagingServiceBaseAddressResolver, httpClient); + this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient, Serialise, Deserialise); + this.MessagingServiceClient = new MessagingServiceClient(MessagingServiceBaseAddressResolver, httpClient, Serialise, Deserialise); } #endregion + String Serialise(Object arg) + { + return StringSerialiser.Serialise(arg, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); + } + + Object Deserialise(String arg, Type type) + { + return StringSerialiser.DeserializeObject(arg, type, new SerialiserOptions(SerialiserPropertyFormat.SnakeCase)); + } + private HttpClient CreateHttpClient() { // Set up test HttpContext DefaultHttpContext context = new(); diff --git a/MessagingService.IntegrationTests/Common/TestingContext.cs b/MessagingService.IntegrationTests/Common/TestingContext.cs index 14bf334..9a19349 100644 --- a/MessagingService.IntegrationTests/Common/TestingContext.cs +++ b/MessagingService.IntegrationTests/Common/TestingContext.cs @@ -1,13 +1,11 @@ using Shared.Logger; using System; using System.Collections.Generic; -using System.Text; namespace MessagingService.IntegrationTests.Common { using System.Linq; using DataTransferObjects; - using SecurityService.DataTransferObjects.Responses; using Shouldly; public class TestingContext diff --git a/MessagingService.IntegrationTests/Email/SendEmailSteps.cs b/MessagingService.IntegrationTests/Email/SendEmailSteps.cs index b64a090..4e30494 100644 --- a/MessagingService.IntegrationTests/Email/SendEmailSteps.cs +++ b/MessagingService.IntegrationTests/Email/SendEmailSteps.cs @@ -3,21 +3,11 @@ namespace MessagingService.IntegrationTests.Email { using System.Collections.Generic; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Text; - using System.Threading; using System.Threading.Tasks; using Common; using DataTransferObjects; - using global::Shared.IntegrationTesting; using IntegrationTesting.Helpers; - using Newtonsoft.Json; using Reqnroll; - using Shared; - using Shouldly; [Binding] [Scope(Tag = "email")] diff --git a/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj b/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj index e31cd00..c32d9ad 100644 --- a/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj +++ b/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj @@ -6,7 +6,7 @@ - + @@ -14,9 +14,9 @@ - - - + + + all diff --git a/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs b/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs index cac611a..fd67c5c 100644 --- a/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs +++ b/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs @@ -113,53 +113,53 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa { #line 4 #line hidden - global::Reqnroll.Table table1 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table6 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Description"}); - table1.AddRow(new string[] { + table6.AddRow(new string[] { "messagingService", "Messaging REST Scope", "A scope for Messaging REST"}); #line 6 - await testRunner.GivenAsync("I create the following api scopes", ((string)(null)), table1, "Given "); + await testRunner.GivenAsync("I create the following api scopes", ((string)(null)), table6, "Given "); #line hidden - global::Reqnroll.Table table2 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table7 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Secret", "Scopes", "UserClaims"}); - table2.AddRow(new string[] { + table7.AddRow(new string[] { "messagingService", "Messaging REST", "Secret1", "messagingService", ""}); #line 10 - await testRunner.GivenAsync("the following api resources exist", ((string)(null)), table2, "Given "); + await testRunner.GivenAsync("the following api resources exist", ((string)(null)), table7, "Given "); #line hidden - global::Reqnroll.Table table3 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table8 = new global::Reqnroll.Table(new string[] { "ClientId", "ClientName", "Secret", "Scopes", "GrantTypes"}); - table3.AddRow(new string[] { + table8.AddRow(new string[] { "serviceClient", "Service Client", "Secret1", "messagingService", "client_credentials"}); #line 14 - await testRunner.GivenAsync("the following clients exist", ((string)(null)), table3, "Given "); + await testRunner.GivenAsync("the following clients exist", ((string)(null)), table8, "Given "); #line hidden - global::Reqnroll.Table table4 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table9 = new global::Reqnroll.Table(new string[] { "ClientId"}); - table4.AddRow(new string[] { + table9.AddRow(new string[] { "serviceClient"}); #line 18 - await testRunner.GivenAsync("I have a token to access the messaging service resource", ((string)(null)), table4, "Given "); + await testRunner.GivenAsync("I have a token to access the messaging service resource", ((string)(null)), table9, "Given "); #line hidden } @@ -193,16 +193,16 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa #line 4 await this.FeatureBackgroundAsync(); #line hidden - global::Reqnroll.Table table5 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table10 = new global::Reqnroll.Table(new string[] { "Sender", "Destination", "Message"}); - table5.AddRow(new string[] { + table10.AddRow(new string[] { "TestSender", "07777777771", "TestSMSMessage"}); #line 24 - await testRunner.GivenAsync("I send the following SMS Messages", ((string)(null)), table5, "Given "); + await testRunner.GivenAsync("I send the following SMS Messages", ((string)(null)), table10, "Given "); #line hidden } await this.ScenarioCleanupAsync(); diff --git a/MessagingService.IntegrationTests/Shared/SharedSteps.cs b/MessagingService.IntegrationTests/Shared/SharedSteps.cs index 4f5f892..8f86975 100644 --- a/MessagingService.IntegrationTests/Shared/SharedSteps.cs +++ b/MessagingService.IntegrationTests/Shared/SharedSteps.cs @@ -1,11 +1,7 @@ using MessagingService.IntegrationTests.Common; -using SecurityService.DataTransferObjects.Requests; -using SecurityService.DataTransferObjects.Responses; -using Shouldly; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/MessagingService.SMSMessage.DomainEvents/MessagingService.SMSMessage.DomainEvents.csproj b/MessagingService.SMSMessage.DomainEvents/MessagingService.SMSMessage.DomainEvents.csproj index 18a32af..da4e888 100644 --- a/MessagingService.SMSMessage.DomainEvents/MessagingService.SMSMessage.DomainEvents.csproj +++ b/MessagingService.SMSMessage.DomainEvents/MessagingService.SMSMessage.DomainEvents.csproj @@ -6,7 +6,7 @@ - + diff --git a/MessagingService.SMSMessageAggregate/MessagingService.SMSMessageAggregate.csproj b/MessagingService.SMSMessageAggregate/MessagingService.SMSMessageAggregate.csproj index 369fa61..77c0de3 100644 --- a/MessagingService.SMSMessageAggregate/MessagingService.SMSMessageAggregate.csproj +++ b/MessagingService.SMSMessageAggregate/MessagingService.SMSMessageAggregate.csproj @@ -6,7 +6,7 @@ - + diff --git a/MessagingService/Bootstrapper/MiddlewareRegistry.cs b/MessagingService/Bootstrapper/MiddlewareRegistry.cs index 4f0b729..3360634 100644 --- a/MessagingService/Bootstrapper/MiddlewareRegistry.cs +++ b/MessagingService/Bootstrapper/MiddlewareRegistry.cs @@ -3,6 +3,10 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi; using Shared.Authorisation; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Shared.Serialisation; namespace MessagingService.Bootstrapper { @@ -50,6 +54,8 @@ public MiddlewareRegistry() { RequestResponseMiddlewareLoggingConfig config = new(middlewareLogLevel, logRequests, logResponses); this.AddSingleton(config); + + this.ConfigureHttpJsonOptions(jsonOptions => JsonSerializerConfiguration.ConfigureMinimalApi(jsonOptions.SerializerOptions)); } private void ConfigureAuthentication() { @@ -87,11 +93,11 @@ private void ConfigureAuthentication() { this.AddClientCredentialsOnlyPolicy(); this.AddClientCredentialsHandler(); - this.ConfigureHttpJsonOptions(options => - { - options.SerializerOptions.PropertyNamingPolicy = new SnakeCaseNamingPolicy(); - options.SerializerOptions.PropertyNameCaseInsensitive = true; // optional, but safer - }); + //this.ConfigureHttpJsonOptions(options => + //{ + // options.SerializerOptions.PropertyNamingPolicy = new SnakeCaseNamingPolicy(); + // options.SerializerOptions.PropertyNameCaseInsensitive = true; // optional, but safer + //}); } private void ConfigureSwagger() { @@ -127,3 +133,57 @@ private void ConfigureSwagger() { } } } + +public static class JsonSerializerConfiguration +{ + public static void ConfigureMinimalApi(JsonSerializerOptions serializerOptions) + { + var defaultOptions = SystemTextJsonSerializer.GetDefaultJsonSerializerOptions(); + serializerOptions.PropertyNamingPolicy = defaultOptions.PropertyNamingPolicy; + serializerOptions.DictionaryKeyPolicy = defaultOptions.DictionaryKeyPolicy; + serializerOptions.ReferenceHandler = defaultOptions.ReferenceHandler; + serializerOptions.WriteIndented = defaultOptions.WriteIndented; + serializerOptions.Converters.Add(new UtcDateTimeJsonConverter()); + serializerOptions.Converters.Add(new NullableUtcDateTimeJsonConverter()); + + } + + private sealed class UtcDateTimeJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var value = reader.GetDateTime(); + return value.Kind == DateTimeKind.Utc ? value : value.ToUniversalTime(); + } + + public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.Kind == DateTimeKind.Utc ? value : value.ToUniversalTime()); + } + } + + private sealed class NullableUtcDateTimeJsonConverter : System.Text.Json.Serialization.JsonConverter + { + public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.Null) + { + return null; + } + + var value = reader.GetDateTime(); + return value.Kind == DateTimeKind.Utc ? value : value.ToUniversalTime(); + } + + public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options) + { + if (value.HasValue == false) + { + writer.WriteNullValue(); + return; + } + + writer.WriteStringValue(value.Value.Kind == DateTimeKind.Utc ? value.Value : value.Value.ToUniversalTime()); + } + } +} diff --git a/MessagingService/Bootstrapper/SerialiserRegistry.cs b/MessagingService/Bootstrapper/SerialiserRegistry.cs new file mode 100644 index 0000000..315f07d --- /dev/null +++ b/MessagingService/Bootstrapper/SerialiserRegistry.cs @@ -0,0 +1,19 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Lamar; +using Microsoft.Extensions.DependencyInjection; +using Shared.Serialisation; + +namespace MessagingService.Bootstrapper; + +[ExcludeFromCodeCoverage] +public class SerialiserRegistry : ServiceRegistry +{ + public SerialiserRegistry() + { + this.AddSingleton(); + this.AddSingleton>(_ => obj => StringSerialiser.Serialise(obj)); + this.AddSingleton>(_ => (str, type) => StringSerialiser.DeserializeObject(str, type)); + this.AddSingleton(SystemTextJsonSerializer.GetDefaultJsonSerializerOptions()); + } +} \ No newline at end of file diff --git a/MessagingService/Handlers/DomainEventHandlers.cs b/MessagingService/Handlers/DomainEventHandlers.cs index 5393ab0..73a90b1 100644 --- a/MessagingService/Handlers/DomainEventHandlers.cs +++ b/MessagingService/Handlers/DomainEventHandlers.cs @@ -4,8 +4,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Shared.DomainDrivenDesign.EventSourcing; using Shared.EventStore.Aggregate; using Shared.EventStore.EventHandling; @@ -50,7 +48,7 @@ public static async Task HandleDomainEvent(HttpRequest request, } catch (Exception ex) { - string domainEventData = JsonConvert.SerializeObject(domainEvent); + string domainEventData = StringSerialiser.Serialise(domainEvent); Logger.LogError($"Failed to process event. Data received [{domainEventData}]", ex); throw; } @@ -74,38 +72,14 @@ private static async Task GetDomainEvent(HttpRequest request, obje if (type == null) throw new NotFoundException($"Failed to find a domain event with type {eventType}"); - var resolver = new JsonIgnoreAttributeIgnorerContractResolver(); - var settings = new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.All, - Formatting = Formatting.Indented, - DateTimeZoneHandling = DateTimeZoneHandling.Utc, - ContractResolver = resolver - }; - if (type.IsSubclassOf(typeof(DomainEvent))) { - string json = JsonConvert.SerializeObject(domainEvent, settings); + String json = StringSerialiser.Serialise(domainEvent); var factory = new DomainEventFactory(); - string validatedJson = ValidateEvent(json); - return factory.CreateDomainEvent(validatedJson, type); + return factory.CreateDomainEvent(json, type); } return null; } - - private static string ValidateEvent(string domainEventJson) - { - var domainEvent = JObject.Parse(domainEventJson); - - if (!domainEvent.ContainsKey("eventId") || - domainEvent["eventId"]!.ToObject() == Guid.Empty) - { - throw new ArgumentException("Domain Event must contain an Event Id"); - } - - return domainEventJson; - } } \ No newline at end of file diff --git a/MessagingService/MessagingService.csproj b/MessagingService/MessagingService.csproj index 59f26b4..19c3acc 100644 --- a/MessagingService/MessagingService.csproj +++ b/MessagingService/MessagingService.csproj @@ -21,13 +21,13 @@ - - + + - - + + diff --git a/MessagingService/Startup.cs b/MessagingService/Startup.cs index 0a932c4..e2a9e60 100644 --- a/MessagingService/Startup.cs +++ b/MessagingService/Startup.cs @@ -1,3 +1,4 @@ +using MessagingService.Endpoints; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -6,7 +7,6 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; -using MessagingService.Endpoints; namespace MessagingService { @@ -26,6 +26,7 @@ namespace MessagingService using Shared.General; using Shared.Logger; using Shared.Middleware; + using Shared.Serialisation; using SMSMessage.DomainEvents; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -56,8 +57,12 @@ public void ConfigureContainer(ServiceRegistry services) services.IncludeRegistry(); services.IncludeRegistry(); services.IncludeRegistry(); + services.IncludeRegistry(); Startup.Container = new Container(services); + + var serialiser = Container.GetRequiredService(); + StringSerialiser.Initialise(serialiser); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.