-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some unit tests for TransactionalBatchOperationResult
- Loading branch information
josh
committed
Nov 25, 2019
1 parent
9342593
commit 00b1787
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchOperationResultTests.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,88 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
[TestClass] | ||
public class BatchOperationResultTests | ||
{ | ||
static readonly Mock<CosmosDiagnostics> MockCosmosDiagnostics = new Mock<CosmosDiagnostics>(MockBehavior.Strict); | ||
static TransactionalBatchOperationResult CreateTestResult() => new TransactionalBatchOperationResult(HttpStatusCode.Unused) | ||
{ | ||
SubStatusCode = Documents.SubStatusCodes.CanNotAcquireOfferOwnerLock, | ||
ETag = "TestETag", | ||
ResourceStream = new MemoryStream(), | ||
RequestCharge = 1.5, | ||
RetryAfter = TimeSpan.FromMilliseconds(1234), | ||
Diagnostics = MockCosmosDiagnostics.Object | ||
}; | ||
|
||
[TestMethod] | ||
public void StatusCodeIsSetThroughCtor() | ||
{ | ||
TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.Unused); | ||
|
||
Assert.AreEqual(HttpStatusCode.Unused, result.StatusCode); | ||
} | ||
|
||
[TestMethod] | ||
public void PropertiesAreSetThroughCopyCtor() | ||
{ | ||
TransactionalBatchOperationResult other = CreateTestResult(); | ||
TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(other); | ||
|
||
Assert.AreEqual(other.StatusCode, result.StatusCode); | ||
Assert.AreEqual(other.SubStatusCode, result.SubStatusCode); | ||
Assert.AreEqual(other.ETag, result.ETag); | ||
Assert.AreEqual(other.RequestCharge, result.RequestCharge); | ||
Assert.AreEqual(other.RetryAfter, result.RetryAfter); | ||
Assert.AreSame(other.ResourceStream, result.ResourceStream); | ||
} | ||
|
||
[TestMethod] | ||
public void PropertiesAreSetThroughGenericCtor() | ||
{ | ||
TransactionalBatchOperationResult other = CreateTestResult(); | ||
object testObject = new object(); | ||
TransactionalBatchOperationResult<object> result = new TransactionalBatchOperationResult<object>(other, testObject); | ||
|
||
Assert.AreEqual(other.StatusCode, result.StatusCode); | ||
Assert.AreEqual(other.SubStatusCode, result.SubStatusCode); | ||
Assert.AreEqual(other.ETag, result.ETag); | ||
Assert.AreEqual(other.RequestCharge, result.RequestCharge); | ||
Assert.AreEqual(other.RetryAfter, result.RetryAfter); | ||
Assert.AreSame(other.ResourceStream, result.ResourceStream); | ||
Assert.AreSame(testObject, result.Resource); | ||
} | ||
|
||
[TestMethod] | ||
public void ToResponseMessageHasPropertiesMapped() | ||
{ | ||
TransactionalBatchOperationResult result = CreateTestResult(); | ||
|
||
ResponseMessage response = result.ToResponseMessage(); | ||
|
||
Assert.AreEqual(result.StatusCode, response.StatusCode); | ||
Assert.AreEqual(result.SubStatusCode, response.Headers.SubStatusCode); | ||
Assert.AreEqual(result.ETag, response.Headers.ETag); | ||
Assert.AreEqual(result.RequestCharge, response.Headers.RequestCharge); | ||
Assert.AreEqual(result.RetryAfter, response.Headers.RetryAfter); | ||
Assert.AreSame(result.ResourceStream, response.Content); | ||
Assert.AreSame(result.Diagnostics, response.Diagnostics); | ||
} | ||
|
||
[TestMethod] | ||
public void IsSuccessStatusCodeTrueFor200to299() | ||
{ | ||
for (int x = 100; x < 999; ++x) | ||
{ | ||
TransactionalBatchOperationResult result = new TransactionalBatchOperationResult((HttpStatusCode)x); | ||
bool success = x >= 200 && x <= 299; | ||
Assert.AreEqual(success, result.IsSuccessStatusCode); | ||
} | ||
} | ||
} | ||
} |