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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:39:03+00:00 2026-05-21T05:39:03+00:00

Okay, I have a business logic class like this: Note: For context, Vendor Briefs

  • 0

Okay, I have a business logic class like this:

Note: For context, Vendor Briefs are simple entities that describe a “download” for a PDF document.

/// <summary>
/// Houses business level functions for dealing with vendor briefs.
/// </summary>
public class VendorBriefController : IVendorBriefController
{
    /// <summary>
    /// Vendor brief controller requires an instance of IVendorBriefRepository.
    /// </summary>
    IVendorBriefRepository _vendorBriefRepository;

    /// <summary>
    /// Initializes an instance of VendorBriefController.
    /// </summary>
    public VendorBriefController(IVendorBriefRepository vendorBriefRepository)
    {
        _vendorBriefRepository = vendorBriefRepository;
    }

    /// <summary>
    /// Get a list of string filters for vendor briefs.
    /// </summary>
    /// <returns>A list of string filters.</returns>
    public dynamic GetFilters()
    {
        List<string> filters = new List<string>
        {
            "All",
            "Active",
            "Inactive"
        };
        return filters;
    }

    /// <summary>
    /// Retrieve vendor brief entity from the repository by its unique ID.
    /// </summary>
    /// <param name="Id">The unique ID of the vendor brief.</param>
    /// <returns>A vendor brief entity.</returns>
    public VendorBrief GetVendorBriefForEditing(int Id)
    {
        var vendorBrief = _vendorBriefRepository.GetVendorBrief(Id);
        return vendorBrief;
    }

    /// <summary>
    /// Get a dynamic list of vendor briefs from the repository based on the supplied filter.
    /// </summary>
    /// <param name="filter">The filter to be used when retrieving vendor briefs.</param>
    /// <returns>A dynamic sorted & filtered list of vendor briefs to be displayed in a grid view.</returns>
    public dynamic GetVendorBriefList(string filter)
    {
        IEnumerable<VendorBrief> results = _vendorBriefRepository.GetVendorBriefs();
        switch (filter)
        {
            default:
                results = _vendorBriefRepository.GetVendorBriefs();
                break;
            case "Active":
                results = _vendorBriefRepository.GetVendorBriefs(true);
                break;
            case "Inactive":
                results = _vendorBriefRepository.GetVendorBriefs(false);
                break;
        }
        return from x in results
               orderby x.DisplayOrder
               select new
               {
                   ID = x.VendorBriefID,
                   Title = x.Title,
                   Active = x.IsActive,
                   DisplayOrder = x.DisplayOrder
               };
    }

    /// <summary>
    /// Save changes to the underlying repository in order to persist changes made to self-tracking vendor brief entities.
    /// </summary>
    /// <param name="vendorBrief"></param>
    public void EditVendorBrief(VendorBrief vendorBrief)
    {
        _vendorBriefRepository.SaveChanges();
    }

    /// <summary>
    /// Remove a vendor brief from the underlying repository.
    /// </summary>
    /// <param name="vendorBrief">The vendor brief to be removed.</param>
    public void DeleteVendorBrief(VendorBrief vendorBrief)
    {
        _vendorBriefRepository.DeleteVendorBrief(vendorBrief);
        _vendorBriefRepository.SaveChanges();
    }

    /// <summary>
    /// Add a vendor brief to the underlying repository.
    /// </summary>
    /// <param name="vendorBrief">The vendor brief to be added.</param>
    public void AddVendorBrief(VendorBrief vendorBrief)
    {
        _vendorBriefRepository.AddVendorBrief(vendorBrief);
        _vendorBriefRepository.SaveChanges();
    }
}

I am taking my first steps into unit testing and I’m learning about Moq. I don’t want a whole unit test class written for this (unless you feel like it of course :P) but a simple sample will do. I’m assuming I need to “mock” IVendorBriefRepository so that I can pass it into the constructor when building my controller (not to be confused with mvc controllers), but I’m not sure how to do it. A sample using some of my own code will really help me get started.

Thanks in advance!

  • 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-21T05:39:04+00:00Added an answer on May 21, 2026 at 5:39 am

    Something like this would test DeleteVendorBrief, for example.

    Mock<IVendorBriefRepository> mock = new Mock<IVendorBriefRepository>();
    
    VendorBriefController controller = new VendorBriefController(mock.Object);
    
    VendorBrief brief = new VendorBrief();
    
    controller.DeleteVendorBrief(brief);
    
    mock.Verify(f=>f.DeleteVendorBrief(brief));
    mock.Verify(f=>f.SaveChanges());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so we have a utility here in-house that generates business-model classes from our
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay, I have this program and I don't want more than one instance of
Okay, this is just a crazy idea I have. Stack Overflow looks very structured
Okay this is a real headscratcher. I have an application which calls a web
Okay, I have done a bit of searching online and found this thread, but
Okay so I have two import pieces of code involved in this. This first
Okay so I have defined my DSNavigationManager class and it has a property called
Okay. I have this code on my site: <?php session_start(); include database.php; include bruger.php;
I have built a console application that works okay when it references a .exe

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.