fakeXrm易于用于CRM测试初始化问题



我正在尝试遵循FakeXrmEasy的基本教程,但我不确定为什么会出现错误。我安装了需要安装的所有内容来模拟 Dynamics 365,但仍然收到错误。我不知道我错过了什么,我真的很想能够使用这个工具。

CS1950 集合初始值设定项的最佳重载添加方法"List.Add(Entity("有一些无效参数 unitTest c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 48 活动

CS0246 找不到类型或命名空间名称"帐户"(是否缺少 using 指令或程序集引用? unitTest c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 45 Active

不知道我是否应该创建一个帐户类,我也尝试过,但这也不起作用。我得到了

CS1503 参数 1:无法从"unitTest.Account"转换为"Microsoft.Xrm.Sdk.Entity"单元测试 c:\Users\acapell\documents\visual studio 2015\Projects\unitTest\unitTest\Program.cs 48 活动

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FakeItEasy;
using FakeXrmEasy;
using Microsoft.Xrm.Sdk;

namespace unitTest
{
class Program
{
static void Main(string[] args)
{
}
}
class unitTest
{
public object ProxyTypesAssembly { get; private set; }
public void MyFirstTest()
{//test method body
var context = new XrmFakedContext();
//You can think of a context like an Organisation database which stores entities In Memory.
//We can also use TypedEntities but we need to tell the context where to look for them, 
//this could be done, easily, like this:
context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));
//We have to define our initial state now, 
//by calling the Initialize method, which expects a list of entities.

var account = new Account() { Id = Guid.NewGuid(), Name = "My First Faked Account yeah!" };
context.Initialize(new List<Entity>() {
account
});
}
}

}

您是否在 CRM 项目中使用早期绑定并获得了正确的引用?如果您不使用早期绑定,则可以尝试后期绑定,例如

//context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));
var account = new Entity();
account.LogicalName = "account";
account.Attributes["name"] = "your account name";

最新更新