Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions src/Abstractions/TaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public TaskOptions(TaskRetryOptions? retry = null, IDictionary<string, string>?
this.Tags = tags;
}

/// <summary>
/// Initializes a new instance of the <see cref="TaskOptions"/> class by copying from another instance.
/// </summary>
/// <param name="options">The task options to copy from.</param>
public TaskOptions(TaskOptions options)
{
Check.NotNull(options);
this.Retry = options.Retry;
this.Tags = options.Tags;
}

/// <summary>
/// Gets the task retry options.
/// </summary>
Expand Down Expand Up @@ -96,12 +107,29 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
: base(options)
{
this.InstanceId = instanceId;
if (instanceId is null && options is SubOrchestrationOptions derived)
if (options is SubOrchestrationOptions derived)
{
this.InstanceId = derived.InstanceId;
if (instanceId is null)
{
this.InstanceId = derived.InstanceId;
}

this.Version = derived.Version;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class by copying from another instance.
/// </summary>
/// <param name="options">The sub-orchestration options to copy from.</param>
public SubOrchestrationOptions(SubOrchestrationOptions options)
: base(options)
{
Check.NotNull(options);
this.InstanceId = options.InstanceId;
this.Version = options.Version;
}

/// <summary>
/// Gets the orchestration instance ID.
/// </summary>
Expand All @@ -116,15 +144,51 @@ public SubOrchestrationOptions(TaskOptions options, string? instanceId = null)
/// <summary>
/// Options for submitting new orchestrations via the client.
/// </summary>
/// <param name="InstanceId">
/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used.
/// </param>
/// <param name="StartAt">
/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past
/// is specified, the orchestration instance will be scheduled immediately.
/// </param>
public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null)
public record StartOrchestrationOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="StartOrchestrationOptions"/> class.
/// </summary>
/// <param name="InstanceId">
/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used.
/// </param>
/// <param name="StartAt">
/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past
/// is specified, the orchestration instance will be scheduled immediately.
/// </param>
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter - using PascalCase to maintain backward compatibility with positional record syntax
public StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null)
#pragma warning restore SA1313
{
this.InstanceId = InstanceId;
this.StartAt = StartAt;
}

/// <summary>
/// Initializes a new instance of the <see cref="StartOrchestrationOptions"/> class by copying from another instance.
/// </summary>
/// <param name="options">The start orchestration options to copy from.</param>
public StartOrchestrationOptions(StartOrchestrationOptions options)
{
Check.NotNull(options);
this.InstanceId = options.InstanceId;
this.StartAt = options.StartAt;
this.Tags = options.Tags;
this.Version = options.Version;
this.DedupeStatuses = options.DedupeStatuses;
}

/// <summary>
/// Gets the unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used.
/// </summary>
public string? InstanceId { get; init; }

/// <summary>
/// Gets the time when the orchestration instance should start executing. If not specified or if a date-time in the past
/// is specified, the orchestration instance will be scheduled immediately.
/// </summary>
public DateTimeOffset? StartAt { get; init; }

/// <summary>
/// Gets the tags to associate with the orchestration instance.
/// </summary>
Expand Down
94 changes: 94 additions & 0 deletions test/Abstractions.Tests/TaskOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,98 @@ public void WithDedupeStatuses_ConvertsAllEnumValuesToStrings()
result.DedupeStatuses.Should().Contain(status.ToString());
}
}

[Fact]
public void TaskOptions_CopyConstructor_CopiesAllProperties()
{
// Arrange
RetryPolicy policy = new(3, TimeSpan.FromSeconds(1));
TaskRetryOptions retry = new(policy);
Dictionary<string, string> tags = new() { { "key1", "value1" }, { "key2", "value2" } };
TaskOptions original = new(retry, tags);

// Act
TaskOptions copy = new(original);

// Assert
copy.Retry.Should().Be(original.Retry);
copy.Tags.Should().BeSameAs(original.Tags);
}

[Fact]
public void SubOrchestrationOptions_CopyConstructor_CopiesAllProperties()
{
// Arrange
RetryPolicy policy = new(3, TimeSpan.FromSeconds(1));
TaskRetryOptions retry = new(policy);
Dictionary<string, string> tags = new() { { "key1", "value1" }, { "key2", "value2" } };
string instanceId = Guid.NewGuid().ToString();
TaskVersion version = new("1.0");
SubOrchestrationOptions original = new(retry, instanceId)
{
Tags = tags,
Version = version,
};

// Act
SubOrchestrationOptions copy = new(original);

// Assert
copy.Retry.Should().Be(original.Retry);
copy.Tags.Should().BeSameAs(original.Tags);
copy.InstanceId.Should().Be(original.InstanceId);
copy.Version.Should().Be(original.Version);
}

[Fact]
public void SubOrchestrationOptions_CopyFromTaskOptions_CopiesVersionWhenSourceIsSubOrchestration()
{
// Arrange
RetryPolicy policy = new(3, TimeSpan.FromSeconds(1));
TaskRetryOptions retry = new(policy);
Dictionary<string, string> tags = new() { { "key1", "value1" } };
string instanceId = Guid.NewGuid().ToString();
TaskVersion version = new("1.0");
SubOrchestrationOptions original = new(retry, instanceId)
{
Tags = tags,
Version = version,
};

// Act
SubOrchestrationOptions copy = new(original as TaskOptions);

// Assert
copy.Retry.Should().Be(original.Retry);
copy.Tags.Should().BeSameAs(original.Tags);
copy.InstanceId.Should().Be(original.InstanceId);
copy.Version.Should().Be(original.Version);
}

[Fact]
public void StartOrchestrationOptions_CopyConstructor_CopiesAllProperties()
{
// Arrange
string instanceId = Guid.NewGuid().ToString();
DateTimeOffset startAt = DateTimeOffset.UtcNow.AddHours(1);
Dictionary<string, string> tags = new() { { "key1", "value1" }, { "key2", "value2" } };
TaskVersion version = new("1.0");
List<string> dedupeStatuses = new() { "Completed", "Failed" };
StartOrchestrationOptions original = new(instanceId, startAt)
{
Tags = tags,
Version = version,
DedupeStatuses = dedupeStatuses,
};

// Act
StartOrchestrationOptions copy = new(original);

// Assert
copy.InstanceId.Should().Be(original.InstanceId);
copy.StartAt.Should().Be(original.StartAt);
copy.Tags.Should().BeSameAs(original.Tags);
copy.Version.Should().Be(original.Version);
copy.DedupeStatuses.Should().BeSameAs(original.DedupeStatuses);
}
}
Loading