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

  • Home
  • SEARCH
  • 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 8941359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:16:51+00:00 2026-06-15T11:16:51+00:00

I’ve completed my implementation of my first OpenRasta RESTful webservice and have successfully got

  • 0

I’ve completed my implementation of my first OpenRasta RESTful webservice and have successfully got the GET requests I wish for working.

Therefore I’ve taken some ‘inspiration’ from Daniel Irvine with his post http://danielirvine.com/blog/2011/06/08/testing-restful-services-with-openrasta/ to built a automated test project to test the implmentation.

I’ve created my own test class but I’m constantly getting a 404 error as the reponse status code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRasta.Hosting.InMemory;
using PoppyService;
using OpenRasta.Web;
using System.IO;
using System.Runtime.Serialization.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;

namespace PoppyServiceTests
{
//http://danielirvine.com/blog/2011/06/08/testing-restful-services-with-openrasta/
[TestFixture]
class OpenRastaJSONTestMehods
{
    [TestCase("http://localhost/PoppyService/users")]
    public static void GET(string uri)
    {
        const string PoppyLocalHost = "http://localhost/PoppyService/";
        if (uri.Contains(PoppyLocalHost))
            GET(new Uri(uri));
        else
            throw new UriFormatException(string.Format("The uri doesn't contain {0}", PoppyLocalHost));
    }
    [Test]
    public static void GET(Uri serviceuri)
    {
        using (var host = new InMemoryHost(new Configuration()))
        {
            var request = new InMemoryRequest()
            {
                Uri = serviceuri,
                HttpMethod = "GET"
            };

            // set up your code formats - I'm using  
            // JSON because it's awesome  
            request.Entity.ContentType = MediaType.Json;
            request.Entity.Headers["Accept"] = "application/json";

            // send the request and save the resulting response  
            var response = host.ProcessRequest(request);
            int statusCode = response.StatusCode;

            NUnit.Framework.Assert.AreEqual(200, statusCode, string.Format("Http StatusCode Error: {0}", statusCode));

            // deserialize the content from the response  
            object returnedObject;
            if (response.Entity.ContentLength > 0)
            {
                // you must rewind the stream, as OpenRasta    
                // won't do this for you    
                response.Entity.Stream.Seek(0, SeekOrigin.Begin);
                var serializer = new DataContractJsonSerializer(typeof(object));
                returnedObject = serializer.ReadObject(response.Entity.Stream);
            }
        }
    }
}

}

If I navigate to the Uri manually in the browser I’m getting the correct responce and HTTP 200.

It’s possibly something to do with my Configuration class, but if I test all the Uris manaully again I get the correct result.

public class Configuration : IConfigurationSource
{
    public void Configure()
    {
        using (OpenRastaConfiguration.Manual)
        {                
            ResourceSpace.Has.ResourcesOfType<TestPageResource>()
                .AtUri("/testpage").HandledBy<TestPageHandler>().RenderedByAspx("~/Views/DummyView.aspx");

            ResourceSpace.Has.ResourcesOfType<IList<AppUser>>()
                .AtUri("/users").And
                .AtUri("/user/{appuserid}").HandledBy<UserHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<AuthenticationResult>()
                .AtUri("/user").HandledBy<UserHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<Client>>()
                .AtUri("/clients").And
                .AtUri("/client/{clientid}").HandledBy<ClientsHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<Agency>>()
                .AtUri("/agencies").And
                .AtUri("/agency/{agencyid}").HandledBy<AgencyHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<ClientApps>>()
                .AtUri("/clientapps/{appid}").HandledBy<ClientAppsHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<Client>()
                .AtUri("/agencyclients").And
                .AtUri("/agencyclients/{agencyid}").HandledBy<AgencyClientsHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<Client>()
                .AtUri("/agencyplususerclients/{appuserid}").HandledBy<AgencyPlusUserClientsHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<Permission>>()
                .AtUri("/permissions/{appuserid}/{appid}").HandledBy<PermissionsHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<Role>>()
                .AtUri("/roles").And
                .AtUri("/roles/{appuserid}").And.AtUri("/roles/{appuserid}/{appid}").HandledBy<RolesHandler>().AsJsonDataContract();

            ResourceSpace.Has.ResourcesOfType<IList<AppVersion>>()
                .AtUri("/userappversion").And
                .AtUri("/userappversion/{appuserid}").HandledBy<UserAppVersionHandler>().AsJsonDataContract();
        }
    }
}

Any suggestions would be greatfully received.

  • 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-06-15T11:16:52+00:00Added an answer on June 15, 2026 at 11:16 am

    I’ve solved it with the help from Nate Taylor (http://taylonr.com/integration-testing-openrasta), who has implemented a similar test method for POST. I was including the solution name ‘PoppyService’ in the Uri which is the Uri for the project hosted on IIS. I mistakenly assumed the configuration would create this Uri for InMemoryHost as well but it routes straight to localhost. Removing this has made the Assert test be successful.

    [TestCase("http://localhost/users")]
        public static void GET(string uri)
        {
            const string LocalHost = "http://localhost/";
            if (uri.Contains(LocalHost))
                GET(new Uri(uri));
            else
                throw new UriFormatException(string.Format("The uri doesn't contain {0}", LocalHost));
        }
    

    The post is also a good find because I need to implement a test method for POST too. Hope this helps others too, as Daniel didn’t specifically explain what he meant by MyResource. Is obvious to me now.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.