Skip to content

Commit 95a0f3e

Browse files
committed
Refactor test
1 parent 9d39e1f commit 95a0f3e

1 file changed

Lines changed: 64 additions & 51 deletions

File tree

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CFP/AllVersionsAndDeletes/BuilderWithCustomSerializerTests.cs

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.CFP.AllVersionsAndDeletes
2424
[TestCategory("ChangeFeedProcessor")]
2525
public class BuilderWithCustomSerializerTests
2626
{
27-
public TestContext TestContext { get; set; }
28-
2927
[TestMethod]
3028
[Owner("philipthomas")]
3129
[Description("Validating to deserization of ChangeFeedItem with a Delete payload with TimeToLiveExpired set to true.")]
@@ -559,54 +557,54 @@ public async Task WhenADocumentIsCreatedWithTtlSetThenTheDocumentIsDeletedTestsA
559557
ChangeFeedProcessor processor = monitoredContainer
560558
.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes(processorName: "processor", onChangesDelegate: (ChangeFeedProcessorContext context, IReadOnlyCollection<ChangeFeedItem<ToDoActivity>> docs, CancellationToken token) =>
561559
{
562-
// NOTE(philipthomas-MSFT): Please allow these Logger.LogLine because TTL on items will purge at random times so I am using this to test when ran locally using emulator.
560+
// NOTE(philipthomas-MSFT): Please allow these Logger.LogLine because TTL on items will purge at random times so I am using this to test when ran locally using emulator.
563561

564-
Logger.LogLine($"@ {DateTime.Now}, {nameof(stopwatch)} -> CFP AVAD took '{stopwatch.ElapsedMilliseconds}' to read document CRUD in feed.");
562+
Logger.LogLine($"@ {DateTime.Now}, {nameof(stopwatch)} -> CFP AVAD took '{stopwatch.ElapsedMilliseconds}' to read document CRUD in feed.");
565563

566-
foreach (ChangeFeedItem<ToDoActivity> change in docs)
564+
foreach (ChangeFeedItem<ToDoActivity> change in docs)
565+
{
566+
if (change.Metadata.OperationType == ChangeFeedOperationType.Create)
567567
{
568-
if (change.Metadata.OperationType == ChangeFeedOperationType.Create)
569-
{
570-
// current
571-
Assert.AreEqual(expected: "1", actual: change.Current.id.ToString());
572-
Assert.AreEqual(expected: "1", actual: change.Current.pk.ToString());
573-
Assert.AreEqual(expected: "Testing TTL on CFP.", actual: change.Current.description.ToString());
574-
Assert.AreEqual(expected: ttlInSeconds, actual: change.Current.ttl);
575-
576-
// metadata
577-
Assert.IsTrue(DateTime.TryParse(s: change.Metadata.ConflictResolutionTimestamp.ToString(), out _), message: "Invalid csrt must be a datetime value.");
578-
Assert.IsTrue(change.Metadata.Lsn > 0, message: "Invalid lsn must be a long value.");
579-
Assert.IsFalse(change.Metadata.IsTimeToLiveExpired);
580-
Assert.IsNull(change.Metadata.Id);
581-
Assert.IsNull(change.Metadata.PartitionKey);
582-
583-
// previous
584-
Assert.IsNull(change.Previous);
585-
}
586-
else if (change.Metadata.OperationType == ChangeFeedOperationType.Delete)
587-
{
588-
// current
589-
Assert.IsNull(change.Current.id);
590-
591-
// metadata
592-
Assert.IsTrue(DateTime.TryParse(s: change.Metadata.ConflictResolutionTimestamp.ToString(), out _), message: "Invalid csrt must be a datetime value.");
593-
Assert.IsTrue(change.Metadata.Lsn > 0, message: "Invalid lsn must be a long value.");
594-
Assert.IsTrue(change.Metadata.IsTimeToLiveExpired);
595-
Assert.AreEqual(expected: "1", actual: change.Metadata.Id.ToString());
596-
Assert.AreEqual(expected: "1", actual: change.Metadata.PartitionKey.Values.FirstOrDefault());
597-
598-
// previous
599-
Assert.IsNull(change.Previous);
600-
601-
// stop after reading delete since it is the last document in feed.
602-
stopwatch.Stop();
603-
allDocsProcessed.Set();
604-
}
605-
else
606-
{
607-
Assert.Fail("Invalid operation.");
608-
}
568+
// current
569+
Assert.AreEqual(expected: "1", actual: change.Current.id.ToString());
570+
Assert.AreEqual(expected: "1", actual: change.Current.pk.ToString());
571+
Assert.AreEqual(expected: "Testing TTL on CFP.", actual: change.Current.description.ToString());
572+
Assert.AreEqual(expected: ttlInSeconds, actual: change.Current.ttl);
573+
574+
// metadata
575+
Assert.IsTrue(DateTime.TryParse(s: change.Metadata.ConflictResolutionTimestamp.ToString(), out _), message: "Invalid csrt must be a datetime value.");
576+
Assert.IsTrue(change.Metadata.Lsn > 0, message: "Invalid lsn must be a long value.");
577+
Assert.IsFalse(change.Metadata.IsTimeToLiveExpired);
578+
Assert.IsNull(change.Metadata.Id);
579+
Assert.IsNull(change.Metadata.PartitionKey);
580+
581+
// previous
582+
Assert.IsNull(change.Previous);
609583
}
584+
else if (change.Metadata.OperationType == ChangeFeedOperationType.Delete)
585+
{
586+
// current
587+
Assert.IsNull(change.Current.id);
588+
589+
// metadata
590+
Assert.IsTrue(DateTime.TryParse(s: change.Metadata.ConflictResolutionTimestamp.ToString(), out _), message: "Invalid csrt must be a datetime value.");
591+
Assert.IsTrue(change.Metadata.Lsn > 0, message: "Invalid lsn must be a long value.");
592+
Assert.IsTrue(change.Metadata.IsTimeToLiveExpired);
593+
Assert.AreEqual(expected: "1", actual: change.Metadata.Id.ToString());
594+
Assert.AreEqual(expected: "1", actual: change.Metadata.PartitionKey.Values.FirstOrDefault());
595+
596+
// previous
597+
Assert.IsNull(change.Previous);
598+
599+
// stop after reading delete since it is the last document in feed.
600+
stopwatch.Stop();
601+
allDocsProcessed.Set();
602+
}
603+
else
604+
{
605+
Assert.Fail("Invalid operation.");
606+
}
607+
}
610608

611609
return Task.CompletedTask;
612610
})
@@ -659,18 +657,33 @@ public async Task WhenADocumentIsCreatedWithTtlSetThenTheDocumentIsDeletedTestsA
659657
}
660658

661659
[TestMethod]
662-
[TestCategory("MultiMaster")]
663660
[TestCategory("ChangeFeed")]
664661
[Owner("philipthomas-MSFT")]
665662
[Description("Scenario: When a document is created, then updated, and finally deleted, there should be 3 changes that will appear for that " +
666-
"document when using ChangeFeedProcessor with AllVersionsAndDeletes set as the ChangeFeedMode.")]
663+
"document when using ChangeFeedProcessor with AllVersionsAndDeletes set as the ChangeFeedMode. This test runs against the Cosmos DB Emulator" +
664+
" which has enablePreviousImageForDeleteInFFCF set to true.")]
667665
[DataRow(true)]
668666
[DataRow(false)]
669-
public async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync(bool propertyNameCaseInsensitive)
667+
public async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsyncEmulator(bool propertyNameCaseInsensitive)
670668
{
671-
bool isMultiMaster = this.TestContext.Properties.ContainsKey("TestCategory") &&
672-
this.TestContext.Properties["TestCategory"].ToString().Contains("MultiMaster");
669+
await this.WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync(propertyNameCaseInsensitive);
670+
}
671+
672+
[TestMethod]
673+
[TestCategory("MultiMaster")]
674+
[Owner("philipthomas-MSFT")]
675+
[Description("Scenario: When a document is created, then updated, and finally deleted, there should be 3 changes that will appear for that " +
676+
"document when using ChangeFeedProcessor with AllVersionsAndDeletes set as the ChangeFeedMode. This test runs against a live multi-region" +
677+
" Cosmos DB account which has does not have enablePreviousImageForDeleteInFFCF set.")]
678+
[DataRow(true)]
679+
[DataRow(false)]
680+
public async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsyncLiveAccount(bool propertyNameCaseInsensitive)
681+
{
682+
await this.WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync(propertyNameCaseInsensitive, true);
683+
}
673684

685+
private async Task WhenADocumentIsCreatedThenUpdatedThenDeletedTestsAsync(bool propertyNameCaseInsensitive, bool isMultiMaster = false)
686+
{
674687
string accountEndpoint = isMultiMaster ?
675688
TestCommon.GetMultiRegionConnectionString() :
676689
null;

0 commit comments

Comments
 (0)