From bd3aecda520bf2887b963d2b3afaf6eab3def0a8 Mon Sep 17 00:00:00 2001 From: Leonardo Merida Mejia Date: Thu, 19 Apr 2018 16:09:32 -0700 Subject: [PATCH] Adding Unit Test Adding Unit Test --- .../CorrelationVectorTests.cs | 104 +++++++++++++++++- ...crosoft.CorrelationVector.UnitTests.csproj | 4 + .../CorrelationVector.cs | 18 ++- .../CorrelationVectorVersion.cs | 3 +- .../SpinParameters.cs | 3 +- 5 files changed, 118 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.CorrelationVector.UnitTests/CorrelationVectorTests.cs b/src/Microsoft.CorrelationVector.UnitTests/CorrelationVectorTests.cs index fac6f78..900cc70 100644 --- a/src/Microsoft.CorrelationVector.UnitTests/CorrelationVectorTests.cs +++ b/src/Microsoft.CorrelationVector.UnitTests/CorrelationVectorTests.cs @@ -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"); } } } diff --git a/src/Microsoft.CorrelationVector.UnitTests/Microsoft.CorrelationVector.UnitTests.csproj b/src/Microsoft.CorrelationVector.UnitTests/Microsoft.CorrelationVector.UnitTests.csproj index 5658157..75628a8 100644 --- a/src/Microsoft.CorrelationVector.UnitTests/Microsoft.CorrelationVector.UnitTests.csproj +++ b/src/Microsoft.CorrelationVector.UnitTests/Microsoft.CorrelationVector.UnitTests.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/src/Microsoft.CorrelationVector/CorrelationVector.cs b/src/Microsoft.CorrelationVector/CorrelationVector.cs index da6f667..28091e9 100644 --- a/src/Microsoft.CorrelationVector/CorrelationVector.cs +++ b/src/Microsoft.CorrelationVector/CorrelationVector.cs @@ -1,4 +1,5 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. using System; using System.Threading; @@ -37,8 +38,7 @@ namespace Microsoft.CorrelationVector /// /// 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 - /// on . + /// done at the entry point of an operation. /// /// /// Taken from the message header indicated by . @@ -59,8 +59,7 @@ namespace Microsoft.CorrelationVector /// /// 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 - /// on . + /// This should be done at the entry point of an operation. /// /// /// Taken from the message header indicated by . @@ -80,8 +79,7 @@ namespace Microsoft.CorrelationVector /// /// 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 - /// on . + /// This should be done at the entry point of an operation. /// /// /// Taken from the message header indicated by . @@ -149,8 +147,7 @@ namespace Microsoft.CorrelationVector /// /// Initializes a new instance of the class. This /// should only be called when no correlation vector was found in the message - /// header. The result should be set to on - /// . + /// header. /// public CorrelationVector() : this(CorrelationVectorVersion.V1) @@ -160,8 +157,7 @@ namespace Microsoft.CorrelationVector /// /// Initializes a new instance of the 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 - /// on . + /// vector was found in the message header. /// /// The correlation vector implemenation version. public CorrelationVector(CorrelationVectorVersion version) diff --git a/src/Microsoft.CorrelationVector/CorrelationVectorVersion.cs b/src/Microsoft.CorrelationVector/CorrelationVectorVersion.cs index 9f0b485..15f25dd 100644 --- a/src/Microsoft.CorrelationVector/CorrelationVectorVersion.cs +++ b/src/Microsoft.CorrelationVector/CorrelationVectorVersion.cs @@ -1,4 +1,5 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. namespace Microsoft.CorrelationVector { diff --git a/src/Microsoft.CorrelationVector/SpinParameters.cs b/src/Microsoft.CorrelationVector/SpinParameters.cs index f282c6c..34962ef 100644 --- a/src/Microsoft.CorrelationVector/SpinParameters.cs +++ b/src/Microsoft.CorrelationVector/SpinParameters.cs @@ -1,4 +1,5 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. using System;