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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:41:53+00:00 2026-06-12T10:41:53+00:00

I’m a bit lost as to how unit tests could tie in to my

  • 0

I’m a bit lost as to how unit tests could tie in to my current project’s design. My current tests are all integration tests which end up pretty much just testing the third party ORM. I was thinking I needed to use the Repository pattern but its not clear to me how exactly how to add that as a layer in my application. Here is a basic object I am working with for an example:

public class Venue : ModelBase<Venue>
{
    public Venue ()
        : base()
    {
    }

    public virtual string VenueName { get; set; }
}

And its actions:

    [HttpGet]
    public ActionResult Create ()
    {
        return View();
    }

    public ActionResult Create ([ModelBinder(typeof(VenueBinder))]Venue Venue)
    {
        Venue.Save();
        return RedirectToAction("List", "Venue");
    }

    [HttpGet]
    public ActionResult Edit (long id) 
    {
        return View(Venue.Load(id));    
    }

    [HttpPost]
    public ActionResult Edit ([ModelBinder(typeof(VenueBinder))]Venue v, long id)
    {
        VenueBinder.EditModel(v, id);
        return RedirectToAction("List", "Venue");
    }

    public ActionResult Delete (long id)
    {
        Venue temp = Venue.Load(id);
        var eventController = new EventController();
        foreach (var e in Event.All().ToList().FindAll(x => x.Venue.ID == id))
        {
            eventController.Delete(e.ID);
        }
        temp.Delete();
        return RedirectToAction("List", "Venue");

    }       

and model binder:

public class VenueBinder : IModelBinder
{
    /// <summary>
    /// bind form data to Venue model
    /// </summary>
    public object BindModel (ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        return new Venue
        {
            VenueName = bindingContext.ValueProvider.GetValue("name").AttemptedValue
        };
    }

    /// <summary>
    /// edits an existing Venue object
    /// </summary>
    public static void EditModel (Venue v, long id)
    {
        Venue temp = Venue.Load(id);
        temp.VenueName = v.VenueName;
        temp.Save();
    }
}
  • 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-12T10:41:54+00:00Added an answer on June 12, 2026 at 10:41 am

    If you want to unit test your controller actions in isolation you will have to abstract the CRUD operations that could be performed on your model behind an interface that the controller will take as a constructor dependency. Inside the unit test you could provide a mocked instance of this interface to the controller and be able to define expectations on it.

    This being said, too many abstractions are not always a good thing and you shouldn’t do it just for the sake of unit testing. If they don’t bring some other value to your site such as have for example a reusable repository layer in other applications you probably shouldn’t be doing it. Integration tests are also fine. You just need to ensure that you are doing it on a data that is in a predictable state for each test, ideally populated before each test and torn down after it. Hopefully your ORM supports this. Jimmy Bogard wrote a nice blog post on the subject of limiting your abstractions.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms

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.