Skip to content

Commit

Permalink
Extensions tests complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Theauxm committed Jul 11, 2024
1 parent 080d9e8 commit d998cb6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
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 ChainSharp.Tests.Unit/UnitTests/Extensions/ExtractTupleTests.cs
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using FluentAssertions;
using LanguageExt;

namespace ChainSharp.Tests.Unit.UnitTests;
namespace ChainSharp.Tests.Unit.UnitTests.Extensions;

public class ExtractTypeFromMemoryTests : TestSetup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using FluentAssertions;
using LanguageExt;

namespace ChainSharp.Tests.Unit.UnitTests;
namespace ChainSharp.Tests.Unit.UnitTests.Extensions;

public class InitializeStepTests : TestSetup
{
Expand Down

0 comments on commit d998cb6

Please sign in to comment.