Announcements
Hi folks
I am new to contributing to a Dynamics 365 application and looking to add some unit tests around a method I am working on but have an issue that is baffling me.
I have used a library called FakeXrmEasy.9 to create a fake XrmFakedContext and added a test Email to this as below:
[TestClass] public class AutoSendEmail { XrmFakedContext _fakeContext; XrmServiceContext _ctx; private Guid _testScheduledTodayEmail = Guid.NewGuid(); [TestInitialize] public void SetUp() { var dueEmail = new Email { ActivityId = id, Id = id, Category = "test category" . . . }; _fakeContext.Initialize(new List() { dueEmail }); _ctx = new XrmServiceContext(_fakeContext.GetOrganizationService()); } [TestMethod] public void Cancel_1st_chaser_email_when_account_payment_method_NOT_invoice() { internalCodeLibrary.AutoSendMail(_ctx, false); } }
So the test simply calls my internal codebase to execute a method and during the course of this method a call is made to ctx.IsAttached for my email which always returns false, however, the existing code then tries to attach my mail and receives exception that "The context is already tracking a different 'email' entity with the same identity"
I don't understand how I can return false for IsAttached then exception that my mail is already being tracked. Any pointers gratefully received.
Cheers
André Arnaud de Cal...
294,095
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator