From 56be267f088b620bb1b9d079d68be324dbe44186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=BCnberg=2C=20Bent?= Date: Fri, 29 Nov 2024 13:58:31 +0100 Subject: [PATCH] test: ensure an appointment can get reposted without changing values --- .../AppointmentControllerIntegrationTests.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/Dataport.Terminfinder.WebAPI.Tests/IntegrationTests/AppointmentControllerIntegrationTests.cs b/src/Dataport.Terminfinder.WebAPI.Tests/IntegrationTests/AppointmentControllerIntegrationTests.cs index 7defb59..d6db6ac 100644 --- a/src/Dataport.Terminfinder.WebAPI.Tests/IntegrationTests/AppointmentControllerIntegrationTests.cs +++ b/src/Dataport.Terminfinder.WebAPI.Tests/IntegrationTests/AppointmentControllerIntegrationTests.cs @@ -245,6 +245,89 @@ public async Task UpdateAppointment() Assert.IsNull(responseSuggestedDates[2].EndTime); } + [TestMethod] + public async Task RepostAppointment_SameObject_IsValid() + { + // Arrange + var appointment = CreateTestAppointment(_customerId, Guid.Empty); + HttpClient client = _testServer.CreateClient(); + + // Act + var content = new StringContent(JsonConvert.SerializeObject(appointment), Encoding.UTF8, + HttpConstants.TerminfinderMediaTypeJsonV1); + var response = await client.PostAsync($"appointment/{_customerId}", content); + + // Assert + Assert.IsNotNull(response); + response.EnsureSuccessStatusCode(); + + // Act + var responseText = await response.Content.ReadAsStringAsync(); + var appointmentResult = JsonConvert.DeserializeObject(responseText); + + // resend previous result + var contentRepost = new StringContent(JsonConvert.SerializeObject(appointmentResult), Encoding.UTF8, + HttpConstants.TerminfinderMediaTypeJsonV1); + var responseRepost = await client.PostAsync($"appointment/{_customerId}", contentRepost); + + // Assert + Assert.IsNotNull(responseRepost); + responseRepost.EnsureSuccessStatusCode(); + + var responseRepostText = await responseRepost.Content.ReadAsStringAsync(); + Assert.AreEqual(responseText, responseRepostText); + } + + [TestMethod] + public async Task RepostAppointment_DifferentObject_PersistentValuesUnchanged() + { + // Arrange + var appointment = CreateTestAppointment(_customerId, Guid.Empty); + HttpClient client = _testServer.CreateClient(); + + // Act + var contentString = JsonConvert.SerializeObject(appointment); + var content = new StringContent(contentString, Encoding.UTF8, HttpConstants.TerminfinderMediaTypeJsonV1); + var response = await client.PostAsync($"appointment/{_customerId}", content); + + // Assert + Assert.IsNotNull(response); + response.EnsureSuccessStatusCode(); + + // resend previous result + // Act + var responseText = await response.Content.ReadAsStringAsync(); + var appointmentResponse = JsonConvert.DeserializeObject(responseText); + var responseVerify1 = await client.GetAsync($"appointment/{_customerId}/{appointmentResponse.AppointmentId}"); + + appointmentResponse.CreatorName = "New Creator!"; + + var contentRepost = new StringContent(JsonConvert.SerializeObject(appointmentResponse), Encoding.UTF8, + HttpConstants.TerminfinderMediaTypeJsonV1); + var responseRepost = await client.PostAsync($"appointment/{_customerId}", contentRepost); + + // Assert + Assert.IsNotNull(responseRepost); + responseRepost.EnsureSuccessStatusCode(); + + var responseRepostText = await responseRepost.Content.ReadAsStringAsync(); + Assert.AreNotEqual(responseText, responseRepostText); + + // verify that values are unchanged from second post request + // Act + var responseVerify2 = await client.GetAsync($"appointment/{_customerId}/{appointmentResponse.AppointmentId}"); + var responseVerify1Text = await responseVerify1.Content.ReadAsStringAsync(); + var responseVerify2Text = await responseVerify2.Content.ReadAsStringAsync(); + + // Assert + Assert.IsNotNull(responseVerify1); + Assert.IsNotNull(responseVerify2); + responseVerify1.EnsureSuccessStatusCode(); + responseVerify2.EnsureSuccessStatusCode(); + + Assert.AreEqual(responseVerify1Text, responseVerify2Text); + } + [TestMethod] public async Task GetAppointment_AppointmentId_NotFound() {