Skip to content

Commit

Permalink
added unit tests for continuation token serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bchong95 committed Oct 19, 2020
1 parent 5d9b360 commit 829d884
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ await feedIterator.ReadNextAsync(this.cancellationToken))
/// </summary>
/// <returns></returns>
[TestMethod]
//[Timeout(30000)]
[Timeout(30000)]
public async Task ChangeFeedIteratorCore_PartitionKey_ReadAll()
{
int totalCount = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Tests.ChangeFeed
{
using System;
using Microsoft.Azure.Cosmos.ChangeFeed.Pagination;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public sealed class ChangeFeedStateCosmosElementSerializerTests
{
[TestMethod]
public void Now()
{
ChangeFeedState now = ChangeFeedState.Now();
CosmosElement cosmosElement = ChangeFeedStateCosmosElementSerializer.ToCosmosElement(now);
TryCatch<ChangeFeedState> monadicState = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(cosmosElement);
Assert.IsTrue(monadicState.Succeeded);
Assert.IsTrue(monadicState.Result is ChangeFeedStateNow);
}

[TestMethod]
public void Beginning()
{
ChangeFeedState beginning = ChangeFeedState.Beginning();
CosmosElement cosmosElement = ChangeFeedStateCosmosElementSerializer.ToCosmosElement(beginning);
TryCatch<ChangeFeedState> monadicState = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(cosmosElement);
Assert.IsTrue(monadicState.Succeeded);
Assert.IsTrue(monadicState.Result is ChangeFeedStateBeginning);
}

[TestMethod]
public void Time()
{
DateTime startTime = DateTime.MinValue.ToUniversalTime();
ChangeFeedState time = ChangeFeedState.Time(startTime);
CosmosElement cosmosElement = ChangeFeedStateCosmosElementSerializer.ToCosmosElement(time);
TryCatch<ChangeFeedState> monadicState = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(cosmosElement);
Assert.IsTrue(monadicState.Succeeded);
if (!(monadicState.Result is ChangeFeedStateTime stateTime))
{
Assert.Fail();
return;
}

Assert.AreEqual(stateTime.StartTime, startTime);
}

[TestMethod]
public void Continuation()
{
CosmosString continuation = CosmosString.Create("asdf");
ChangeFeedState time = ChangeFeedState.Continuation(continuation);
CosmosElement cosmosElement = ChangeFeedStateCosmosElementSerializer.ToCosmosElement(time);
TryCatch<ChangeFeedState> monadicState = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(cosmosElement);
Assert.IsTrue(monadicState.Succeeded);
if (!(monadicState.Result is ChangeFeedStateContinuation changeFeedContinuation))
{
Assert.Fail();
return;
}

Assert.AreEqual(changeFeedContinuation.ContinuationToken, continuation);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Tests.FeedRange
{
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public sealed class FeedRangeCosmosElementSerializerTests
{
[TestMethod]
public void LogicalPartitionKey()
{
Cosmos.PartitionKey somePartitionKey = new Cosmos.PartitionKey(42);
FeedRangeInternal feedRange = new FeedRangePartitionKey(somePartitionKey);
AssertRoundTrip(feedRange);
}

[TestMethod]
public void PhysicalPartitionKeyRangeId()
{
int physicalPkRangeId = 0;
FeedRangeInternal feedRange = new FeedRangePartitionKeyRange(physicalPkRangeId.ToString());
AssertRoundTrip(feedRange);
}

[TestMethod]
public void EffectivePartitionKeyRange()
{
Microsoft.Azure.Documents.Routing.Range<string> range = new Microsoft.Azure.Documents.Routing.Range<string>(
min: "A",
max: "B",
isMinInclusive: true,
isMaxInclusive: false);

FeedRangeInternal feedRange = new FeedRangeEpk(range);
AssertRoundTrip(feedRange);
}

private static void AssertRoundTrip(FeedRangeInternal feedRange)
{
CosmosElement cosmosElement = FeedRangeCosmosElementSerializer.ToCosmosElement(feedRange);
TryCatch<FeedRangeInternal> monad = FeedRangeCosmosElementSerializer.MonadicCreateFromCosmosElement(cosmosElement);
Assert.IsTrue(monad.Succeeded);
Assert.AreEqual(feedRange.ToJsonString(), monad.Result.ToJsonString());
}
}
}

0 comments on commit 829d884

Please sign in to comment.