|
| 1 | +// |
| 2 | +// Copyright (c) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 4 | +// |
| 5 | + |
| 6 | +namespace Microsoft.Azure.Functions.PowerShellWorker.Test.Durable |
| 7 | +{ |
| 8 | + using System; |
| 9 | + using Microsoft.Azure.Functions.PowerShellWorker.Durable; |
| 10 | + using Xunit; |
| 11 | + |
| 12 | + public class OrchestrationVersionExtractorTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void GetVersionFromHistory_ReturnsNull_WhenHistoryIsNull() |
| 16 | + { |
| 17 | + // Act |
| 18 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(null); |
| 19 | + |
| 20 | + // Assert |
| 21 | + Assert.Null(result); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void GetVersionFromHistory_ReturnsNull_WhenHistoryHasNoExecutionStartedEvent() |
| 26 | + { |
| 27 | + // Arrange |
| 28 | + var historyEvents = new[] |
| 29 | + { |
| 30 | + new HistoryEvent { EventType = HistoryEventType.TaskScheduled, EventId = 1 }, |
| 31 | + new HistoryEvent { EventType = HistoryEventType.TaskCompleted, EventId = 2, TaskScheduledId = 1 } |
| 32 | + }; |
| 33 | + |
| 34 | + // Act |
| 35 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 36 | + |
| 37 | + // Assert |
| 38 | + Assert.Null(result); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void GetVersionFromHistory_ReturnsVersion_WhenExecutionStartedEventExists() |
| 43 | + { |
| 44 | + // Arrange |
| 45 | + const string expectedVersion = "1.0.0"; |
| 46 | + var historyEvents = new[] |
| 47 | + { |
| 48 | + new HistoryEvent { |
| 49 | + EventType = HistoryEventType.ExecutionStarted, |
| 50 | + EventId = 1, |
| 51 | + Version = expectedVersion |
| 52 | + }, |
| 53 | + new HistoryEvent { EventType = HistoryEventType.TaskScheduled, EventId = 2 } |
| 54 | + }; |
| 55 | + |
| 56 | + // Act |
| 57 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 58 | + |
| 59 | + // Assert |
| 60 | + Assert.Equal(expectedVersion, result); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void GetVersionFromHistory_ReturnsFirstExecutionStartedVersion_WhenMultipleExecutionStartedEventsExist() |
| 65 | + { |
| 66 | + // Arrange |
| 67 | + const string expectedVersion = "1.0.0"; |
| 68 | + const string secondVersion = "2.0.0"; |
| 69 | + |
| 70 | + var historyEvents = new[] |
| 71 | + { |
| 72 | + new HistoryEvent { |
| 73 | + EventType = HistoryEventType.ExecutionStarted, |
| 74 | + EventId = 1, |
| 75 | + Version = expectedVersion |
| 76 | + }, |
| 77 | + new HistoryEvent { EventType = HistoryEventType.TaskScheduled, EventId = 2 }, |
| 78 | + new HistoryEvent { |
| 79 | + EventType = HistoryEventType.ExecutionStarted, |
| 80 | + EventId = 3, |
| 81 | + Version = secondVersion |
| 82 | + } |
| 83 | + }; |
| 84 | + |
| 85 | + // Act |
| 86 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 87 | + |
| 88 | + // Assert |
| 89 | + Assert.Equal(expectedVersion, result); |
| 90 | + Assert.NotEqual(secondVersion, result); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments