-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
ChainSharp.Tests.Unit/UnitTests/Extensions/AddTupleToMemoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Runtime.CompilerServices; | ||
using ChainSharp.Exceptions; | ||
using ChainSharp.Extensions; | ||
using ChainSharp.Workflow; | ||
using FluentAssertions; | ||
using LanguageExt; | ||
|
||
namespace ChainSharp.Tests.Unit.UnitTests.Extensions; | ||
|
||
public class AddTupleToMemoryTests : TestSetup | ||
{ | ||
[Theory] | ||
public async Task TestAddTupleToMemory() | ||
{ | ||
// Arrange | ||
var input = 1; | ||
var inputTuple = ("hello", false); | ||
|
||
var workflow = new TestWorkflow().Activate(input); | ||
|
||
// Act | ||
workflow.AddTupleToMemory(inputTuple); | ||
|
||
// Assert | ||
|
||
workflow.Exception.Should().BeNull(); | ||
workflow.Memory.Count.Should().Be(4); // Unit is always added, along with input. | ||
workflow.Memory.Values.Should().Contain(false); | ||
workflow.Memory.Values.Should().Contain("hello"); | ||
} | ||
|
||
[Theory] | ||
public async Task TestInvalidAddTupleToMemoryNotTuple() | ||
{ | ||
// Arrange | ||
var input = 1; | ||
var inputTuple = "hello"; | ||
|
||
var workflow = new TestWorkflow().Activate(input); | ||
|
||
// Act | ||
Assert.Throws<WorkflowException>(() => workflow.AddTupleToMemory(inputTuple)); | ||
} | ||
|
||
[Theory] | ||
public async Task TestInvalidAddTupleToMemoryNull() | ||
{ | ||
// Arrange | ||
var input = 1; | ||
var workflow = new TestWorkflow().Activate(input); | ||
|
||
// Act | ||
Assert.Throws<WorkflowException>(() => workflow.AddTupleToMemory((ITuple)null!)); | ||
} | ||
|
||
private class TestWorkflow : Workflow<int, string> | ||
{ | ||
protected override async Task<Either<Exception, string>> RunInternal(int input) => | ||
Resolve(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
ChainSharp.Tests.Unit/UnitTests/Extensions/ExtractTupleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using ChainSharp.Exceptions; | ||
using ChainSharp.Extensions; | ||
using ChainSharp.Workflow; | ||
using FluentAssertions; | ||
using LanguageExt; | ||
|
||
namespace ChainSharp.Tests.Unit.UnitTests.Extensions; | ||
|
||
public class ExtractTupleTests : TestSetup | ||
{ | ||
[Theory] | ||
public async Task TestExtractTuple() | ||
{ | ||
// Arrange | ||
var input = 1; | ||
|
||
var inputObject = new object(); | ||
var workflow = new TestWorkflow().Activate(input, "hello", false, 'c', inputObject); | ||
|
||
var inputTuple = typeof(ValueTuple<int, string, bool, char, object>); | ||
|
||
// Act | ||
var result = (ValueTuple<int, string, bool, char, object>)workflow.ExtractTuple(inputTuple); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Item1.Should().Be(1); | ||
result.Item2.Should().Be("hello"); | ||
result.Item3.Should().Be(false); | ||
result.Item4.Should().Be('c'); | ||
result.Item5.Should().Be(inputObject); | ||
} | ||
|
||
[Theory] | ||
public async Task TestInvalidExtractTuple() | ||
{ | ||
// Arrange | ||
var input = 1; | ||
|
||
var workflow = new TestWorkflow().Activate(input); | ||
|
||
var inputTuple = typeof(ValueTuple<int>); | ||
|
||
// Act | ||
Assert.Throws<WorkflowException>(() => workflow.ExtractTuple(inputTuple)); | ||
} | ||
|
||
private class TestWorkflow : Workflow<int, string> | ||
{ | ||
protected override async Task<Either<Exception, string>> RunInternal(int input) => | ||
Resolve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters