Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:31:34+00:00 2026-05-26T21:31:34+00:00

What would be the best way to create unit tests for testing the parameters

  • 0

What would be the best way to create unit tests for testing the parameters I send to my WCF service?

I have a project where I have a repository class that speaks to my WCF service. It looks something like this:

public class MyRepository : IMyRepository
{
    public Customer GetCustomer(int customerId)
    {
        var client = new MyWCFServiceClient();
        MyWCFServiceCustomer customerWCF = client.GetCustomer(customerId);
        Customer customer = ConvertCustomer(customerWCF);
        return customer;
    }

    //Convert a customer object recieved from the WCF service to a customer of
    //the type used in this project.
    private Customer ConvertCustomer(MyWCFServiceCustomer customerWCF)
    {
        Customer customer = new Customer();
        customer.Id = customerWCF.Id;
        customer.Name = customerWCF.Name;
        return customer;
    }
}

(This is obviously simplified)

Now I would like to write unit tests to check that the parameters I send to my service from the repository is correct. In the example above it would be kind of pointless since I only send the customerId just as it is passed in, but in my real code there are more parameters and some more logic in the repository class.

The problem is that the generated service client class (MyWCFServiceClient) doesn’t have an interface and so I can’t mock it in my tests (or am I wrong about that?).

Edit: I was wrong about this. There is an interface! See my answer below.

One solution would be to have a class that wraps the service client and that only re-sends the parameters and returns the result:

public class ClientProxy : IClientProxy
{
    public MyWCFServiceCustomer GetCustomer(int customerId)
    {
        var client = new MyWCFServiceClient();
        return client.GetCustomer(customerId);
    }
}
public interface IClientProxy
{
    MyWCFServiceCustomer GetCustomer(int customerId);
}

That way I could give that class an interface and thus mock it. But it seems tedious to write that “proxy” class and keep it updated, so I was hoping you have a better solution! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:31:35+00:00Added an answer on May 26, 2026 at 9:31 pm

    My bad… there actually is an interface to the generated service class. I found it when looking some more. It just didn’t have the name I expected it to have (in my example, if the client was called MyWCFServiceClient I expected the interface to be called IMyWCFServiceClient, but it was actually called IMyWCFService).

    So I could just rewrite my controller to inject the service client and thus make it mockable:

    public class MyRepository : IMyRepository
    {
        private readonly IMyWCFService _serviceClient;
    
        //Constructor
        public MyRepository(IMyWCFService serviceClient)
        {
            _serviceClient = serviceClient;
        }
    
        public Customer GetCustomer(int customerId)
        {
            MyWCFServiceCustomer customerWCF = _serviceClient.GetCustomer(customerId);
            Customer customer = ConvertCustomer(customerWCF);
            return customer;
        }
    
        //Convert a customer object recieved from the WCF service to a customer of
        //the type used in this project.
        private Customer ConvertCustomer(MyWCFServiceCustomer customerWCF)
        {
            Customer customer = new Customer();
            customer.Id = customerWCF.Id;
            customer.Name = customerWCF.Name;
            return customer;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the best way to create a JS chat client with GWT?
What would be the best way to create a circularly linked list in C#.
In Java, what would the best way be to have a constantly listening port
What would be the best way to have a list of items with a
what would be the best way to create long static urls in asp.net MVC?
I was wondering what would be the best way to create LINQ-to-SQL classes to
What would be the best way to create fluid layout, which would fill the
I am curious about what would be the best way to create a 3-tier
What is the best practice way to do unit testing with Spring? I assume
I have a component that uses log4net. I want to create unit tests, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.