jordimontana82 / fake-xrm-easy

The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you
https://dynamicsvalue.com/get-started/overview?source=git
Other
263 stars 182 forks source link

ConditionOperator.LessThan is throwing error "Specified Cast is not valid" for DateTimeField #571

Closed pavansarma93 closed 3 years ago

pavansarma93 commented 3 years ago

I am trying for the below code and I encountered the error saying "Specified Cast is not valid" , The error is on the DateTime field , This is a valid condition because it is giving the data required when executing on plugin. However the Unit test is failing. Hope this would be fixed soon.

[TestMethod]
        public void TestMethod1()
        {
            XrmFakedContext fakeContext = new XrmFakedContext();
            IOrganizationService service = fakeContext.GetOrganizationService();
        Entity account = new Entity("account",Guid.NewGuid());
        account["createdon"] = DateTime.Now.AddDays(-1).ToShortDateString();

        fakeContext.Initialize(new List<Entity>() {
        account
        });

        QueryExpression query = new QueryExpression("account");
        query.Criteria.AddCondition("createdon", ConditionOperator.LessThan, DateTime.Now.ToShortDateString());

        var result = service.RetrieveMultiple(query);

    }`
jordimontana82 commented 3 years ago

Hi @pavansarma93 ,

Did you try initialising the account record with the actual DateTime value instead of the string? Do you get the same error?

pavansarma93 commented 3 years ago

@jordimontana82 : That's a very quick response. yeah after that it fixed. Thank you so much. Just a request if possible in your blogs can you add the examples for a late bound plugin with all standard operations (retrieve, retrievemultiple, create etc.). Because there are no resources out there.

jordimontana82 commented 3 years ago

Thanks, yes, we're upgrading the website actually, so a brand new docs site will be available.