-
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
1 parent
dd4e9f1
commit 7d2c26c
Showing
8 changed files
with
497 additions
and
19 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
SLCommandScript.Core.UnitTests/Iterables/EmptyIterableTests.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,39 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using SLCommandScript.Core.Iterables; | ||
|
||
namespace SLCommandScript.Core.UnitTests.Iterables; | ||
|
||
[TestFixture] | ||
public class EmptyIterableTests | ||
{ | ||
#region Constructor Tests | ||
[Test] | ||
public void EmptyIterable_ShouldProperlyInitialize() | ||
{ | ||
// Act | ||
var iterable = new EmptyIterable(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(0); | ||
} | ||
#endregion | ||
|
||
#region LoadNext Tests | ||
[Test] | ||
public void LoadNext_ShouldReturnFalse() | ||
{ | ||
// Arrange | ||
var iterable = new EmptyIterable(); | ||
|
||
// Act | ||
var result = iterable.LoadNext(null); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(0); | ||
} | ||
#endregion | ||
} |
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
268 changes: 268 additions & 0 deletions
268
SLCommandScript.Core.UnitTests/Iterables/SingleItemIterableTests.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,268 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using SLCommandScript.Core.Iterables; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SLCommandScript.Core.UnitTests.Iterables; | ||
|
||
[TestFixture] | ||
public class SingleItemIterableTests | ||
{ | ||
private const string TestString = "test"; | ||
|
||
private static void Inject(IDictionary<string, string> target, string item) | ||
{ | ||
target[item] = item; | ||
} | ||
|
||
#region Constructor Tests | ||
[Test] | ||
public void SingleItemIterable_ShouldProperlyInitialize_WhenProvidedDataSourceIsNull() | ||
{ | ||
// Act | ||
var iterable = new SingleItemIterable<string>((Func<string>) null, null); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(0); | ||
} | ||
|
||
[Test] | ||
public void SingleItemIterable_ShouldProperlyInitialize_WhenProvidedDataSourceIsNotNull() | ||
{ | ||
// Act | ||
var iterable = new SingleItemIterable<string>(() => TestString, null); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void SingleItemIterable_ShouldProperlyInitialize_WhenProvidedItemDirectly() | ||
{ | ||
// Act | ||
var iterable = new SingleItemIterable<string>(TestString, null); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
#endregion | ||
|
||
#region LoadNext Tests | ||
[Test] | ||
public void LoadNext_ShouldProperlyIterate_WhenDataSourceIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>((Func<string>) null, null); | ||
|
||
// Act | ||
var result = iterable.LoadNext(null); | ||
|
||
// Assert | ||
result.Should().BeFalse(); | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(0); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlyIterate_WhenProvidedDictionaryIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(() => TestString, null); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(null)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlyIterate_WhenProvidedMapperIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(() => TestString, null); | ||
var variables = new TestVariablesCollector(); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(variables)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
variables.GetArray().Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlySetVariables_WhenProvidedDictionaryIsNotNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(() => TestString, Inject); | ||
var variables = new TestVariablesCollector(); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(variables)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
variables.GetArray().Should().HaveCount(1); | ||
variables.GetArray().Should().Contain(TestString); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlyIterate_WhenProvidedItemAndDictionaryIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(TestString, null); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(null)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlyIterate_WhenProvidedItemAndMapperIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(TestString, null); | ||
var variables = new TestVariablesCollector(); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(variables)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
variables.GetArray().Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void LoadNext_ShouldProperlySetVariables_WhenProvidedItemAndDictionaryIsNotNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(TestString, Inject); | ||
var variables = new TestVariablesCollector(); | ||
var count = 0; | ||
|
||
// Act | ||
while (iterable.LoadNext(variables)) | ||
{ | ||
++count; | ||
} | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(1); | ||
count.Should().Be(1); | ||
variables.GetArray().Should().HaveCount(1); | ||
variables.GetArray().Should().Contain(TestString); | ||
} | ||
#endregion | ||
|
||
#region Reset Tests | ||
[Test] | ||
public void Reset_ShouldProperlyResetIterable_WhenSourceIsNull() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>((Func<string>) null, Inject); | ||
|
||
// Act | ||
iterable.Reset(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeTrue(); | ||
iterable.Count.Should().Be(0); | ||
} | ||
|
||
[Test] | ||
public void Reset_ShouldProperlyResetIterable_BeforeRunning() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(() => TestString, Inject); | ||
|
||
// Act | ||
iterable.Reset(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void Reset_ShouldProperlyResetIterable_AfterRunning() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(() => TestString, Inject); | ||
|
||
// Act | ||
while (iterable.LoadNext(null)) {} | ||
iterable.Reset(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void Reset_ShouldProperlyResetIterable_BeforeRunningOnItem() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(TestString, Inject); | ||
|
||
// Act | ||
iterable.Reset(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
public void Reset_ShouldProperlyResetIterable_AfterRunningOnItem() | ||
{ | ||
// Arrange | ||
var iterable = new SingleItemIterable<string>(TestString, Inject); | ||
|
||
// Act | ||
while (iterable.LoadNext(null)) { } | ||
iterable.Reset(); | ||
|
||
// Assert | ||
iterable.IsAtEnd.Should().BeFalse(); | ||
iterable.Count.Should().Be(1); | ||
} | ||
#endregion | ||
} |
Oops, something went wrong.