public void RetrieveAccountsByIdTest() { var connection = new CrmConnection("Crm"); var service = new OrganizationService(connection); var context = new OrganizationServiceContext(service); using (ShimsContext.Create()) { var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context); LINQToCRM target = new LINQToCRM(context); fakeContext.CreateQueryString = (entityName) => { return(new System.Linq.EnumerableQuery <Microsoft.Xrm.Sdk.Entity>(new Microsoft.Xrm.Sdk.Entity[] { })); }; Guid id = Guid.NewGuid(); Microsoft.Xrm.Sdk.Entity expected = new Microsoft.Xrm.Sdk.Entity(); System.Linq.Fakes.ShimQueryable.FirstOrDefaultOf1IQueryableOfM0 <Microsoft.Xrm.Sdk.Entity>((a) => { expected.Id = id; return(expected); }); Microsoft.Xrm.Sdk.Entity actual; actual = target.RetrieveAccountsById(id); Assert.AreEqual(expected, actual); } }
public void RetrieveAccountsByNameTest() { var connection = new CrmConnection("Crm"); var service = new OrganizationService(connection); var context = new OrganizationServiceContext(service); using (ShimsContext.Create()) { var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context); LINQToCRM target = new LINQToCRM(context); var entity1 = new Microsoft.Xrm.Sdk.Entity("account"); entity1.Id = Guid.NewGuid(); entity1["name"] = "abcabcabc"; var entity2 = new Microsoft.Xrm.Sdk.Entity("account"); entity2.Id = Guid.NewGuid(); entity2["name"] = "123123123"; var entity3 = new Microsoft.Xrm.Sdk.Entity("account"); entity3.Id = Guid.NewGuid(); entity3["name"] = "a1b2c3a1b2c3"; fakeContext.CreateQueryString = (entityName) => { return(new System.Linq.EnumerableQuery <Microsoft.Xrm.Sdk.Entity>(new Microsoft.Xrm.Sdk.Entity[] { entity1, entity2, entity3 })); }; IEnumerable <Microsoft.Xrm.Sdk.Entity> expected = new List <Microsoft.Xrm.Sdk.Entity> { entity1, entity2 }; System.Linq.Fakes.ShimEnumerableQuery <Microsoft.Xrm.Sdk.Entity> .AllInstances.GetEnumerator = (a) => { return(expected.GetEnumerator()); }; string accountName = "abcabcabc"; IEnumerable <Microsoft.Xrm.Sdk.Entity> actual; actual = target.RetrieveAccountsByName(accountName); Assert.AreEqual(expected.Count(), actual.Count()); Assert.AreEqual(expected.ElementAt(0), actual.ElementAt(0)); Assert.AreEqual(expected.ElementAt(1), actual.ElementAt(1)); } }
public void DuplicatePluginNameOnDownload() { // Since the name is used to uniquely identify plugins per type, we can't have existing duplicates when downloading steps using (ShimsContext.Create()) { // Arrange Fakes.ShimQueries.GetPluginStepsOrganizationServiceContextString = (OrganizationServiceContext context, string name) => { return(new List <SdkMessageProcessingStep>() { new SdkMessageProcessingStep { Name = "step" }, new SdkMessageProcessingStep { Name = "step" } }); }; var trace = new TraceLogger(); OrganizationServiceContext ctx = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(); var task = new DownloadPluginMetadataTask(ctx, trace); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\TestPlugin"); bool exception = false; // Act try { task.Execute(path); } catch (SparkleTaskException ex) { exception = (ex.ExceptionType == SparkleTaskException.ExceptionTypes.DUPLICATE_STEP); } // Assert Assert.IsTrue(exception, "Duplicate step names not detected"); } }
private static DownloadWebresourceConfigTask GetWebresourceTestTask(ConfigFile config, WebResource existingWebresource) { using (ShimsContext.Create()) { // Arrange Fakes.ShimQueries.GetWebresourcesOrganizationServiceContext = (OrganizationServiceContext context) => { return(new List <WebResource> { existingWebresource }); }; SparkleXrm.Tasks.Config.Fakes.ShimConfigFile.FindConfigStringBoolean = (string folder, bool raiseEror) => { return(new List <ConfigFile> { config }); }; SparkleXrm.Tasks.Fakes.ShimDirectoryEx.SearchStringStringListOfString = (string folder, string search, List <string> paths) => { return(new List <string>() { @"C:\code\solution\webresources\new_\js\somefile.js" }); }; SparkleXrm.Tasks.Config.Fakes.ShimConfigFile.AllInstances.Save = (ConfigFile c) => { }; var trace = new TraceLogger(); OrganizationServiceContext ctx = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(); var task = new DownloadWebresourceConfigTask(ctx, trace); task.Prefix = "new"; var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\SparkleXrm.Tasks.Tests\Resources"); // Act task.Execute(path); return(task); } }
public void CreateAccountTest() { // // Arrange // var connection = new CrmConnection("Crm"); var service = new OrganizationService(connection); var context = new OrganizationServiceContext(service); using (ShimsContext.Create()) { string accountName = "abcabcabc"; Guid actual; Guid expected = Guid.NewGuid(); int callCount = 0; Entity entity = null; var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context); fakeContext.AddObjectEntity = e => { callCount++; entity = e; }; fakeContext.SaveChanges = () => { entity.Id = expected; // SaveChangesResultCollection only has one internal constructor // so we can not create a instance outside of Microsoft.Xrm.Sdk assembly // we will use reflection to create instances of SaveChangesResultCollection and SaveChangesResult var results = CreateSaveChangesResultCollection(SaveChangesOptions.None); var request = new OrganizationRequest(); var response = new OrganizationResponse(); results.Add(CreateSaveChangesResult(request, response)); return(results); }; ContextMethods target = new ContextMethods(context); // // Act // actual = target.CreateAccount(accountName); // // Assert // Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.AddObject is called once Assert.IsNotNull(entity); // verify OrganizationServiceContext.AddObject is called with not null object Assert.AreEqual(entity.LogicalName, "account"); // verify OrganizationServiceContext.AddObject is called with entity with proper entity name Assert.AreEqual(entity.GetAttributeValue <string>("name"), accountName); // verify OrganizationServiceContext.AddObject is called with entity with proper value set on name attribute Assert.AreEqual(expected, actual); } }