public void _01_Convert_ShouldCreateACommaSeparatedStringOfNumbers() { //Arrange var drawedNumbers = new List <DrawNumber> { new DrawNumberBuilder(_random).Build(), new DrawNumberBuilder(_random).Build(), new DrawNumberBuilder(_random).Build() }; //Act var result = _converter.Convert(drawedNumbers, null, null, null); //Assert Assert.That(result, Is.Not.Null, () => "The converted object should not be null."); Assert.That(result, Is.TypeOf <string>(), () => $"The converted object should be a string, but was '{result.GetType().FullName}'."); var numberString = (string)result; Assert.That(drawedNumbers.All(d => numberString.Contains(d.Number.ToString())), Is.True, () => "The converted string does not contain all the numbers."); Assert.That(numberString.Count(c => c == ','), Is.EqualTo(drawedNumbers.Count - 1), () => $"The converted string should contain {drawedNumbers.Count - 1} comma's when there are {drawedNumbers.Count} drawed numbers."); Assert.That(numberString, Does.Not.EndsWith(" ").And.Not.EndsWith(","), () => "The converted string should not end with a whitespace or a comma."); }
public void _01_Convert_ShouldCreateACommaSeperatedStringOfNumbers() { //Arrange var drawedNumbers = new HashSet <DrawNumber> { new DrawNumberBuilder(_random).Build(), new DrawNumberBuilder(_random).Build(), new DrawNumberBuilder(_random).Build() }; //Act object result = null; try { result = _converter.Convert(drawedNumbers, null, null, null); } catch (InvalidCastException) { Assert.Fail("An InvalidCastException is thrown when the value is a Hashset<DrawNumber>. " + "Cast to an IEnumerable<DrawNumber> to be able to handle all collection types."); } //Assert Assert.That(result, Is.Not.Null, "The converted object should not be null."); Assert.That(result, Is.TypeOf <string>(), $"The converted object should be a string, but was '{result.GetType().FullName}'."); var numberString = (string)result; Assert.That(drawedNumbers.All(d => numberString.Contains(d.Number.ToString())), Is.True, "The converted string does not contain all the numbers."); Assert.That(numberString.Count(c => c == ','), Is.EqualTo(drawedNumbers.Count - 1), $"The converted string should contain {drawedNumbers.Count - 1} comma's when there are {drawedNumbers.Count} drawed numbers."); Assert.That(numberString, Does.Not.EndsWith(" ").And.Not.EndsWith(","), "The converted string should not end with a whitespace or a comma."); }