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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:49:15+00:00 2026-05-25T01:49:15+00:00

I am currently implementing SiteMinder for the site, which looks for a key called

  • 0

I am currently implementing SiteMinder for the site, which looks for a key called SM_USER in the request header. I retrieve it using the function below:

 public string ReadUser()
 {
    return HttpContext.Current.Request.Headers["SM_USER"];
 }

I wish to test if functionality releated to this function work; I have already tried unit testing using a mock class so I am looking to create the key SM_USER in the request header. How can I do that?

I am implementing the application with MVC3.

  • 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-25T01:49:16+00:00Added an answer on May 25, 2026 at 1:49 am

    As long as you are using HttpContext.Current you will not be able to test it as Unit Test will not have HttpContext.Current.

    Try to use an Interface with method returning string, say ReadUser(). Implement this interface in a class in your application. Use the interface variable whichever class you are using this method in. In that class’ default constructor set that interface variable value to ‘new’ implementer class. Add an overload of the constructor which will take a parameter of type interface and set that parameter to interface variable.

    Now in your UnitTest project implement same interface in another class. In this implementation you can now pass whatever mock value you want test.

    public interface IReadUserInfo
    {  string ReadUser();     }
    
    public class ReadUserInfo: IReadUserInfo
    {
        public string ReadUser()
        {
           return HttpContext.Current.Request.Headers["SM_USER"];
        }
    }
    
    
    public class UserClass
    {
        IReadUserInfo userinfo;
    
        public UserClass()
        {
            userinfo = new ReadUserInfo();
        }
    
        public USerClass(IReadUserInfo newuserinfo)
        {
            userinfo = newuserinfo;
        }
    }
    
    public class TestReadUserInfo : IReadUSerInfo
    {
         public string ReadUser()
         { return "testvalue";  }
    }
    

    If ReadUser is the only value you are using from Request header, then this approach will solve the problem. However, if you using more values from Request object, you might want to mock entire request object in similar way.

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

Sidebar

Related Questions

I am currently implementing a blog-like site using Ruby on Rails. Each Post has
I'm currently implementing a .NET wrapper for a Java library by using JNI to
I'm currently implementing a histogram that will show a very large scale data using
I am currently implementing S3 integration into my Rais application which uses Paperclip. Currently,
I am currently implementing something similar to an hospital intra site, where doctors can
I'm currently implementing a software keyboard ( using some sophisticated prediction ), and drawing
I am currently implementing a timer/callback system using Don Clugston's fastdelegates. (see http://www.codeproject.com/KB/cpp/FastDelegate.aspx )
I'm currently implementing Interceptors using Castle DynamicProxy. I require the interceptor to pick up
I'm trying to create a file explorer using nscollectionview and am currently implementing a
I'm currently implementing a script engine in a game I wrote using the C#

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.