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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:01:48+00:00 2026-05-25T21:01:48+00:00

I have a service layer method that recieves an object(Dto) as a parameter. Within

  • 0

I have a service layer method that recieves an object(Dto) as a parameter.

Within that method I new up a business object and i pass the values of the properties of the Dto to the properties of the business object. I then pass the business object as a parameter to a repository method call.

How will my unit test ensure that the business object declared in the service method under test receives the right value into its properties?

  • 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-25T21:01:49+00:00Added an answer on May 25, 2026 at 9:01 pm

    You can mock the repository (I hope that you can inject it into the service layer) and check whether the business object passed into the repository has the expected property values.

    EDIT: An example


    Infrastructure:

    public interface IRepository
    {
       void Add(BusinessObject item);
    }
    
    public sealed class ServiceLayerContext
    {
       private readonly IRepository repository;
    
       public ServiceLayerContext(IRepository repository)
       {
           this.repository = repository;
       }
    
       public void ProcessDto(IDtoObject dto)
       {
           var businessObject = this.CreateBusinessObject(dto);
           this.repository.Add(businessObject);
       }
    
       private BusinessObject CreateBusinessObject(IDtoObject dto)
       {
       }
    }
    

    Test pseudocode (because RhinoMockі not the Moq):

       [Test]
       public void ShouldCreateBusinessOBjectWithPropertiesInitializedByDtoValues()
       {
          // ARRANGE
          // - create mock of the IRepository
          // - create dto
          // - setup expectations for the IRepository.Add() method
          //   to check whether all property values are the same like in dto   
          var repositoryMock = MockRepository.GenerateMock<IRepository>();
          var dto = new Dto() { ... };
          BusinessObject actualBusinessObject = null;
          repositoryMock.Expect(x => x.Add(null)).IgnoreArguments().WhenCalled(
            (mi) => 
            {
                actualBusinessObject = mi[0] as BusinessObject;            
            }).Repeat().Any();
    
          // ACT
          // - create service layer, pass in repository mock
          // - execute svc.ProcessDto(dto)     
          var serviceLayerContext = new ServiceLayerContext(repositoryMock);
          serviceLayerContext.ProcessDto(dto);
    
          // ASSERT
          // - check whether expectations are passed
          Assert.IsNotNull(actualBusinessObject);
          Assert.AreEqual(dto.Id, actualBusinessObject.Id);
          ...
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In your service layer, say you have a method that does XX, is this
I have a service layer that retrieves a DTO from a repository. Depending on
In my service facade layer, I have a service class with a method/operation that
In the service layer I have a classes that look something like: class MyService
I have an application that is structured as an service layer wich uses a
I have a service-layer Interface that extends from a base Interface; I would like
in my service layer public class MyServiceLayerImpl{ public void method1(){ MyServicelayer.method(); //is this correct?
Say you have an ASP.NET MVC project and are using a service layer, such
I have a method that will be used to send out email. i want
I have a WCF service that uses ODP.NET to read data from an Oracle

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.