-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for continuation token serialization
- Loading branch information
Showing
3 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ts/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedStateCosmosElementSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...mos/tests/Microsoft.Azure.Cosmos.Tests/FeedRange/FeedRangeCosmosElementSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |