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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:33:42+00:00 2026-05-11T12:33:42+00:00

In a new MVC application, I am building out all of the models, controllers,

  • 0

In a new MVC application, I am building out all of the models, controllers, views etc. without my backend DB setup yet. I have an idea of what the backed will look like, but for now I’m focusing on the application.

I know that I can mock up a dummy model within the controller like:

public ActionResult Pictures() {     MyMVCApp.Models.Pictures pics = null;     MyMVCApp.Classes.Picture pic1 = new MyMVCApp.Classes.Picture     {         AlbumID=1,         Description='John Doh',         ThumbnailLocation = 'Photos/Thumbnails/John.jpg'     };     MyMVCApp.Classes.Picture pic2 = new MyMVCApp.Classes.Picture     {         AlbumID = 2,         Description = 'Jane Doh',         ThumbnailLocation = 'Photos/Thumbnails/Jane.jpg'     };     pics = new Pictures     {         PageTitle='PHOTO ALBUMS',         PhotoAlbums = new List<MyMVCApp.Classes.PhotoAlbum>()     };     pics.PhotoAlbums.Add(new MyMVCApp.Classes.PhotoAlbum     {         AlbumID = 1,         AlbumName = 'Test1',         AlbumCover = pic1,         Created = DateTime.Now.AddDays(-15)     });      pics.PhotoAlbums.Add(new MyMVCApp.Classes.PhotoAlbum     {         AlbumID = 2,         AlbumName = 'Test2',         AlbumCover = pic2,         Created = DateTime.Now.AddDays(-11).AddHours(12)     });     return View(pics); } 

Doing this at least gives me something to look at on the view. My concern is when I’m ready to actually use the DB for my model, I don’t want to lose my test Model.

How should I separate this out so that I don’t have to change the View each time between the real controller and the test controller?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T12:33:42+00:00Added an answer on May 11, 2026 at 12:33 pm

    You might consider not setting up those data classes within your controller. Instead request them from a InMemoryPictureRepository that will return the instances to you as you need them for testing.

    In other words, put the responsiblity of data persistence behind an IRepository interface. That way you can have versions that are used for test that basically deliver hard-coded instances.

    Ultimately, I think you really want to use dependency injection with an IoC container and not have the Repository referenced directly in your controller, but a drastically oversimplified look might be like this:

    public class PictureController : Controller {     IPictureRepository _pictureRepository;      public PictureController()      {         //Assume you change this for test/prod. Again you'd probably           //want to inject this if you really want testable controllers         IPictureRepository _pictureRepository = new InMemoryPictureRepository();      }       public ActionResult Pictures()      {          List<Picture> pics  = _pictureService.GetAllPictures();          return View(pics);      } } 

    Now you can have this InMemoryPictureRepository

    public class InMemoryPictureRepository : IPictureRepository {     public List<Picture> GetAllPictures()     {         //All your hard-coded stuff to return dummy data;     } } 

    And this for your live stuff:

    public class PictureRepository : IPictureRepository {     public List<Picture> GetAllPictures()     {        //Code to get data from L2S or wherever. This returns real stuff     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I am new to Spring MVC . I have a web application. I have
I have a new solution that is an ASP.NET MVC 2.0 application. I have
I have an application (ASP.NET MVC) that uses a Next New method to get
I'm building an Asp.net MVC 2 application. I have an entity called Team that
I have a MVC Sencha Touch application I'm building and am having some issues
I'm building an ASP .NET MVC 4 application. Now, when I deploy a new
I am building an MVC 3 application with an IIS 7.5 backend. On my
I have been building ASP.NET MVC application and I'm worried about potential multi-threading issues
I have recently joined a new developing project building a thick client application using

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.