Showing posts from February, 2016

A Red Herring When Using Moq to Mock Methods With Optional Parameters

I recently spent some time writing unit tests for some code that required me to mock an object that has a method with optional properties. I used the Moq framework, and when I set up the method in question, I defaulted the optional parameters. This was required, as leaving them out of the Setup() call was not allowed.

Also as part of my set up of this method, I instructed Moq to return the first parameter as the return value. I've had plenty of experience with Moq and setting up return values for mocked methods, but it didn't prepare me for the mistake I had unknowingly made. Here's how I set the method up originally:

_repoMock.Setup(x =>  x.Save(It.IsAny<Click>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))    .Returns((Click click) => click); When I ran my unit test, the method above resulted in a "Parameter count mismatch" exception. I checked and double-checked my arguments, and went about trying to resolve the issu…

How to Add a Reference to System.ServiceModel (WCF) to an ASP.NET 5 Application

I ran into a situation yesterday wherein I needed to add a reference to System.ServiceModel to an application using DNX RC1 Final Update 1 (if it's "final", why is there an update? I digress...).

To do this, I had to add a frameworkAssemblies property to the JSON object for dnx451 declared under frameworks in my project.json file, and then add the System.ServiceModel reference there, as shown below:

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "CMS.Services.Contracts": "1.0.0-*",
        "CSharpSDK": "1.0.0-*"
      "frameworkAssemblies": {
        "System.ServiceModel": ""