Scenario:
I'm writing a c#, .NET 4 program to read and parse data
from a computer that is attached to a non computer device
that does have a specialized "computer" for capturing data.
This data can be downloaded through a serial cable
with a program like Windows HyperTerminal.
A "capture" text file is created for later processing.
I've a separate program that parses the downloaded data from
the specialized "computer".
I want to replace the manual downloading with a c# .NET 4
program that automates the downloading of the serial port data.
Since my development environment is not even connected to the target computer, I need to simulate the transfer
of serial data in order to use TDD and xUnit.net to ensure
as best as possible that my program is robust and as
correct as possible before I actually test it in the "real world"
environment.
I'm wondering how I might use Moq (and/or maybe something else)
for the purpose that I've described above.
Note: serial computing has a number of issues,
random data loss is possible in this particular
situation but the most likely issues may be
related to timing and timeouts; example, a human
might be using the related non computer device while the
specialized "computer" is attempting to
respond to requests via its serial port.
Any ideas would be appreciated.
Thank you.
Regards,
Gerry
Are you experienced with using mocks in more mundane situations? Do
you have experience with other mocking frameworks or tools? Have you
used TDD before?
I'm trying to understand whether you are asking about mocking and
testing in general or MOQ in particular.
David Kreth Allen
On Fri, Nov 26, 2010 at 10:43 AM, gerry_lowry [alliston ontario canada
[705] 250-0112] <gerry...@abilitybusinesscomputerservices.com>
wrote:
> --
> Post: moq...@googlegroups.com
> Unsubscribe: moqdisc-u...@googlegroups.com
--
David Kreth Allen
http://codecontracts.info
I've too little experience with Moq, which I've
chosen because the source is available and because
Moq is written in c# and has had great reviews.
Also, the fact that Daniel chose xUnit.net
to unit test Moq was a strong initial factor
in my looking at Moq versus alternatives.
My use of Moq is very limited to date,
mostly with ASP.NET MVC development.
Perhaps I'm over complicating this?
As described below, serial port data flow
appears to me to be a bit more challenging
because of timing issues that are much less
likely in a RESTful ASP.NET MVC environment.
g.
P.S.: I had done quite a bit of research around Moq
but then was not allowed by my employer at
the time to even use xUnit.net or any unit testing
period in their WebForms environment; for
that reason, I'm quite rusty and busy trying
to "get it" with regards to mocking in general
and Moq in particular.
----- Original Message ----- David Kreth Allen http://codecontracts.info <davidkr...@gmail.com>
To: <moq...@googlegroups.com>
Sent: Friday, November 26, 2010 12:04 PM
Subject: Re: [Moq] how does one Moq a serial port?
__________________________________
Gerry Lowry, Partner http://twitter.com/gerryLowry1947
Alliston � Ontario � Canada � L9R 0E1 � 705.250.0112
gerry...@abilitybusinesscomputerservices.com http://abilitybusinesscomputerservices.com
P.S.: more comments below.
-- edited ---- Original Message ----- From: David Allen To: moq...@googlegroups.com
Sent: Friday, November 26, 2010 9:04 PM Subject: Re: [Moq] how does one Moq a serial port?
On Fri, Nov 26, 2010 at 11:26 AM, gerry_lowry [alliston ontario canada [705] 250-0112] wrote:
> Perhaps I'm over complicating this?
We can wish, but I am afraid it is really just complicated <smile>.
[snip]
your situation with the devices poses some special challenges.
{g.} which is why I'm grateful for your answer.
... architecture ... perspective.
a system interface layer which is at the boundary of your system, and
operates the serial port to poll the external device.
{g.} it must both send and listen
{g.} example text commands and sample responses:
{g.} >show time
{g.} 10:21 DEC 1, 2010
{g.} >show transaction summary
{g.} 246/1000 USED
{g.} >show transactions
{g.} stream of data ending with prompt
{g.} line 1 of transaction 1
{g.} line n of transaction 1
{g.}
{g.} line 1 of transaction n
{g.} line n of transaction n
{g.} 246/1000 USED
{g.} >enter privileged mode
{g.} PASSWORD ?:
{g.} et cetera
... some classes you use to read a serial port. ... you will have to mock.
...I took a look at the most likely candidate, the SerialPort class. This poses several challenges:
1) can you mock it?
2) Do you understand how it will behave in the happy path and variant use cases?
{g.} yes, from doing this manually via HyperTerminal two or more times
{g.} per month for a few years;
{g.} nevertheless, I just replaced a Perl script with an almost
{g.} complete c# class and in the process discovered that
{g.} my original Perl script has a serious flaw that I did not
{g.} discover because my sample data was too small to
{g.} reveal an exception case.
... I see two ways around this obstacle:
either buy TypeMock, ...or
you create your own interface ISerialPort
[snip]
The adapter approach is the one I would use because I would not want to buy TypeMock.
Your choice may be different.
{g.} same choice as yours for three reasons:
{g.} (a) really like Moq
{g.} (b) could spend my entire life learning new tools
{g.} and never write a line of code
{g.} (c) money is really tight at the moment
...I pasted a simplified version below.
It's worthwhile for others to have because this is such a common challenge.
{g.} I'm certain others while appreciate your effort also; again, thank you.
[snip]
You will have to get access to the real device for an extended period of time.
{g.} fortunately, this is possible.
... lots of hard choices. ... all of them involve playing with the device ...
I'm sure you were expecting to do this anyway, right?
{g.} yes
... let me know your thoughts.
{g.} definitely, I will once I've sorted them out;
{g.} I need to study your approach; your ideas
{g.} will get me headed in the right direction.
[snip]
Thank you David.