Skip to content

Extract interface ISerialPortStream for better testing/mocking#77

Closed
tedvanderveen wants to merge 2 commits intojcurl:v2.xfrom
tedvanderveen:v2.x
Closed

Extract interface ISerialPortStream for better testing/mocking#77
tedvanderveen wants to merge 2 commits intojcurl:v2.xfrom
tedvanderveen:v2.x

Conversation

@tedvanderveen
Copy link
Contributor

For UnitTests, there are no actual Com ports and connected devices available, so in an ideal world creating a Mock (using Moq for example) requires no actual implementation, just an interface to mock.


void CopyTo(Stream destination);
void CopyTo(Stream destination, int bufferSize);
Task CopyToAsync(Stream destination);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The *Async won't compile for .NET 4.0, which I still use

/// active that the stream can continue to read. Writes will throw an exception.
/// </remarks>
#if !NETSTANDARD15
public new void Close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile for NETFX.

jcurl pushed a commit that referenced this pull request Nov 1, 2018
Having an interface allows for test code to be created without having to have an actual serial port. Just write the test code against the interface.

Original Pull Request: #77

Additions to this pull request to make it compile:
* Included the interface in the solution files for .NET 4.0 / 4.5;
* Fix compile errors in the interface for NETFX;
* Fix .NET 4.0 compatibility by not including the XXXAsync methods;
* Added documentation to removing warnings when building.
@jcurl
Copy link
Owner

jcurl commented Nov 1, 2018

This is now in v2.x branch after cleaning up.

@jcurl jcurl closed this Nov 1, 2018
@tedvanderveen
Copy link
Contributor Author

@jcurl can you please publish new Nuget package with this new ISerialPortStream reflected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants