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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:01:56+00:00 2026-05-13T10:01:56+00:00

We have a requirement to add an event reminder when a user enters their

  • 0

We have a requirement to add an event reminder when a user enters their email address on an event page. Event is another domain object. Our initial thought was to create a Customer domain object and related CustomerService:

public class CustomerService {
    public void AddEventReminder(string emailAddress, int eventId) {
       var customer = new Customer(emailAddress);
       customer.AddEmailReminder(eventId);
    }
}

How can we verify in a unit test that the AddEmailReminder method was indeed called on the new customer?

My thoughts:

  1. Use a factory to create the customer. This smells because I thought you were only supposed to use factory where there was some complexity in the object creation.
  2. Bad code. Maybe there is a better way to do this?
  3. Moq magic.

On a separate note (maybe it is related), how do we decide which is the aggregate root here? We have arbitrarily decided the customer is, but it could equally be the event. I have read and understand articles on aggregate roots, but it is unclear in this scenario.

  • 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-13T10:01:56+00:00Added an answer on May 13, 2026 at 10:01 am

    In cases like this I would create a protected method in the service that creates the customer, in the test override that method it with anonymous inner class, and make it return a mock Customer object. Then you can verify on the mock Customer object that AddEmailReminder was called.
    Something like:

    public class CustomerService {
        public void AddEventReminder(string emailAddress, int eventId) {
           var customer = createCustomer(emailAddress);
           customer.AddEmailReminder(eventId);
        }
    
        protected Customer createCustomer(string emailAddress) {
           return new Customer(emailAddress);
        }
    }
    

    and in the test (assume limited C# knowledge, but it should illustrate the point):

    void testCustomerCreation() {
        /* final? */ Customer mockCustomer = new Customer("email");
        CustomerService customerService = new CustomerService() {
           protected Customer createCustomer(string emailAddress) {
               return mockCustomer;
           }            
        };
    
        customerService.AddEventReminder("email", 14);
    
        assertEquals(mockCustomer.EventReminder() /* ? */, 14);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to add a standard drop-down from which you can select
Can i add two header text in Datagrid? My Requirement is to have two
I have requirement to get Facebook friends list with their images. How can I
I'm working in Drupal 6. I have a requirement to add a particular block
I have a requirement to programmatically add a file along with metadata to a
I'm working with Windows Azure Table Storage and have a simple requirement: add a
I have a requirement to add a RequiredFieldValidator and RegularExpressionValidator to a dynamically created
Using Microsoft Sql 2000 I have a requirement to be able to email a
I have a requirement to add the data in a grid panel on a
I have requirement where some times I would like to load children as well

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.