|
| 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 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(null); |
| 18 | + |
| 19 | + Assert.Null(result); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void GetVersionFromHistory_ReturnsNull_WhenHistoryHasNoExecutionStartedEvent() |
| 24 | + { |
| 25 | + var historyEvents = new[] |
| 26 | + { |
| 27 | + new HistoryEvent { EventType = HistoryEventType.OrchestratorStarted }, |
| 28 | + new HistoryEvent { EventType = HistoryEventType.TaskScheduled } |
| 29 | + }; |
| 30 | + |
| 31 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 32 | + |
| 33 | + Assert.Null(result); |
| 34 | + } |
| 35 | + |
| 36 | + [Fact] |
| 37 | + public void GetVersionFromHistory_ReturnsVersion_WhenExecutionStartedEventExists() |
| 38 | + { |
| 39 | + var historyEvents = new[] |
| 40 | + { |
| 41 | + new HistoryEvent { EventType = HistoryEventType.OrchestratorStarted }, |
| 42 | + new HistoryEvent { EventType = HistoryEventType.ExecutionStarted, Version = "1.0" }, |
| 43 | + }; |
| 44 | + |
| 45 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 46 | + |
| 47 | + Assert.Equal("1.0", result); |
| 48 | + } |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void GetVersionFromHistory_ReturnsFirstExecutionStartedVersion_WhenMultipleExecutionStartedEventsExist() |
| 52 | + { |
| 53 | + var historyEvents = new[] |
| 54 | + { |
| 55 | + new HistoryEvent { EventType = HistoryEventType.ExecutionStarted, Version = "1.0" }, |
| 56 | + new HistoryEvent { EventType = HistoryEventType.ExecutionStarted, Version = "2.0" } |
| 57 | + }; |
| 58 | + |
| 59 | + string result = OrchestrationVersionExtractor.GetVersionFromHistory(historyEvents); |
| 60 | + |
| 61 | + Assert.Equal("1.0", result); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments