diff --git a/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/NotifierJsonContext.cs b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/NotifierJsonContext.cs new file mode 100644 index 00000000..e2684855 --- /dev/null +++ b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/NotifierJsonContext.cs @@ -0,0 +1,7 @@ +using System.Text.Json.Serialization; + +namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier; + +[JsonSerializable(typeof(RecipeDownload))] +[JsonSerializable(typeof(RecipeDownloadResult))] +internal partial class NotifierJsonContext : JsonSerializerContext; diff --git a/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownload.cs b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownload.cs new file mode 100644 index 00000000..7034ec6f --- /dev/null +++ b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownload.cs @@ -0,0 +1,11 @@ +namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier; + +internal sealed class RecipeDownload +{ + public string? MachineCode { get; set; } + public string? DownloadPath { get; set; } + public string? WorkOrderNumber { get; set; } + public string? PartNumber { get; set; } + public string? JobStepNumber { get; set; } + public string? Username { get; set; } +} diff --git a/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownloadResult.cs b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownloadResult.cs new file mode 100644 index 00000000..5d4e0c42 --- /dev/null +++ b/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/RecipeDownloadResult.cs @@ -0,0 +1,7 @@ +namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier; + +internal sealed class RecipeDownloadResult +{ + public bool Result { get; set; } + public string? ResultText { get; set; } +} diff --git a/tests/ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests/JsonContractTests.cs b/tests/ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests/JsonContractTests.cs new file mode 100644 index 00000000..c6074f04 --- /dev/null +++ b/tests/ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests/JsonContractTests.cs @@ -0,0 +1,27 @@ +using System.Text.Json; +using ZB.MOM.WW.ScadaBridge.DelmiaNotifier; + +namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier.Tests; + +public class JsonContractTests +{ + [Fact] + public void RecipeDownload_serializes_pascalcase() + { + var json = JsonSerializer.Serialize( + new RecipeDownload { MachineCode = "Z28061", DownloadPath = @"C:\r.nc", + WorkOrderNumber = "W1", PartNumber = "P1", JobStepNumber = "0100", Username = "op" }, + NotifierJsonContext.Default.RecipeDownload); + Assert.Contains("\"MachineCode\":\"Z28061\"", json); + Assert.Contains("\"DownloadPath\"", json); + } + + [Fact] + public void RecipeDownloadResult_deserializes_pascalcase() + { + var r = JsonSerializer.Deserialize("{\"Result\":true,\"ResultText\":\"ok\"}", + NotifierJsonContext.Default.RecipeDownloadResult); + Assert.True(r!.Result); + Assert.Equal("ok", r.ResultText); + } +}