-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #69
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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,39 @@ | ||
using AutoFixture; | ||
using AutoFixture.Idioms; | ||
using FluentAssertions; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Tranquire.Tests; | ||
using Xunit; | ||
|
||
namespace Tranquire.Tests | ||
{ | ||
public class TranquireEnumerableExtensionsTests | ||
{ | ||
[Theory, DomainAutoData] | ||
public void Sut_VerifyGuardClause(GuardClauseAssertion assertion) | ||
{ | ||
assertion.Verify(typeof(TranquireEnumerableExtensions)); | ||
} | ||
|
||
[Theory, DomainAutoData] | ||
public void ToAction_ShouldBeActionThatCallsAllActions( | ||
IAction<Unit>[] actions, | ||
string name, | ||
Mock<IActor> actor) | ||
{ | ||
//arrange | ||
//act | ||
var actual = actions.ToAction(name); | ||
actual.ExecuteWhenAs(actor.Object); | ||
//assert | ||
actual.Name.Should().Be(name); | ||
foreach (var action in actions) | ||
{ | ||
actor.Verify(m => m.Execute(action)); | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Tranquire; | ||
|
||
namespace System.Linq | ||
{ | ||
/// <summary> | ||
/// Extension methods for IEnumerable of actions and questions | ||
/// </summary> | ||
public static class TranquireEnumerableExtensions | ||
{ | ||
/// <summary> | ||
/// Transform an IEnumerable of action in a single action | ||
/// </summary> | ||
/// <param name="actions">The list of actions</param> | ||
/// <param name="name">The resulting action name</param> | ||
/// <returns>A new action that will execute the input action one after the other</returns> | ||
public static IAction<Unit> ToAction(this IEnumerable<IAction<Unit>> actions, string name) | ||
{ | ||
if (actions == null) | ||
{ | ||
throw new ArgumentNullException(nameof(actions)); | ||
} | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
throw new ArgumentNullException(nameof(name)); | ||
} | ||
|
||
return new DefaultCompositeAction(name, actions.ToArray()); | ||
} | ||
} | ||
} |