csharp CRM 2016 #UnitTests#CRM2016 #MoussaElAnnan

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp CRM 2016 #UnitTests#CRM2016 #MoussaElAnnan相关的知识,希望对你有一定的参考价值。

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FakeXrmEasy;
using System.Reflection;
using Microsoft.Xrm.Sdk;
using System.Collections.Generic;
using CrmEarlyBound;
using System.Linq;

namespace ExecuteMultipleUnitTest {
 [TestClass]
 public class UnitTest1 {
  [TestMethod]
  public void TestMethod1_Passed() {

   var context = new XrmFakedContext();

   context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));
   var account = new Account {
    Id = Guid.NewGuid(),
     Name = "An Account"
   };

   context.Initialize(new List < Account > () {
    account
   });

   var service = context.GetFakedOrganizationService();

   var accountToUpdate = new Account() {
    Id = account.Id
   };
   accountToUpdate.Name = "A new faked name!";
   service.Update(accountToUpdate);

   var updatedAccountName = context.CreateQuery < Account > ()
    .Where(e => e.Id == account.Id)
    .FirstOrDefault();
   Assert.AreEqual("A new faked name!", updatedAccountName.Name);
  }

  [TestMethod]
  public void TestMethod1_Failed() {
   var context = new XrmFakedContext();
   context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));

   var account = new Account {
    Id = Guid.NewGuid(),
     Name = "An Account"
   };

   context.Initialize(new List < Account > () {
    account
   });

   var service = context.GetFakedOrganizationService();

   var accountToUpdate = new Account() {
    Id = account.Id
   };
   accountToUpdate.Name = "A new faked name1!";
   service.Update(accountToUpdate);

   var updatedAccountName = context.CreateQuery < Account > ()
    .Where(e => e.Id == account.Id)
    .FirstOrDefault();
   Assert.AreEqual("A new faked name!", updatedAccountName.Name);
  }
 }
}

以上是关于csharp CRM 2016 #UnitTests#CRM2016 #MoussaElAnnan的主要内容,如果未能解决你的问题,请参考以下文章

csharp CRM 2016 #Emails#C#CRM2016 #MoussaElAnnan

csharp CRM 2016 #Client #Connection #CrmServiceClient#CRM2016 #MoussaElAnnan

csharp CRM 2015-2016 C ##Plugins #Metadata#CRM2016 #MoussaElAnnan

csharp CRM 2015-2016 C#Helper #Teams #Sharing#CRM2016 #MoussaElAnnan

csharp CRM 2016 C ## C ##OptionSets #MoussaElAnnan

csharp UnitTest单元测试