Родитель
efffa70755
Коммит
bd3aecda52
|
@ -1,3 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.CorrelationVector;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CorrelationVector.UnitTests
|
||||
|
@ -6,8 +10,106 @@ namespace Microsoft.CorrelationVector.UnitTests
|
|||
public class CorrelationVectorTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestMethod1()
|
||||
public void SimpleCreateCorrelationVectorTest()
|
||||
{
|
||||
var correlationVector = new CorrelationVector();
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(2, splitVector.Length, "Correlation Vector should be created with two components separated by a '.'");
|
||||
Assert.AreEqual(16, splitVector[0].Length, "Correlation Vector base should be 16 character long");
|
||||
Assert.AreEqual("0", splitVector[1], "Correlation Vector extension should start with zero");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateV1CorrelationVectorTest()
|
||||
{
|
||||
var correlationVector = new CorrelationVector(CorrelationVectorVersion.V1);
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(2, splitVector.Length, "Correlation Vector should be created with two components separated by a '.'");
|
||||
Assert.AreEqual(16, splitVector[0].Length, "Correlation Vector base should be 16 character long");
|
||||
Assert.AreEqual("0", splitVector[1], "Correlation Vector extension should start with zero");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateV2CorrelationVectorTest()
|
||||
{
|
||||
var correlationVector = new CorrelationVector(CorrelationVectorVersion.V2);
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(2, splitVector.Length, "Correlation Vector should be created with two components separated by a '.'");
|
||||
Assert.AreEqual(22, splitVector[0].Length, "Correlation Vector base should be 22 character long");
|
||||
Assert.AreEqual("0", splitVector[1], "Correlation Vector extension should start with zero");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateCorrelationVectorFromGuidTest()
|
||||
{
|
||||
var guid = System.Guid.NewGuid();
|
||||
var correlationVector = new CorrelationVector(guid);
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(2, splitVector.Length, "Correlation Vector should be created with two components separated by a '.'");
|
||||
Assert.AreEqual(22, splitVector[0].Length, "Correlation Vector base should be 22 character long");
|
||||
Assert.AreEqual("0", splitVector[1], "Correlation Vector extension should start with zero");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ParseCorrelationVectorV1Test()
|
||||
{
|
||||
var correlationVector = CorrelationVector.Parse("ifCuqpnwiUimg7Pk.1");
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual("ifCuqpnwiUimg7Pk", splitVector[0], "Correlation Vector base was not parsed properly");
|
||||
Assert.AreEqual("1", splitVector[1], "Correlation Vector extension was not parsed properly");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ParseCorrelationVectorV2Test()
|
||||
{
|
||||
var correlationVector = CorrelationVector.Parse("Y58xO9ov0kmpPvkiuzMUVA.3.4.5");
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(4, splitVector.Length, "Correlation Vector was not parsed properly");
|
||||
Assert.AreEqual("Y58xO9ov0kmpPvkiuzMUVA", splitVector[0], "Correlation Vector base was not parsed properly");
|
||||
Assert.AreEqual("3", splitVector[1], "Correlation Vector extension was not parsed properly");
|
||||
Assert.AreEqual("4", splitVector[2], "Correlation Vector extension was not parsed properly");
|
||||
Assert.AreEqual("5", splitVector[3], "Correlation Vector extension was not parsed properly");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SimpleIncrementCorrelationVectorTest()
|
||||
{
|
||||
var correlationVector = new CorrelationVector();
|
||||
correlationVector.Increment();
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
Assert.AreEqual("1", splitVector[1], "Correlation Vector extension should have been incremented by one");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SimpleExtendCorrelationVectorTest()
|
||||
{
|
||||
var correlationVector = new CorrelationVector();
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
var vectorBase = splitVector[0];
|
||||
var extension = splitVector[1];
|
||||
|
||||
correlationVector = CorrelationVector.Extend(correlationVector.Value);
|
||||
splitVector = correlationVector.Value.Split('.');
|
||||
|
||||
Assert.AreEqual(3, splitVector.Length, "Correlation Vector should contain 3 components separated by a '.' after extension");
|
||||
Assert.AreEqual(vectorBase, splitVector[0], "Correlation Vector base should contain the same base after extension");
|
||||
Assert.AreEqual(extension, splitVector[1], "Correlation Vector should preserve original ");
|
||||
Assert.AreEqual("0", splitVector[2], "Correlation Vector new extension should start with zero");
|
||||
}
|
||||
|
||||
public void ValidateCreationTest()
|
||||
{
|
||||
CorrelationVector.ValidateCorrelationVectorDuringCreation = true;
|
||||
var correlationVector = new CorrelationVector();
|
||||
correlationVector.Increment();
|
||||
var splitVector = correlationVector.Value.Split('.');
|
||||
Assert.AreEqual("1", splitVector[1], "Correlation Vector extension should have been incremented by one");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.CorrelationVector\Microsoft.CorrelationVector.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
@ -37,8 +38,7 @@ namespace Microsoft.CorrelationVector
|
|||
|
||||
/// <summary>
|
||||
/// Creates a new correlation vector by extending an existing value. This should be
|
||||
/// done at the entry point of an operation. The result should be set to
|
||||
/// <see cref="TransactionContext.Vector"/> on <see cref="Sll.Context"/>.
|
||||
/// done at the entry point of an operation.
|
||||
/// </summary>
|
||||
/// <param name="correlationVector">
|
||||
/// Taken from the message header indicated by <see cref="HeaderName"/>.
|
||||
|
@ -59,8 +59,7 @@ namespace Microsoft.CorrelationVector
|
|||
|
||||
/// <summary>
|
||||
/// Creates a new correlation vector by applying the Spin operator to an existing value.
|
||||
/// This should be done at the entry point of an operation. The result should be set to
|
||||
/// <see cref="TransactionContext.Vector"/> on <see cref="Sll.Context"/>.
|
||||
/// This should be done at the entry point of an operation.
|
||||
/// </summary>
|
||||
/// <param name="correlationVector">
|
||||
/// Taken from the message header indicated by <see cref="HeaderName"/>.
|
||||
|
@ -80,8 +79,7 @@ namespace Microsoft.CorrelationVector
|
|||
|
||||
/// <summary>
|
||||
/// Creates a new correlation vector by applying the Spin operator to an existing value.
|
||||
/// This should be done at the entry point of an operation. The result should be set to
|
||||
/// <see cref="TransactionContext.Vector"/> on <see cref="Sll.Context"/>.
|
||||
/// This should be done at the entry point of an operation.
|
||||
/// </summary>
|
||||
/// <param name="correlationVector">
|
||||
/// Taken from the message header indicated by <see cref="HeaderName"/>.
|
||||
|
@ -149,8 +147,7 @@ namespace Microsoft.CorrelationVector
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CorrelationVector"/> class. This
|
||||
/// should only be called when no correlation vector was found in the message
|
||||
/// header. The result should be set to <see cref="TransactionContext.Vector"/> on
|
||||
/// <see cref="Sll.Context"/>.
|
||||
/// header.
|
||||
/// </summary>
|
||||
public CorrelationVector()
|
||||
: this(CorrelationVectorVersion.V1)
|
||||
|
@ -160,8 +157,7 @@ namespace Microsoft.CorrelationVector
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CorrelationVector"/> class of the
|
||||
/// given implemenation version. This should only be called when no correlation
|
||||
/// vector was found in the message header. The result should be set to
|
||||
/// <see cref="TransactionContext.Vector"/> on <see cref="Sll.Context"/>.
|
||||
/// vector was found in the message header.
|
||||
/// </summary>
|
||||
/// <param name="version">The correlation vector implemenation version.</param>
|
||||
public CorrelationVector(CorrelationVectorVersion version)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace Microsoft.CorrelationVector
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче