From df81264794fda73680fe8d16c556dd065d1012db Mon Sep 17 00:00:00 2001 From: Laura Neto <12862535+lauraneto@users.noreply.github.com> Date: Tue, 7 Oct 2025 16:55:31 +0200 Subject: [PATCH] Integration tests: Fix failing SQLServer integration tests (#20406) Fix failing SQLServer integration tests Adjusted the tests so that the created content is retrieved again after creation, instead of using the returned IContent. This is needed because SQLServer, when using datetime, rounds to the closest .000, .003, or .007, which would cause the comparisons to fail. We should consider moving away from datetime to datetime2, as the former should be avoided according to Microsoft. https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-ver17 --- .../ContentEditingServiceTests.Update.cs | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs index 589c4a3516..c5ca28d111 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs @@ -587,11 +587,17 @@ public partial class ContentEditingServiceTests var createResult = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(createResult.Success); + Assert.NotNull(createResult.Result.Content); - var firstUpdateDateEn = createResult.Result.Content!.GetUpdateDate("en-US")!; - var firstUpdateDateDa = createResult.Result.Content!.GetUpdateDate("da-DK")!; + // Retrieve the actual stored content to ensure the database truncation of times isn't interfering with the test + var createdContent = await ContentEditingService.GetAsync(createResult.Result.Content.Key); + Assert.NotNull(createdContent); + var firstUpdateDateEn = createdContent.GetUpdateDate("en-US"); + Assert.IsNotNull(firstUpdateDateEn); + var firstUpdateDateDa = createdContent.GetUpdateDate("da-DK"); + Assert.IsNotNull(firstUpdateDateDa); - Thread.Sleep(100); + await Task.Delay(100); var updateModel = new ContentUpdateModel { @@ -610,15 +616,13 @@ public partial class ContentEditingServiceTests // re-get and re-test VerifyUpdate(await ContentEditingService.GetAsync(updateResult.Result.Content!.Key)); + return; void VerifyUpdate(IContent? updatedContent) { Assert.IsNotNull(updatedContent); - Assert.AreEqual(firstUpdateDateDa?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), updatedContent.GetUpdateDate("da-DK")?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond)); - - var lastUpdateDateEn = updatedContent.GetUpdateDate("en-US") - ?? throw new InvalidOperationException("Expected a publish date for EN"); - Assert.Greater(lastUpdateDateEn.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), firstUpdateDateEn?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond)); + Assert.AreEqual(firstUpdateDateDa, updatedContent.GetUpdateDate("da-DK")); + Assert.Less(firstUpdateDateEn, updatedContent.GetUpdateDate("en-US")); } } @@ -626,10 +630,16 @@ public partial class ContentEditingServiceTests public async Task Updating_Single_Variant_Property_Does_Not_Change_Update_Dates_Of_Other_Variants() { var content = await CreateCultureVariantContent(); - var firstUpdateDateEn = content.GetUpdateDate("en-US") - ?? throw new InvalidOperationException("Expected an update date for EN"); - var firstUpdateDateDa = content.GetUpdateDate("da-DK") - ?? throw new InvalidOperationException("Expected an update date for DA"); + + // Retrieve the actual stored content to ensure the database truncation of times isn't interfering with the test + var createdContent = await ContentEditingService.GetAsync(content.Key); + Assert.NotNull(createdContent); + var firstUpdateDateEn = createdContent.GetUpdateDate("en-US"); + Assert.IsNotNull(firstUpdateDateEn); + var firstUpdateDateDa = createdContent.GetUpdateDate("da-DK"); + Assert.IsNotNull(firstUpdateDateDa); + + await Task.Delay(100); var updateModel = new ContentUpdateModel { @@ -667,15 +677,13 @@ public partial class ContentEditingServiceTests // re-get and re-test VerifyUpdate(await ContentEditingService.GetAsync(content.Key)); + return; void VerifyUpdate(IContent? updatedContent) { Assert.IsNotNull(updatedContent); - Assert.AreEqual(firstUpdateDateEn.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), updatedContent.GetUpdateDate("en-US")?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond)); - - var lastUpdateDateDa = updatedContent.GetUpdateDate("da-DK") - ?? throw new InvalidOperationException("Expected an update date for DA"); - Assert.Greater(lastUpdateDateDa.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), firstUpdateDateDa.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond)); + Assert.AreEqual(firstUpdateDateEn, updatedContent.GetUpdateDate("en-US")); + Assert.Less(firstUpdateDateDa, updatedContent.GetUpdateDate("da-DK")); } } }