Hi,
let's take the following method which saves a MemoryStream to a file:
public void Write(MemoryStream stream, string fileName)
{
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
stream.WriteTo(fs);
}
}
I would like to write a unit test that ensures that the the FileStream instance in this method was created with the particular constructor (string path, FileMode mode) and that correct parameters were passed to it (the value of fileName and FileMode.Create in this case). At the same time, I'd like that the FileStream instance created in this method does nothing, i.e. that nothing is saved to the file system upon calling this method in a unit test. So essentially, I would need to mock the FileStream object so that it a) does nothing and b) I can check whether the particular constructor was called with particular parameters.
Any way to achieve this using JustMock (commercial edition)?
Thanks, Robert
let's take the following method which saves a MemoryStream to a file:
public void Write(MemoryStream stream, string fileName)
{
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
stream.WriteTo(fs);
}
}
I would like to write a unit test that ensures that the the FileStream instance in this method was created with the particular constructor (string path, FileMode mode) and that correct parameters were passed to it (the value of fileName and FileMode.Create in this case). At the same time, I'd like that the FileStream instance created in this method does nothing, i.e. that nothing is saved to the file system upon calling this method in a unit test. So essentially, I would need to mock the FileStream object so that it a) does nothing and b) I can check whether the particular constructor was called with particular parameters.
Any way to achieve this using JustMock (commercial edition)?
Thanks, Robert