Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test names #100

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion System.IO.Ports/SerialPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ internal static SerialPort FindDevice(int index)
/// <exception cref="IOException">The port is in an invalid state. -or- An attempt to set the state of the underlying
/// port failed. For example, the parameters passed from this <see cref="SerialPort"/>
/// object were invalid.</exception>
protected void Dispose(bool disposing)
internal void Dispose(bool disposing)
{
if (!_disposed)
{
Expand Down
4 changes: 2 additions & 2 deletions System.IO.Ports/System.IO.Ports.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<Import Project="..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion System.IO.Ports/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.IO.Streams" version="1.1.9" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Text" version="1.2.3" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.5.107" targetFramework="netnanoframework10" developmentDependency="true" />
</packages>
95 changes: 65 additions & 30 deletions Tests/UnitTestsSerialPort/SerialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See LICENSE file in the project root for full license information.
//

using nanoFramework.Hardware.Esp32;
using nanoFramework.Hardware.Esp32; // TODO: only include if platform needs it?!
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
using nanoFramework.TestFramework;
using System;
using System.Diagnostics;
Expand All @@ -20,12 +20,14 @@ public class SerialTests
static SerialPort _serOne;
static SerialPort _serTwo;

// TODO: only include if platform needs it?!
[Setup]
public void SetupComPorts()
public void SetupComPorts_ESP32()
{
OutputHelper.WriteLine("Setting up tests for an ESP32...");
try
{
Debug.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");
OutputHelper.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");
Configuration.SetPinFunction(32, DeviceFunction.COM2_RX);
Configuration.SetPinFunction(33, DeviceFunction.COM2_TX);
Configuration.SetPinFunction(12, DeviceFunction.COM2_RTS);
Expand All @@ -36,42 +38,75 @@ public void SetupComPorts()
Configuration.SetPinFunction(27, DeviceFunction.COM3_RTS);
Configuration.SetPinFunction(14, DeviceFunction.COM3_CTS);

Debug.WriteLine("You will need to connect:");
Debug.WriteLine(" COM2 RX <-> COM3 TX");
Debug.WriteLine(" COM2 TX <-> COM3 RX");
Debug.WriteLine(" COM2 RTS <-> COM3 CTS");
Debug.WriteLine(" COM2 CTS <-> COM3 RTS");
OutputHelper.WriteLine("You will need to connect:");
OutputHelper.WriteLine(" COM2 RX <-> COM3 TX");
OutputHelper.WriteLine(" COM2 TX <-> COM3 RX");
OutputHelper.WriteLine(" COM2 RTS <-> COM3 CTS"); // TODO: Optional?!
OutputHelper.WriteLine(" COM2 CTS <-> COM3 RTS"); // TODO: Optional?!
_serOne = new SerialPort("COM2");
_serTwo = new SerialPort("COM3");
Debug.WriteLine("Devices created, trying to open them");
OutputHelper.WriteLine("SerialPorts created, trying to open them");
_serOne.Open();
Debug.WriteLine("Serial One COM2 opened");
OutputHelper.WriteLine("SerialPort One COM2 opened.");
_serTwo.Open();
Debug.WriteLine("Devices opened, will close them");
// Wait a bit just to make sure and close them again
OutputHelper.WriteLine("SerialPort Two COM3 opened.");
OutputHelper.WriteLine("All SerialPorts opened, will close them");
// Wait a bit just to make sure and close them all
Thread.Sleep(100);
_serOne.Close();
_serTwo.Close();
EnsurePortsClosed();
OutputHelper.WriteLine("SerialPorts Closed.");
}
catch
{
Assert.SkipTest("Serial Ports not supported in this platform or not properly configured");
}
}

//[Setup]
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
//public void SetupComPorts_ChibOs_STM32F769I_Disco()
//{
// OutputHelper.WriteLine("Setting up tests for an STM32F769I...");
// try
// {
// Debug.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");

// OutputHelper.WriteLine("You will need to connect:");
// OutputHelper.WriteLine(" COM5 (PD2) RX <-> COM6 (PC6) TX");
// OutputHelper.WriteLine(" COM5 (PC12) TX <-> COM6 (PC7) RX");
// // OutputHelper.WriteLine(" COM5 RTS <-> COM6 CTS");
// // OutputHelper.WriteLine(" COM5 CTS <-> COM6 RTS");
// _serOne = new SerialPort("COM5");
// _serTwo = new SerialPort("COM6");
// OutputHelper.WriteLine("SerialPorts created, trying to open them");
// _serOne.Open();
// OutputHelper.WriteLine("SerialPort One COM5 opened");
// _serTwo.Open();
// OutputHelper.WriteLine("SerialPort Two COM6 opened");
// OutputHelper.WriteLine("SarialPorts opened, will close them");
// // Wait a bit just to make sure and close them all
// Thread.Sleep(100);
// EnsurePortsClosed();
// OutputHelper.WriteLine("SerialPorts Closed.");
// }
// catch
// {
// Assert.SkipTest("Serial Ports not supported in this platform or not properly configured");
// }
//}

[TestMethod]
public void GetPortNamesTest()
public void GetAllAvailableSerialPortNames()
{
var ports = SerialPort.GetPortNames();
Debug.WriteLine("Available ports:");
OutputHelper.WriteLine("Available SerialPorts:");
foreach (string port in ports)
{
Debug.WriteLine($" {port}");
OutputHelper.WriteLine($" {port}");
}
}

[TestMethod]
public void BasicReadWriteTests()
public void WriteAndReadFourBytes()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -111,7 +146,7 @@ public void VerifyDefaultReadLineCharacter()
}

[TestMethod]
public void WriteAndReadStringTests()
public void WriteAndReadSimpleAsciiString_37Chars()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -128,7 +163,7 @@ public void WriteAndReadStringTests()
}

[TestMethod]
public void ReadMultipleLinesTests()
public void WriteAndReadMultipleLineAsciiString()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -149,7 +184,7 @@ public void ReadMultipleLinesTests()
}

[TestMethod]
public void CheckReadByteSize()
public void CheckReadByteSizeUtf8String()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -188,7 +223,7 @@ public void CheckReadLineWithoutAnything()
}

[TestMethod]
public void CheckReadTimeoutTest()
public void CheckReadTimeout()
{
Assert.Throws(typeof(TimeoutException), () =>
{
Expand All @@ -204,7 +239,7 @@ public void CheckReadTimeoutTest()
}

[TestMethod]
public void ReadByteWriteByteTests()
public void WriteThreeBytesReadSingleByte()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -227,7 +262,7 @@ public void ReadByteWriteByteTests()
}

[TestMethod]
public void CheckBytesAvailableTest()
public void CheckBytesAreAvailable()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -266,7 +301,7 @@ public void TryReadWriteWhileClosed()
}

[TestMethod]
public void AdjustBaudRateTests()
public void AdjustBaudRateTo115200()
{
// Arrange
_serOne.BaudRate = 115200;
Expand All @@ -276,7 +311,7 @@ public void AdjustBaudRateTests()
}

[TestMethod]
public void AdjustHandshakeTests()
public void AdjustHandshakeRTS()
{
// Arrange
_serOne.Handshake = Handshake.RequestToSend;
Expand All @@ -289,7 +324,7 @@ public void AdjustHandshakeTests()
}

[TestMethod]
public void TestStreams()
public void StreamsCanWriteRead()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -315,7 +350,7 @@ public void TestStreams()
}

[TestMethod]
public void TestEvents()
public void DataReceivedEventsAreGenerated()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -343,7 +378,7 @@ private void DataReceivedNormalEventTest(object sender, SerialDataReceivedEventA
}

[TestMethod]
public void TestWatchCharEvents()
public void WatchCharEventsAreGenerated()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -388,7 +423,7 @@ private void SendAndReceiveBasic()
}

[Cleanup]
public void CleanPorts()
public void DisposeSerialPorts()
{
EnsurePortsClosed();
_serOne.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.1",
"version": "2.2",
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
"assemblyVersion": {
"precision": "revision"
},
Expand Down