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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:27:44+00:00 2026-05-27T06:27:44+00:00

I have a project in which I am using .nettiers generated code as my

  • 0

I have a project in which I am using .nettiers generated code as my DAL.

At the moment, my tests consist of physically setting up test data in the database for each test, then allowing the nettiers objects to hit the database and return as required.

Obviously, this isn’t particularly efficient and so far my 250 odd tests take about 10 minutes to run, so I’ve been looking into adding mocking into my tests.

While I’m pretty sure I understand the concepts of mocking out the database calls, I’m having trouble applying it to nettiers in particular, since it’s fairly strongly coupled to the database.

One of the methods I want to test looks like this (cut down slightly for brevity’s sake):

public class InterfaceManagerService
{
    public DataDocument SaveDataDocument(DataDocument entity)
    {
        var lookupEntity = DataRepository.DataDocumentProvider.GetByDocumentId(entity.DocumentId);
        if (lookupEntity == null)
        {
            File fileEntity = new File();
            fileEntity.Name = entity.Name;

            var savedFileEntity = DataRepository.FileProvider.Save(fileEntity);

            entity.FileId = savedFileEntity.FileId;

            var savedEntity = DataRepository.DataDocumentProvider.Save(entity);

            return (savedEntity);
        }             
    }
}

Currently, I’m using a trial version of Typemock, since that appears to do what is required, but I’m open to any alternatives, particuarly open source ones.

The first problem I run into it working out if I should be creating a mocked instance of InterfaceManagerService, or of the DataRepository, or the Entities themselves (nettiers entities do have an interface that might be useful).

The second problem is, how to create the fake object that is to be returned, since nettiers puts a bunch of extra properties into the entities that would result in large and unwieldly tests if I create a fake instance of each object I’m expecting.

I guess ultimately, I’m looking for some direction in the best way to write unit tests for methods that use nettiers data repository methods, but to avoid hitting the database, since there doesn’t appear to be much about it on the internet currently.

  • 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-27T06:27:45+00:00Added an answer on May 27, 2026 at 6:27 am

    I’m going to give some suggestions derived from my personal experience. While these may not address all of your concerns, I hope that they will at least be of some help to you.

    • Rhino Mocks is a fairly well-known mocking framework. If you are looking for an alternative to Typemock, I’d suggest that.

    • Regarding whether to mock the InterfaceManagerService or the DataRepository, I’d say that it depends on what you’re trying to test. Do you want to test the InterfaceManagerService? Then you would want to create mock objects for the DataRepository.FileProvider and DataRepository.DataDocumentProvider. If you are not already familiar with the concept of “dependency injection”, then look into that; it looks like you should apply some dependency injection to your InterfaceManagerService class (assuming that you want to unit test it).

      If you want to unit test code that consumes the InterfaceManagerService, then just mock the InterfaceManagerService.

    … how to create the fake object that is to be returned, since nettiers
    puts a bunch of extra properties into the entities that would result
    in large and unwieldly tests if I create a fake instance of each
    object I’m expecting.

    • Writing a single unit test is easy. Writing many unit tests to cover all of the scenarios that you need to cover, and doing so in an efficient manner that does not result in much code being duplicated throughout your unit tests is difficult, especially when the inputs and outputs of the method being tested are complex.

      For this I don’t have much guidance, other than to say that my personal approach is to try to consolidate test initialization logic and test verification logic in order to avoid a lot of code duplication, but at the same time I try to avoid making the unit testing code itself so complicated that it becomes difficult to understand and prone to bugs.

      In general, I think that I end up dividing test logic into 3 categories: inputs/initialization, expectations, and results/verification. I’ve found that putting the logic into these 3 categories was helpful for me in being able to consolidate the common code across unit tests.

      Die-hard test-driven development proponents would likely say that struggling to produce a clean set of unit testing code is an indication of a design flaw in the application. I’m not going to disagree with that, but I will say that, unfortunately, the projects that I’ve been involved with have not generally produced a unit testing code base that was both simple and thoroughly comprehensive. The simple unit tests generally didn’t really explore problematic scenarios, and the comprehensive unit tests generally required a lot of test setup logic.

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

Sidebar

Related Questions

I have a Silverlight Project which passes data using the Data Contract to a
I have a project which is source controlled using Subversion and VisualSVN. Since the
I have a MS Project file which I am using the Primary Interop Assemblies
I have just restarted a project in which I am using NHibernate. The project
I have a rather large (freeware) project written with Delphi 2007 which is using
I have a .net 1.1 project in VS.Net 2003 (using C#) in which I
I have a project which is using DocumentFormat.OpenXml.dll 2.0.3920.0. However, I want this to
I have a C++ project which is using boost. The whole project is built
I have a project which needs to generate PDF documents. I am using iTextSharp.
Using Visual Studio 2010 C++. I have a project which uses MFC and I

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.