web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Unit testing issue

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans