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
10 changes: 7 additions & 3 deletions src/Dapr.Workflow/WorkflowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal WorkflowState(WorkflowMetadata? metadata)
{
_metadata = metadata;
}

/// <summary>
/// Gets a value indicating whether the requested workflow instance exists.
/// </summary>
Expand All @@ -53,12 +53,16 @@ WorkflowRuntimeStatus.Failed or
/// <summary>
/// Gets the time at which this workflow instance was created.
/// </summary>
public DateTimeOffset CreatedAt => _metadata?.CreatedAt ?? default;
public DateTimeOffset CreatedAt => _metadata?.CreatedAt is { } dt && dt != default
? new DateTimeOffset(DateTime.SpecifyKind(dt, DateTimeKind.Utc))
: default;

/// <summary>
/// Gets the time at which this workflow instance last had its state updated.
/// </summary>
public DateTimeOffset LastUpdatedAt => _metadata?.LastUpdatedAt ?? default;
public DateTimeOffset LastUpdatedAt => _metadata?.LastUpdatedAt is { } dt && dt != default
? new DateTimeOffset(DateTime.SpecifyKind(dt, DateTimeKind.Utc))
: default;

/// <summary>
/// Gets the execution status of the workflow.
Expand Down
22 changes: 20 additions & 2 deletions test/Dapr.Workflow.Test/WorkflowStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,29 @@ public void Properties_ShouldReflectMetadata_WhenPresent()
Assert.True(state.Exists);
Assert.True(state.IsWorkflowRunning);
Assert.False(state.IsWorkflowCompleted);
Assert.Equal(created, state.CreatedAt);
Assert.Equal(updated, state.LastUpdatedAt);
Assert.Equal(created, state.CreatedAt.DateTime);
Assert.Equal(updated, state.LastUpdatedAt.DateTime);
Assert.Equal(WorkflowRuntimeStatus.Running, state.RuntimeStatus);
}

[Fact]
public void CreatedAt_ShouldReturnDefault_WhenMetadataCreatedAtIsMinValue()
{
var serializer = new JsonWorkflowSerializer();
var metadata = new WorkflowMetadata(
InstanceId: "i",
Name: "wf",
RuntimeStatus: WorkflowRuntimeStatus.Running,
CreatedAt: DateTime.MinValue,
LastUpdatedAt: DateTime.MinValue,
Serializer: serializer);

var state = new WorkflowState(metadata);

Assert.Equal(DateTime.MinValue, state.CreatedAt.DateTime);
Assert.Equal(DateTime.MinValue, state.LastUpdatedAt.DateTime);
}

[Theory]
[InlineData(WorkflowRuntimeStatus.Completed)]
[InlineData(WorkflowRuntimeStatus.Failed)]
Expand Down
Loading