Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how you can mock your <code>FileConnection</code></p> <pre><code>Mock&lt;IFileConnection&gt; fileConnection = new Mock&lt;IFileConnection&gt;( MockBehavior.Strict); fileConnection.Setup(item =&gt; item.Get(It.IsAny&lt;string&gt;,It.IsAny&lt;string&gt;)) .Throws(new IOException()); </code></pre> <p>Then instantiate your Transfer class and use the mock in your method call</p> <pre><code>Transfer transfer = new Transfer(); transfer.GetFile(fileConnection.Object, someRemoteFilename, someLocalFileName); </code></pre> <p><strong>Update:</strong></p> <p>First of all you have to mock your dependencies only, not the class you are testing(Transfer class in this case). Stating those dependencies in your constructor make it easy to see what services your class needs to work. It also makes it possible to replace them with fakes when you are writing your unit tests. At the moment it's impossible to replace those properties with fakes.</p> <p>Since you are setting those properties using another dependency, I would write it like this:</p> <pre><code>public class Transfer { public Transfer(IInternalConfig internalConfig) { source = internalConfig.GetFileConnection("source"); destination = internalConfig.GetFileConnection("destination"); } //you should consider making these private or protected fields public virtual IFileConnection source { get; set; } public virtual IFileConnection destination { get; set; } public virtual void GetFile(IFileConnection connection, string remoteFilename, string localFilename) { connection.Get(remoteFilename, localFilename); } public virtual void PutFile(IFileConnection connection, string localFilename, string remoteFilename) { connection.Get(remoteFilename, localFilename); } public virtual void TransferFiles(string sourceName, string destName) { var tempName = Path.GetTempFileName(); GetFile(source, sourceName, tempName); PutFile(destination, tempName, destName); } } </code></pre> <p>This way you can mock internalConfig and make it return IFileConnection mocks that does what you want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload