Skip to content

Commit df81264

Browse files
authored
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
1 parent e9ae3cf commit df81264

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,17 @@ public async Task Updating_Single_Variant_Name_Does_Not_Change_Update_Dates_Of_O
587587

588588
var createResult = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
589589
Assert.IsTrue(createResult.Success);
590+
Assert.NotNull(createResult.Result.Content);
590591

591-
var firstUpdateDateEn = createResult.Result.Content!.GetUpdateDate("en-US")!;
592-
var firstUpdateDateDa = createResult.Result.Content!.GetUpdateDate("da-DK")!;
592+
// Retrieve the actual stored content to ensure the database truncation of times isn't interfering with the test
593+
var createdContent = await ContentEditingService.GetAsync(createResult.Result.Content.Key);
594+
Assert.NotNull(createdContent);
595+
var firstUpdateDateEn = createdContent.GetUpdateDate("en-US");
596+
Assert.IsNotNull(firstUpdateDateEn);
597+
var firstUpdateDateDa = createdContent.GetUpdateDate("da-DK");
598+
Assert.IsNotNull(firstUpdateDateDa);
593599

594-
Thread.Sleep(100);
600+
await Task.Delay(100);
595601

596602
var updateModel = new ContentUpdateModel
597603
{
@@ -610,26 +616,30 @@ public async Task Updating_Single_Variant_Name_Does_Not_Change_Update_Dates_Of_O
610616

611617
// re-get and re-test
612618
VerifyUpdate(await ContentEditingService.GetAsync(updateResult.Result.Content!.Key));
619+
return;
613620

614621
void VerifyUpdate(IContent? updatedContent)
615622
{
616623
Assert.IsNotNull(updatedContent);
617-
Assert.AreEqual(firstUpdateDateDa?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), updatedContent.GetUpdateDate("da-DK")?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond));
618-
619-
var lastUpdateDateEn = updatedContent.GetUpdateDate("en-US")
620-
?? throw new InvalidOperationException("Expected a publish date for EN");
621-
Assert.Greater(lastUpdateDateEn.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), firstUpdateDateEn?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond));
624+
Assert.AreEqual(firstUpdateDateDa, updatedContent.GetUpdateDate("da-DK"));
625+
Assert.Less(firstUpdateDateEn, updatedContent.GetUpdateDate("en-US"));
622626
}
623627
}
624628

625629
[Test]
626630
public async Task Updating_Single_Variant_Property_Does_Not_Change_Update_Dates_Of_Other_Variants()
627631
{
628632
var content = await CreateCultureVariantContent();
629-
var firstUpdateDateEn = content.GetUpdateDate("en-US")
630-
?? throw new InvalidOperationException("Expected an update date for EN");
631-
var firstUpdateDateDa = content.GetUpdateDate("da-DK")
632-
?? throw new InvalidOperationException("Expected an update date for DA");
633+
634+
// Retrieve the actual stored content to ensure the database truncation of times isn't interfering with the test
635+
var createdContent = await ContentEditingService.GetAsync(content.Key);
636+
Assert.NotNull(createdContent);
637+
var firstUpdateDateEn = createdContent.GetUpdateDate("en-US");
638+
Assert.IsNotNull(firstUpdateDateEn);
639+
var firstUpdateDateDa = createdContent.GetUpdateDate("da-DK");
640+
Assert.IsNotNull(firstUpdateDateDa);
641+
642+
await Task.Delay(100);
633643

634644
var updateModel = new ContentUpdateModel
635645
{
@@ -667,15 +677,13 @@ public async Task Updating_Single_Variant_Property_Does_Not_Change_Update_Dates_
667677

668678
// re-get and re-test
669679
VerifyUpdate(await ContentEditingService.GetAsync(content.Key));
680+
return;
670681

671682
void VerifyUpdate(IContent? updatedContent)
672683
{
673684
Assert.IsNotNull(updatedContent);
674-
Assert.AreEqual(firstUpdateDateEn.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), updatedContent.GetUpdateDate("en-US")?.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond));
675-
676-
var lastUpdateDateDa = updatedContent.GetUpdateDate("da-DK")
677-
?? throw new InvalidOperationException("Expected an update date for DA");
678-
Assert.Greater(lastUpdateDateDa.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond), firstUpdateDateDa.TruncateTo(DateTimeExtensions.DateTruncate.Millisecond));
685+
Assert.AreEqual(firstUpdateDateEn, updatedContent.GetUpdateDate("en-US"));
686+
Assert.Less(firstUpdateDateDa, updatedContent.GetUpdateDate("da-DK"));
679687
}
680688
}
681689
}

0 commit comments

Comments
 (0)