Last active
November 30, 2015 18:15
-
-
Save bitbonk/f48c460c5bd065606b55 to your computer and use it in GitHub Desktop.
Can I have one Should() instead of two?
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
using System; | |
using System.Collections; | |
using System.Linq; | |
using FluentAssertions; | |
using Xunit; | |
public class ParserTests | |
{ | |
[Theory, | |
InlineData(DataType.String, "foo", "foo"), | |
InlineData(DataType.Integer, "42", 42), | |
InlineData(DataType.ByteArray, "1,2,3", new byte[] { 1, 2, 3 }), | |
InlineData(DataType.ByteArray, "1,2,3", new double[] { 1, 2, 3 })] | |
public void ShouldAllEqual(DataType datatype, string dataToParse, object expectedResult) | |
{ | |
var result = Parser.Parse(datatype, dataToParse); | |
result.ShouldBeEquivalentTo(expectedResult, o => o.RespectingRuntimeTypes()); | |
} | |
} | |
// Simplified SUT: | |
public enum DataType | |
{ | |
String, | |
Integer, | |
ByteArray | |
} | |
public static class Parser | |
{ | |
public static object Parse(DataType datatype, string dataToParse) | |
{ | |
switch (datatype) | |
{ | |
case DataType.Integer: | |
return int.Parse(dataToParse); | |
case DataType.ByteArray: | |
return | |
dataToParse.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) | |
.Select(byte.Parse) | |
.ToList(); | |
default: | |
return dataToParse; | |
} | |
} | |
} |
You probably meant RespectingRuntimeTypes()
that will not fail the last test (that I have just added) but it should.
Yes, that's the one I meant. But I suspect it's doing the automatic conversion. The only way to remove that one is to modify it on a global level using the AssertionOptions.EquivalencySteps
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could try
result.ShouldBeEquivalentTo(expectedResult, options => options.IncludingRuntimeType)
;