Skip to content

Commit

Permalink
Improved Assertion syntax, using Has.Count, Has.Length when possible,…
Browse files Browse the repository at this point in the history
… using Multiple assertions
  • Loading branch information
angalbiati committed Sep 5, 2024
1 parent 40c79a0 commit cd4f610
Show file tree
Hide file tree
Showing 11 changed files with 815 additions and 431 deletions.
296 changes: 190 additions & 106 deletions DbcParserLib.Tests/DbcBuilderTests.cs

Large diffs are not rendered by default.

62 changes: 37 additions & 25 deletions DbcParserLib.Tests/EnvironmentVariableLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ public void EnvironmentVariableDefinitionLineIsParsedTest()
dbcBuilderMock.Setup(mock => mock.AddEnvironmentVariable("EnvKlemme45", It.IsAny<EnvironmentVariable>()))
.Callback<string, EnvironmentVariable>((_, envVariable) =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Integer));
Assert.That(envVariable.IntegerEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.IntegerEnvironmentVariable.Maximum, Is.EqualTo(1));
Assert.That(envVariable.IntegerEnvironmentVariable.Default, Is.EqualTo(0));
Assert.Multiple(() =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Integer));
Assert.That(envVariable.IntegerEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.IntegerEnvironmentVariable.Maximum, Is.EqualTo(1));
Assert.That(envVariable.IntegerEnvironmentVariable.Default, Is.EqualTo(0));
});
}
);
dbcBuilderMock.Setup(mock => mock.AddNodeEnvironmentVariable("ENTtest", "EnvKlemme45"));
Expand All @@ -77,10 +80,13 @@ public void EnvironmentVariableAlwaysStringDefinitionLineIsParsedTest()
dbcBuilderMock.Setup(mock => mock.AddEnvironmentVariable("EnvKlemme45", It.IsAny<EnvironmentVariable>()))
.Callback<string, EnvironmentVariable>((_, envVariable) =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.String));
Assert.Multiple(() =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.String));
});
}
);
dbcBuilderMock.Setup(mock => mock.AddNodeEnvironmentVariable("ENTtest", "EnvKlemme45"));
Expand All @@ -99,13 +105,16 @@ public void EnvironmentVariableFloatDefinitionLineIsParsedTest()
dbcBuilderMock.Setup(mock => mock.AddEnvironmentVariable("EnvKlemme45", It.IsAny<EnvironmentVariable>()))
.Callback<string, EnvironmentVariable>((_, envVariable) =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Float));
Assert.That(envVariable.FloatEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.FloatEnvironmentVariable.Maximum, Is.EqualTo(10));
Assert.That(envVariable.FloatEnvironmentVariable.Default, Is.EqualTo(5));
Assert.Multiple(() =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Float));
Assert.That(envVariable.FloatEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.FloatEnvironmentVariable.Maximum, Is.EqualTo(10));
Assert.That(envVariable.FloatEnvironmentVariable.Default, Is.EqualTo(5));
});
}
);
dbcBuilderMock.Setup(mock => mock.AddNodeEnvironmentVariable("ENTtest", "EnvKlemme45"));
Expand All @@ -124,13 +133,16 @@ public void EnvironmentVariableFloatScientificNotationDefinitionLineIsParsedTest
dbcBuilderMock.Setup(mock => mock.AddEnvironmentVariable("EnvKlemme45", It.IsAny<EnvironmentVariable>()))
.Callback<string, EnvironmentVariable>((_, envVariable) =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Float));
Assert.That(envVariable.FloatEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.FloatEnvironmentVariable.Maximum, Is.EqualTo(10));
Assert.That(envVariable.FloatEnvironmentVariable.Default, Is.EqualTo(5));
Assert.Multiple(() =>
{
Assert.That(envVariable.Name, Is.EqualTo("EnvKlemme45"));
Assert.That(envVariable.Unit, Is.EqualTo(""));
Assert.That(envVariable.Access, Is.EqualTo(EnvAccessibility.Unrestricted));
Assert.That(envVariable.Type, Is.EqualTo(EnvDataType.Float));
Assert.That(envVariable.FloatEnvironmentVariable.Minimum, Is.EqualTo(0));
Assert.That(envVariable.FloatEnvironmentVariable.Maximum, Is.EqualTo(10));
Assert.That(envVariable.FloatEnvironmentVariable.Default, Is.EqualTo(5));
});
}
);
dbcBuilderMock.Setup(mock => mock.AddNodeEnvironmentVariable("ENTtest", "EnvKlemme45"));
Expand Down
92 changes: 64 additions & 28 deletions DbcParserLib.Tests/ExtensionMethodsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public void MotorolaTest()
ByteOrder = 0, // 0 = Big Endian (Motorola), 1 = Little Endian (Intel)
};

Assert.That(sig.Motorola(), Is.True);
Assert.That(sig.Msb(), Is.True);
Assert.That(sig.Intel(), Is.False);
Assert.That(sig.Lsb(), Is.False);
Assert.Multiple(() =>
{
Assert.That(sig.Motorola(), Is.True);
Assert.That(sig.Msb(), Is.True);
Assert.That(sig.Intel(), Is.False);
Assert.That(sig.Lsb(), Is.False);
});
}

[Test]
Expand All @@ -29,10 +32,13 @@ public void IntelTest()
ByteOrder = 1, // 0 = Big Endian (Motorola), 1 = Little Endian (Intel)
};

Assert.That(sig.Motorola(), Is.False);
Assert.That(sig.Msb(), Is.False);
Assert.That(sig.Intel(), Is.True);
Assert.That(sig.Lsb(), Is.True);
Assert.Multiple(() =>
{
Assert.That(sig.Motorola(), Is.False);
Assert.That(sig.Msb(), Is.False);
Assert.That(sig.Intel(), Is.True);
Assert.That(sig.Lsb(), Is.True);
});
}

[Test]
Expand All @@ -44,8 +50,11 @@ public void NoMultiplexingTest()
};

var multiplexing = sig.MultiplexingInfo();
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.None));
Assert.That(multiplexing.Group, Is.EqualTo(0));
Assert.Multiple(() =>
{
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.None));
Assert.That(multiplexing.Group, Is.EqualTo(0));
});
}

[Test]
Expand All @@ -57,8 +66,11 @@ public void MultiplexorTest()
};

var multiplexing = sig.MultiplexingInfo();
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexor));
Assert.That(multiplexing.Group, Is.EqualTo(0));
Assert.Multiple(() =>
{
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexor));
Assert.That(multiplexing.Group, Is.EqualTo(0));
});
}

[Test]
Expand All @@ -70,8 +82,11 @@ public void MultiplexedSingleDigitTest()
};

var multiplexing = sig.MultiplexingInfo();
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(3));
Assert.Multiple(() =>
{
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(3));
});
}

[Test]
Expand All @@ -83,8 +98,11 @@ public void ExtendedMultiplexingIsPartiallySupportedTest()
};

var multiplexing = sig.MultiplexingInfo();
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(3));
Assert.Multiple(() =>
{
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(3));
});
}

[Test]
Expand All @@ -96,8 +114,11 @@ public void MultiplexedDoubleDigitTest()
};

var multiplexing = sig.MultiplexingInfo();
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(12));
Assert.Multiple(() =>
{
Assert.That(multiplexing.Role, Is.EqualTo(MultiplexingRole.Multiplexed));
Assert.That(multiplexing.Group, Is.EqualTo(12));
});
}

[Test]
Expand Down Expand Up @@ -170,8 +191,11 @@ public void FsmNoSpacesParsedTest()
{ 3, "Third" }
};

Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
Assert.Multiple(() =>
{
Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
});
}

[Test]
Expand All @@ -186,8 +210,11 @@ public void FsmWithSpacesParsedTest()
{ 3, " T h i r d " }
};

Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
Assert.Multiple(() =>
{
Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
});
}

[Test]
Expand All @@ -201,8 +228,11 @@ public void FsmWithEmptyStringParsedTest()
{ 2, " " }
};

Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
Assert.Multiple(() =>
{
Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
});
}

[Test]
Expand All @@ -216,8 +246,11 @@ public void FsmWithIntegerStringParsedTest()
{ 2, "2" }
};

Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
Assert.Multiple(() =>
{
Assert.That(operation, Is.True);
Assert.That(dict, Is.EqualTo(expectedDict));
});
}

[Test]
Expand All @@ -226,8 +259,11 @@ public void FsmErrorTest()
var text = "1 \"First with spaces\" 2 \" Second \" 3 T h i r d \"";
var operation = text.TryParseToDict(out var dict);

Assert.That(operation, Is.False);
Assert.That(dict, Is.Null);
Assert.Multiple(() =>
{
Assert.That(operation, Is.False);
Assert.That(dict, Is.Null);
});
}
}
}
26 changes: 16 additions & 10 deletions DbcParserLib.Tests/MessageLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ public void FullLineIsParsed()
dbcBuilderMock.Setup(mock => mock.AddMessage(It.IsAny<Message>()))
.Callback<Message>(message =>
{
Assert.That(message.ID, Is.EqualTo(1041));
Assert.That(message.Name, Is.EqualTo("DOORS_SEATBELTS"));
Assert.That(message.DLC, Is.EqualTo(8));
Assert.That(message.Transmitter, Is.EqualTo("TRX"));
Assert.That(message.IsExtID, Is.False);
Assert.Multiple(() =>
{
Assert.That(message.ID, Is.EqualTo(1041));
Assert.That(message.Name, Is.EqualTo("DOORS_SEATBELTS"));
Assert.That(message.DLC, Is.EqualTo(8));
Assert.That(message.Transmitter, Is.EqualTo("TRX"));
Assert.That(message.IsExtID, Is.False);
});
});

var messageLineParser = CreateParser();
Expand All @@ -94,11 +97,14 @@ public void FullLineWithSomeRamdomSpacesIsParsed()
dbcBuilderMock.Setup(mock => mock.AddMessage(It.IsAny<Message>()))
.Callback<Message>(message =>
{
Assert.That(message.ID, Is.EqualTo(1041));
Assert.That(message.Name, Is.EqualTo("DOORS_SEATBELTS"));
Assert.That(message.DLC, Is.EqualTo(8));
Assert.That(message.Transmitter, Is.EqualTo("TRX"));
Assert.That(message.IsExtID, Is.False);
Assert.Multiple(() =>
{
Assert.That(message.ID, Is.EqualTo(1041));
Assert.That(message.Name, Is.EqualTo("DOORS_SEATBELTS"));
Assert.That(message.DLC, Is.EqualTo(8));
Assert.That(message.Transmitter, Is.EqualTo("TRX"));
Assert.That(message.IsExtID, Is.False);
});
});

var messageLineParser = CreateParser();
Expand Down
14 changes: 10 additions & 4 deletions DbcParserLib.Tests/NodeLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,22 @@ public void FullLineIsParsed()
dbcBuilderMock.Setup(mock => mock.AddNode(It.IsAny<Node>()))
.Callback<Node>(node =>
{
Assert.That(string.IsNullOrWhiteSpace(node.Name), Is.False);
Assert.That(string.IsNullOrWhiteSpace(node.Comment), Is.True);
Assert.Multiple(() =>
{
Assert.That(string.IsNullOrWhiteSpace(node.Name), Is.False);
Assert.That(string.IsNullOrWhiteSpace(node.Comment), Is.True);
});
results.Add(node.Name);
});

var nodeLineParser = CreateParser();
var nextLineProviderMock = m_repository.Create<INextLineProvider>();

Assert.That(nodeLineParser.TryParse(@"BU_: NODE_1 NODE_2 NODE_4 ", dbcBuilderMock.Object, nextLineProviderMock.Object), Is.True);
Assert.That(results, Is.EquivalentTo(expectations));
Assert.Multiple(() =>
{
Assert.That(nodeLineParser.TryParse(@"BU_: NODE_1 NODE_2 NODE_4 ", dbcBuilderMock.Object, nextLineProviderMock.Object), Is.True);
Assert.That(results, Is.EquivalentTo(expectations));
});
}

[TestCase("BU_: 0nodeName")]
Expand Down
Loading

0 comments on commit cd4f610

Please sign in to comment.