Solution restructured to use multiple test projects
This commit is contained in:
89
test/AMWD.Common.Tests/Cli/EnumerableWalkerTest.cs
Normal file
89
test/AMWD.Common.Tests/Cli/EnumerableWalkerTest.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AMWD.Common.Cli;
|
||||
|
||||
namespace AMWD.Common.Tests.Cli
|
||||
{
|
||||
[TestClass]
|
||||
public class EnumerableWalkerTest
|
||||
{
|
||||
private List<string> _list;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_list = ["one", "two", "three", "four"];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ShouldThrowExceptionOnNullReference()
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
_ = new EnumerableWalker<object>(null);
|
||||
|
||||
// assert - ArgumentNullException
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnEnumerator()
|
||||
{
|
||||
// arrange
|
||||
var walker = new EnumerableWalker<string>(_list);
|
||||
|
||||
// act
|
||||
var enumerator = walker.GetEnumerator();
|
||||
|
||||
// assert
|
||||
Assert.IsNotNull(enumerator);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnGenericEnumerator()
|
||||
{
|
||||
// arrange
|
||||
var walker = new EnumerableWalker<string>(_list);
|
||||
|
||||
// act
|
||||
var enumerator = ((IEnumerable<string>)walker).GetEnumerator();
|
||||
|
||||
// assert
|
||||
Assert.IsNotNull(enumerator);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnItems()
|
||||
{
|
||||
// arrange
|
||||
var walker = new EnumerableWalker<string>(_list);
|
||||
_ = walker.GetEnumerator();
|
||||
|
||||
string[] items = new string[_list.Count];
|
||||
|
||||
// act
|
||||
for (int i = 0; i < _list.Count; i++)
|
||||
items[i] = walker.GetNext();
|
||||
|
||||
// assert
|
||||
for (int i = 0; i < _list.Count; i++)
|
||||
Assert.AreEqual(_list[i], items[i], $"Position {i} failed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnDefaultWhenNothingLeft()
|
||||
{
|
||||
// arrange
|
||||
var walker = new EnumerableWalker<string>(Array.Empty<string>());
|
||||
_ = walker.GetEnumerator();
|
||||
|
||||
// act
|
||||
string item = walker.GetNext();
|
||||
|
||||
// assert
|
||||
Assert.AreEqual(default, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user