Creating a test mode through the url parameter, which inserts values ​​into the form

Since I'm fairly new to web application development, I am currently having difficulty implementing some of the testing features.

As part of the project that I am currently working on (MVC 3 application for processing payments), I was asked to create a test mode, which can be accessed through the URL in this way:

http://websiteurl?testmode=1

The idea is that when one of the developers adds the testmode parameter to the URL, a set of form values ​​is automatically generated to save time on entering data every time the application is validated.

I currently have an if statement in the controller that uses Request.QueryString to set the parameter below - this is the code I'm currently using:

if (Request.QueryString.AllKey.Contains("tm"))
{
     if (Request.QueryString["tm"] == 1)
     {
         insert values to be generated
     }
}

, , ?

, ​​ Moq RhinoMocks, , , ?

+5
2

"TestMode".

:

// I would consider retrieving this from web.config
protected string testModeKey = "tm";

public bool IsTestContext
{
   get
   {
      return Request.QueryString[testModeKey] != null;
   }
}

HttpRequest:

public static bool IsTestContext(this HttpRequest request, string testModeKey = "tm")
{
   request.QueryString[testModeKey] != null;
}

. , . , .

, IDataRepository, : FakeDataRepository ReadDataRepository.

factory ifelse, , .

IDataRepository DataRepository { get; set; }

if (Request.IsTestContext)
   DataRepository = new FakeDataRepository();
else
   DataRepository = new RealDataRepository();

, , , , . . , , ?

+2

, , :

silk, -, , , , , , Microsoft.Practices.ServiceLocation.

, Business Logic Domain, , , (SagePay), SagePayMvc.dll.

. , , , . , , JQuery.

, -, , -.

, , .

Entity Framework Code First, , .

- ( , , ), , , , , , .

Test Class, , Student , , , , Moq.

0
source

All Articles