Skip to content

Commit

Permalink
To action (#76)
Browse files Browse the repository at this point in the history
Closes #69
  • Loading branch information
Galad authored Jun 6, 2018
1 parent 7f30776 commit 0d68deb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Tranquire.Tests/TranquireEnumerableExtensionsTests.cs
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));
}
}
}
}
33 changes: 33 additions & 0 deletions src/Tranquire/TranquireEnumerableExtensions.cs
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());
}
}
}

0 comments on commit 0d68deb

Please sign in to comment.