Hi Krishna,
Just replying to your tweet sorry and FakeXrmEasy.
Did you have a look at the get started (https://dynamicsvalue.com/get-started/overview) page? It contains basic information about how to get started.
Now, back to your specific question. FakeXrmEasy is not to be meant to be used just for codeactivities or plugins, it essentially exposes an implementation of IOrganizationService with a query engine and other CRM messages already implemented. So basically you can unit test any .net code using that is connected to Dynamics 365 CE (CRM).
First, you'll need to setup your console app so it only references the interface (IOrganizationService), maybe refactor its logic into a separate class, so it will be easier to unit test. Once you have that...
The way I would unit test that is by something similar to this (in a unit test project with a reference to your console app):
[Fact]
public void Should_update_a_case_property_when_some_class_method_is_called()
{
/***** ARRANGE PHASE HERE ****/
var ctx = new XrmFakedContext();
var case = new Case()
{ Id = Guid.NewGuid(),
//Any other attributes here...
};
//defines an initial state where we only have one case record
ctx.Initialize(case);
/***** ACT PHASE HERE ****/
//returns an instance of an organization service already mocked, any future calls to that service will create / delete, / update entities in the faked context (ctx)
var service = ctx.GetOrganizationService();
//Say your class in the console app was called... SomeClass.cs with a constructor to pass in the organization service like public //SomeClass(IOrganizationService)
var someClass = new SomeClass(service); //your class will use the fake service from a unit test, a real service when invoked from the console app
someClass.UpdateCase(case);
/***** ASSERT PHASE HERE (we query the context to check if an attribute(s) was updated to some value(s) )****/
var updatedCase = ctx.CreateQuery<Case>().FirstOrDefault();
Assert.Equal("someValue", updatedCase.SomeProperty);
}
As you can see, with FakeXrmEasy I didn't have to mock anything...
That's it, hope it makes sense (was typing directly into the text editor so there might be errors... :) )