From 4866cabbf60b28ca29bafb499e99a06ffeadc3fd Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 22 Sep 2023 14:37:54 +0200 Subject: [PATCH 1/4] return object on post of order --- .../EmailNotificationOrdersController.cs | 2 +- src/Altinn.Notifications/Models/OrderIdExt.cs | 27 +++++++++++++++++++ .../EmailNotificationOrdersControllerTests.cs | 6 +++-- .../PostTests.cs | 15 ++++++----- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/Altinn.Notifications/Models/OrderIdExt.cs diff --git a/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs b/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs index 61086d0c..d8f705ef 100644 --- a/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs +++ b/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs @@ -66,6 +66,6 @@ public async Task> Post(EmailNotificationOrde } string selfLink = registeredOrder!.GetSelfLink(); - return Accepted(selfLink, registeredOrder!.Id.ToString()); + return Accepted(selfLink, new OrderIdExt(registeredOrder!.Id)); } } diff --git a/src/Altinn.Notifications/Models/OrderIdExt.cs b/src/Altinn.Notifications/Models/OrderIdExt.cs new file mode 100644 index 00000000..f32339f9 --- /dev/null +++ b/src/Altinn.Notifications/Models/OrderIdExt.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; + +namespace Altinn.Notifications.Models +{ + /// + /// A class representing a container for an order id. + /// + /// + /// External representaion to be used in the API. + /// + public class OrderIdExt + { + /// + /// The order id + /// + [JsonPropertyName("orderId")] + public Guid OrderId { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public OrderIdExt(Guid orderId) + { + OrderId = orderId; + } + } +} diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs index 157de9ac..4097a6f2 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs @@ -195,12 +195,14 @@ public async Task Post_ServiceReturnsOrder_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string actualOrderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + Assert.NotNull(orderIdObjectExt); Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); - Assert.Equal($"{_order.Id}", actualOrderId); + Assert.Equal(_order.Id, orderIdObjectExt.OrderId); serviceMock.VerifyAll(); } diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs index 55cff340..9eb836e7 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs @@ -1,6 +1,7 @@ using System.Net; using System.Net.Http.Headers; using System.Text; +using System.Text.Json; using Altinn.Notifications.Controllers; using Altinn.Notifications.Core.Enums; @@ -75,12 +76,13 @@ public async Task Post_ServiceReturnsOrderWIthId_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string orderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - Guid.Parse(orderId); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderId, response.Headers?.Location?.ToString()); + Assert.NotNull(orderIdObjectExt); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderIdObjectExt.OrderId, response.Headers?.Location?.ToString()); } [Fact] @@ -97,12 +99,13 @@ public async Task Post_OrderWithoutSendersRef_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string orderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - Guid.Parse(orderId); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderId, response.Headers?.Location?.ToString()); + Assert.NotNull(orderIdObjectExt); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderIdObjectExt.OrderId, response.Headers?.Location?.ToString()); } public async void Dispose() From d4dd6d11ab235172adf1abe8857fcecf94b0e2f2 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 22 Sep 2023 14:40:02 +0200 Subject: [PATCH 2/4] changed order of assertions --- .../EmailNotificationOrdersControllerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs index 4097a6f2..06419348 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs @@ -201,8 +201,8 @@ public async Task Post_ServiceReturnsOrder_Accepted() // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); Assert.NotNull(orderIdObjectExt); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); Assert.Equal(_order.Id, orderIdObjectExt.OrderId); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); serviceMock.VerifyAll(); } From 0205654d737aa70eaa4457b06ba13f1e62333581 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 22 Sep 2023 15:05:38 +0200 Subject: [PATCH 3/4] uodated last test --- .../EmailNotificationOrdersControllerTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs index cd78e612..a66f3919 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs @@ -256,12 +256,13 @@ public async Task Post_OrderWithoutFromAddress_StringEmptyUsedAsServiceInput_Acc // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string actualOrderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); - Assert.Equal($"{_order.Id}", actualOrderId); + Assert.Equal(_order.Id, orderIdObjectExt.OrderId); serviceMock.VerifyAll(); } From 4279b453c43af4ca0925284875cc6b6ef468f036 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 22 Sep 2023 15:14:31 +0200 Subject: [PATCH 4/4] changed order of assertions --- .../EmailNotificationOrdersControllerTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs index a66f3919..d60958ac 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs @@ -261,9 +261,11 @@ public async Task Post_OrderWithoutFromAddress_StringEmptyUsedAsServiceInput_Acc // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); + Assert.NotNull(orderIdObjectExt); Assert.Equal(_order.Id, orderIdObjectExt.OrderId); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); + serviceMock.VerifyAll(); }