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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:53:33+00:00 2026-05-27T10:53:33+00:00

The basic issue is how to test a presenter. Take: Domain object (will eventually

  • 0

The basic issue is how to test a presenter.

Take:
Domain object (will eventually be persisted to DB)
Base attributes are Id (DB ID, Int/GUID/Whatever) and TransientID (Local ID until saved, GUID)

DomainObject


namespace domain {  
  public class DomainObject {    
   private int _id;    
   private Guid transientId;    
   public DomainObject()
   {      
    _transient_Id = Guid.NewGuid();    
   }
  }
}

PresenterTest:


var repository = Mock.StrictMock();
var view = Mock.StrictMock();

view.Save += null;
var saveEvent = LastCall.Ignore().GetEventRaiser();

var domainObject = new DomainObject() {Id = 0, Attribute = "Blah"};

Mock.ExpectCall(Repository.Save(domainObject)).Returns(True);
Mock.ReplayAll();

var sut = new Presenter(repository, view);
Save_Event.raise(view, EventArgs.Empty);

Mock.Verify()

So the problem here is that the domain object identity is calculated with ID and failing that it’s calculated with transientID, there’s no way to know what the transientID will be so I can’t have the mock repository check for equality.

The workarounds so far are:

1) LastCall.Ignore and content myself with jsut testing that the method got called but not test the content of the call.

2) Write a DTO to test against and save to a service. The service than handles the mapping to domain.

3) Write a fake testRepository that uses custom logic to determine success.

–1 doesn’t test the majority of the logic. –2 is a lot of extra code for no good purpose –3 Seems potentially brittle.

Right now I’m leaning towards DTO’s and a service in the theory that it gives the greatest isolation between tiers but is probably 75% unnecessary…

  • 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-27T10:53:34+00:00Added an answer on May 27, 2026 at 10:53 am

    there’s no way to know what the transientID will be so I can’t have the mock repository check for equality.

    Actually, I think there is an opportunity here.

    Instead of calling Guid.NewGuid(), you could create your own GuidFactory class that generates GUIDs. By default, it would use Guid.NewGuid() internally, but you could take control of it for tests.

    public static class GuidFactory
    {
        static Func<Guid> _strategy = () => Guid.NewGuid();
    
        public static Guid Build()
        {
            return _strategy();
        }
    
        public static void SetStrategy(Func<Guid> strategy)
        {
            _strategy = strategy;
        }
    }
    

    In your constructor, you replace Guid.NewGuid() with GuidFactory.Build().

    In your test setup, you override the strategy to suit your needs — return a known Guid that you can use elsewhere in your tests or just output the default result to a field.

    For example:

    public class PseudoTest
    {
        IList<Guid> GeneratedGuids = new List<Guid>();
    
        public void SetUpTest()
        {
            GuidFactory.SetStrategy(() => 
            {
                var result = Guid.NewGuid();
                GeneratedGuids.Add(result);
                return result;
            });
        }
    
        public void Test()
        {
            systemUnderTest.DoSomething();
            Assert.AreEqual(GeneratedGuids.Last(), someOtherGuid);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really basic issue, but I'm new to perl and cannot work
I'm working on a basic Issue Management System in order to learn ASP.NET MVC.
Now I must be missing something here, as this seems a very basic issue
I'm having a linking issue with a basic C++ program. No, I'm not including
I've got two sizing issue regarding a Window I've got. The basic layout is
I'm trying to create a basic shopping cart, having an issue with the product
I have basic issue that i don't understand, we use HEAT to consume directory
I am writing a basic application to test the behavior of the accelerometer. Currently
I have a pretty basic assignment, but am having an issue making my main
I recently had this issue with a client. The code read: ini_set( sendmail_from, noreply@<current-domain>.com

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.