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 6838739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:38:00+00:00 2026-05-26T23:38:00+00:00

I’ve created the start of a REST solution here which I coded first, because

  • 0

I’ve created the start of a REST solution here which I coded first, because I’m having issues getting my head around testing the REST service. This is my first stab at a rest service so apologies if anything is gravely offensive.

In a nutshell I have a concrete class handling the service work:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ESIID : BaseREST<ESI>
{

    [OperationContract]
    [WebGet(UriTemplate = "/{guid}/{id}", ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped)]
    public Message LookupESIID(string guid, string id)
    {
        ResponseType = ResponseTypes.Json;
        return GetById(guid, id);
    }

    private Message GetById(string guid, string id)
    {
        bllSvc = new Business.Services.TXESIIDRepository(guid);
        var results = bllSvc.ByID(id);

        return results.Count == 0 ? NoResults() : FormatResponse(results);
    }

}

which inherits from a base (some methods included for context):

public abstract class BaseREST<T>
{
    protected ResponseTypes ResponseType { get; set; }

    public Message ReturnJson(string json)
    {
        var webContext = WebOperationContext.Current;
        webContext.StatusCode = HttpStatusCode.OK;

        return webContext.CreateJsonResponse(json);
    }

    public Message FormatResponse(List<T> results)
    {
        switch (ResponseType)
        {
            case ResponseTypes.Json:
                return ReturnJson(JsonConvert.SerializeObject(results));
                break;
            case ResponseTypes.Xml:
                return ReturnXml(results);
                break;
             default:
                return ReturnErrorJson(new Error{ErrorDescription = "Format error", ErrorDetail = "Requested format is not valid", StatusCode = HttpStatusCode.BadRequest});
        }
    }

    public Message NoResults()
    {
        var err = new Error
        {
            ErrorDescription = ConfigurationManager.AppSettings["NotFound_Descr"]
            , ErrorDetail = ConfigurationManager.AppSettings["NotFound_Detail"]
            , StatusCode = HttpStatusCode.BadRequest 
        };

        return ReturnError(err);   
    }
}

I’m at a loss for how to properly test the implementation and the base class. Is it possible (and frankly good) to create some type of mocked HTTP client in the test setup which would then set the URI? I can’t think of how to make these classes flexible for unit AND integration tests.

Thanks for any direction on this.

  • 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-26T23:38:00+00:00Added an answer on May 26, 2026 at 11:38 pm

    To be honest, I’m no expert on this – but in a similar situation I have passed an interface into the constructor for the base class that handles the pesky WebOperationContext functions, eg:

    public interface IWebOperationContextWrapper
    {
        HttpStatusCode OutgoingStatusCode { get; set; }
        string OutgoingStatusDescription { get; set; }
    }
    

    The actual WCF service endpoint being a tiny function that instantiates a concrete instance with a real WOContect, which is passed to the function that actually does the work, eg:

        //wcf endpoint
        public SomeResponseDto SomeWebMethod(string id)
        {            
            WebOperationContextWrapper webOperationContext = new WebOperationContextWrapper();
            return ThisIsATestableFunctionThatCanBePassedAFakeContext(Id, webOperationContext);
        }
    

    If I want to test the function the endpoint calls I now can:

    IWebOperationContextWrapper webOperationContext = MockRepository.GenerateStub<IWebOperationContextWrapper>();
    
            var result = svc.ThisIsATestableFunctionThatCanBePassedAFakeContext(Id, webOperationContext);
    
            Assert.IsWhatever(result);
    

    I don’t actually test the WCF service, because all the WCF service does is execute functions in a de-coupled class. I test that class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.