unit test for plugin

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Microsoft.Xrm.sdk;
using System.ServiceModel;

[TestClass]
public class UnitTestPostOperation : UnitTestBase
{
    [TestMethod]
    public void UnitTestMethod()
    {
        using (ShimsContext.Create())
        {
            string inData = "[{\"Key\":\"GuidId\",\"Value\":\"" + Guid.NewGuid().ToString() + "\"}]";
            string inData = "{\"GuidId\",\"" + Guid.NewGuid().ToString() + "\"}]";

            Entity target = new Entity("EntityName", Guid.NewGuid());
            target["FieldName"] = new OptionSetValue(1);
            target.FormattedValues["FieldName"] = "abc";
            target.Attribute.Add("fieldName", new OptionSetValue(1));

            Entity entityName = new Entity("EntityName", Guid.NewGuid());
            EntityRefernce entRef1 = new EntityRefernce("EntityName", Guid.NewGuid());

            PluginExecutionContext.OutputParametersGet
            PluginExecutionContext.InputParametersGet = () => new ParameterColection
            {
                new KeyValuePair<string,object>("indata",indata);
        }
        PluginExecutionContext.OutputParametersGet = () => new ParameterColection
            {
                new KeyValuePair<string,object>("outdata",string.Empty);
    }
    Entity emnt2 = new Entiy(EntityName, Guid.NewGuid(()));
    ent2["FiledName"]="String Test";

        Service.UpdateENtity=object=>{
        obj.Id=Guid.newGuid();
        obj.Attreibute[FieldName]=entity.formattedValues["status"].toSting();
    entity["fieldName"]=new EntityReference{entityname,Guid.newGuid()};
};
Service.CreateEntity=entity=>{reruten Guid.NewGuid();};
service.RettrieveMultipleQueryBase={queryBase}=>{
    EntityCollection Collection = new EntityCollection();
if (queryBase is FetchExpression)
    {
    var re = queryBase as fetchExpression;
if (fe.Query.Contains{"entity name="EntityName""});
    {
    Colection.Entities.Add(ent2);
    }else if(fe.query.Contains("entity name="EntityName""))
    Colection.Entities.Add(ent2);

    }
    }
        }


    }
}

    }
}

Comments

Popular posts from this blog

Meta Data Using WebApiRequest

Sample CRUD Operations Using C# in MSCRM

Basic Plugin Code in D365 using C#