コード例 #1
0
 public void XrmLookupServiceVerifyDoesNotCrashIfConnectionDoesNotWork()
 {
     try
     {
         var solution        = ReCreateTestSolution();
         var testEntryObject = new TestXrmObjectEntryClass()
         {
             XrmLookupField = solution.ToLookup()
         };
         var classSelfMapper = new ClassSelfMapper();
         var newConnection   = classSelfMapper.Map(GetXrmRecordConfiguration());
         newConnection.OrganizationUniqueName = "Foo";
         var newService           = new XrmRecordService(newConnection);
         var objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), newService));
         objectEntryViewModel.LoadFormSections();
         Assert.IsNotNull(testEntryObject.XrmLookupField);
         Assert.IsNotNull(testEntryObject.XrmLookupFieldCascaded);
     }
     catch (FakeUserMessageException)
     {
     }
 }
コード例 #2
0
        public void RecreatePortalData(bool createSecondDuplicateSite = false, XrmRecordService useRecordService = null)
        {
            useRecordService = useRecordService ?? XrmRecordService;

            DeleteAllPortalData(useRecordService: useRecordService);

            var website1 = CreateTestRecord(Entities.adx_website, new Dictionary <string, object>
            {
                { Fields.adx_website_.adx_name, "Fake Site 1" }
            }, useService: useRecordService.XrmService);

            CreateWebsiteRecords(website1, useRecordService: useRecordService);

            if (createSecondDuplicateSite)
            {
                var website2 = CreateTestRecord(Entities.adx_website, new Dictionary <string, object>
                {
                    { Fields.adx_website_.adx_name, "Fake Site 2" }
                }, useService: useRecordService.XrmService);
                CreateWebsiteRecords(website2, useRecordService: useRecordService);
            }
        }
コード例 #3
0
        private void VerifyRecordTypes(CustomisationImportRequest request)
        {
            var response = new CustomisationImportResponse();

            var optionMetadata =
                CustomisationImportService.ExtractOptionSetsFromExcel(request.ExcelFile.FileName, Controller, response);
            var fieldMetadata =
                CustomisationImportService.ExtractFieldMetadataFromExcel(request.ExcelFile.FileName, Controller,
                                                                         optionMetadata, response).Values;
            var recordMetadata =
                CustomisationImportService.ExtractRecordMetadataFromExcel(request.ExcelFile.FileName, Controller,
                                                                          fieldMetadata, response).Values;

            foreach (var metadata in recordMetadata)
            {
                Assert.IsTrue(XrmRecordService.RecordTypeExists(metadata.SchemaName));
                Assert.IsTrue(metadata.DisplayName == XrmRecordService.GetRecordTypeMetadata(metadata.SchemaName).DisplayName);
                Assert.IsTrue(metadata.CollectionName ==
                              XrmRecordService.GetRecordTypeMetadata(metadata.SchemaName).CollectionName);
                Assert.IsTrue(metadata.Audit == XrmRecordService.GetRecordTypeMetadata(metadata.SchemaName).Audit);
            }
        }
コード例 #4
0
        private void AddWebBrowseGridFunction()
        {
            var customGridFunction = new CustomGridFunction("WEB", "Open In Web", (g) =>
            {
                if (g.SelectedRows.Count() != 1)
                {
                    g.ApplicationController.UserMessage("Please Select One Row To Browse The Connection");
                }
                else
                {
                    var selectedRow = g.SelectedRows.First();
                    var instance    = ((ObjectRecord)selectedRow.Record).Instance as SavedXrmRecordConfiguration;
                    if (instance != null)
                    {
                        var xrmRecordService = new XrmRecordService(instance);
                        Process.Start(xrmRecordService.WebUrl);
                    }
                }
            }, (g) => g.GridRecords != null && g.GridRecords.Any());

            this.AddCustomGridFunction(customGridFunction, typeof(SavedXrmRecordConfiguration));
        }
コード例 #5
0
        private void VerifyViews(CustomisationImportRequest request)
        {
            var response = new CustomisationImportResponse();

            var optionMetadata =
                CustomisationImportService.ExtractOptionSetsFromExcel(request.ExcelFile.FileName, Controller, response);
            var fieldMetadata =
                CustomisationImportService.ExtractFieldMetadataFromExcel(request.ExcelFile.FileName, Controller,
                                                                         optionMetadata, response).Values;
            var recordMetadata =
                CustomisationImportService.ExtractRecordMetadataFromExcel(request.ExcelFile.FileName, Controller,
                                                                          fieldMetadata, response).Values;

            foreach (var metadata in recordMetadata)
            {
                var views = XrmRecordService.GetViewsToUpdate(metadata);
                Assert.IsTrue(views.Any());
                foreach (var query in views)
                {
                    foreach (var viewField in metadata.Views.First().Fields)
                    {
                        if (query.Contains("fetchxml"))
                        {
                            Assert.IsTrue(
                                query.GetStringField("fetchxml")
                                .Contains("<attribute name=\"" + viewField.FieldName + "\" />"));
                        }
                        if (query.Contains("layoutxml"))
                        {
                            Assert.IsTrue(
                                query.GetStringField("layoutxml")
                                .Contains("<cell name=\"" + viewField.FieldName + "\" width=\"" + viewField.Width +
                                          "\" />"));
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void VsixDeployWebResourcesTest()
        {
            //first delete all the test deployed javascriot files
            var javaScriptFiles = GetJavaScriptFiles();

            DeleteJavaScriptFileRecords();
            Assert.IsFalse(GetJavaScriptFileRecords().Any());

            //create an app, deploy and verify created
            VisualStudioService.SetSelectedItems(GetJavaScriptFiles().Select(f => new FakeVisualStudioProjectItem(f)).ToArray());
            var testApplication = CreateAndLoadTestApplication <DeployWebResourceModule>();
            var dialog          = testApplication.NavigateToDialog <DeployWebResourceModule, DeployWebResourceDialog>();

            Assert.AreEqual(GetJavaScriptFiles().Count(), GetJavaScriptFileRecords().Count());

            //okay the code also allows match by display name
            //so I will add this to verify that too
            //basically change ones display name and file name then verify it still matches
            var files         = GetJavaScriptFiles();
            var records       = GetJavaScriptFileRecords();
            var firstFileInfo = new FileInfo(files.First());
            var record        = records.First(e => e.GetStringField(Fields.webresource_.name) == firstFileInfo.Name);

            XrmRecordService.Delete(record);
            var newRecord = XrmRecordService.NewRecord(Entities.webresource);

            newRecord.SetField(Fields.webresource_.name, "jrm_fakescriptname", XrmRecordService);
            newRecord.SetField(Fields.webresource_.displayname, firstFileInfo.Name, XrmRecordService);
            newRecord.SetField(Fields.webresource_.webresourcetype, OptionSets.WebResource.Type.ScriptJScript, XrmRecordService);
            XrmRecordService.Create(newRecord);

            //create an app, deploy again and verify not duplicated
            VisualStudioService.SetSelectedItems(GetJavaScriptFiles().Select(f => new FakeVisualStudioProjectItem(f)).ToArray());
            testApplication = CreateAndLoadTestApplication <DeployWebResourceModule>();
            dialog          = testApplication.NavigateToDialog <DeployWebResourceModule, DeployWebResourceDialog>();

            Assert.AreEqual(GetJavaScriptFiles().Count(), GetJavaScriptFileRecords().Count());
        }
コード例 #7
0
        private void DeployPackage(DeployPackageRequest request, ServiceRequestController controller, DeployPackageResponse response)
        {
            var xrmRecordService = new XrmRecordService(request.Connection, controller.Controller);
            var packageFolder    = request.FolderContainingPackage.FolderPath;
            var solutionFiles    = Directory.GetFiles(packageFolder, "*.zip")
                                   .OrderBy(s => s)
                                   .ToArray();

            var importItems = ImportSolutions(solutionFiles, controller.Controller, xrmRecordService);

            response.AddResponseItems(importItems.Select(it => new DataImportResponseItem(it.Type, null, it.Name, null, $"{it.Result} - {it.ErrorCode} - {it.ErrorText}", null, it.GetUrl())));

            foreach (var childFolder in Directory.GetDirectories(packageFolder))
            {
                if (new DirectoryInfo(childFolder).Name == "Data")
                {
                    var dataImportService = new ImportXmlService(xrmRecordService);
                    var importResponse    = new ImportXmlResponse();
                    dataImportService.ImportXml(childFolder, controller, importResponse);
                    response.LoadImportxmlResponse(importResponse);
                }
            }
        }
コード例 #8
0
        public XrmPackageSettingsDialog(IDialogController dialogController, XrmPackageSettings objectToEnter, IVisualStudioService visualStudioService, XrmRecordService xrmRecordService)
            : base(dialogController, xrmRecordService, objectToEnter)
        {
            XrmRecordService    = xrmRecordService;
            VisualStudioService = visualStudioService;

            if (string.IsNullOrWhiteSpace(XrmRecordService.XrmRecordConfiguration.OrganizationUniqueName))
            {
                //if there was no connection then lets redirect to the connection entry first
                var    newConnection = new SavedXrmRecordConfiguration();
                Action refreshChildDialogConnection = () => {
                    newConnection.Active = true;
                    XrmRecordService.XrmRecordConfiguration = newConnection;
                    SettingsObject.Connections = new[] { newConnection };
                };
                var connectionEntryDialog = new ConnectionEntryDialog(this, newConnection, visualStudioService, true, doPostEntry: refreshChildDialogConnection);
                var subDialogList         = new List <DialogViewModel>();
                subDialogList.Add(connectionEntryDialog);
                XrmRecordService.XrmRecordConfiguration = newConnection;
                subDialogList.AddRange(SubDialogs);
                SubDialogs = subDialogList;
            }
        }
コード例 #9
0
        public void DeleteAllPortalData(IEnumerable <string> dontDeleteTypes = null, XrmRecordService useRecordService = null)
        {
            var typesToDelete = new[]
            {
                Entities.adx_websitelanguage,
                Entities.adx_webrole,
                Entities.adx_webpage,
                Entities.adx_webpageaccesscontrolrule,
                Entities.adx_entityform,
                Entities.adx_entityformmetadata,
                Entities.adx_entitylist,
                Entities.adx_webform,
                Entities.adx_webformstep,
                Entities.adx_webformmetadata,
                Entities.adx_weblink,
                Entities.adx_weblinkset,
                Entities.adx_website,
                Entities.adx_webfile,
                Entities.adx_webtemplate,
                Entities.adx_contentsnippet,
                Entities.adx_entitypermission,
                Entities.adx_pagetemplate,
                Entities.adx_publishingstate,
                Entities.adx_sitesetting,
                Entities.adx_sitemarker,
                Entities.adx_contentaccesslevel,
            };

            if (dontDeleteTypes != null)
            {
                typesToDelete = typesToDelete.Except(dontDeleteTypes).ToArray();
            }
            foreach (var type in typesToDelete)
            {
                DeleteAll(type, serviceToUse: useRecordService?.XrmService);
            }
        }
コード例 #10
0
        private void AddAutonumbersToSavedConnectionsGrid()
        {
            var customGridFunction = new CustomGridFunction("AUTONUMBERS", "Auto Numbers", (g) =>
            {
                if (g.SelectedRows.Count() != 1)
                {
                    g.ApplicationController.UserMessage("Please Select One Row To Run This Function");
                }
                else
                {
                    var selectedRow = g.SelectedRows.First();
                    var instance    = ((ObjectRecord)selectedRow.Record).Instance as SavedXrmRecordConfiguration;
                    if (instance != null)
                    {
                        var xrmRecordService = new XrmRecordService(instance, formService: new XrmFormService());
                        var dialog           = new AutonumberDialog(xrmRecordService, new DialogController(ApplicationController));
                        dialog.SetTabLabel(instance.ToString() + " " + dialog.TabLabel);
                        g.ApplicationController.NavigateTo(dialog);
                    }
                }
            }, (g) => g.GridRecords != null && g.GridRecords.Any());

            this.AddCustomGridFunction(customGridFunction, typeof(SavedXrmRecordConfiguration));
        }
コード例 #11
0
        private void AddBrowseButtonToSavedConnectionsGrid()
        {
            var customGridFunction = new CustomGridFunction("CRUD", "Crud/Query", (g) =>
            {
                if (g.SelectedRows.Count() != 1)
                {
                    g.ApplicationController.UserMessage("Please Select One Row To Run This Function");
                }
                else
                {
                    var selectedRow = g.SelectedRows.First();
                    var instance    = ((ObjectRecord)selectedRow.Record).Instance as SavedXrmRecordConfiguration;
                    if (instance != null)
                    {
                        var xrmRecordService = new XrmRecordService(instance, serviceFactory: ApplicationController.ResolveType <IOrganizationConnectionFactory>(), formService: new XrmFormService());
                        var dialog           = new XrmCrudDialog(xrmRecordService, new DialogController(ApplicationController));
                        dialog.SetTabLabel(instance.ToString() + " " + dialog.TabLabel);
                        g.ApplicationController.NavigateTo(dialog);
                    }
                }
            }, (g) => g.GridRecords != null && g.GridRecords.Any());

            this.AddCustomGridFunction(customGridFunction, typeof(SavedXrmRecordConfiguration));
        }
コード例 #12
0
        public void CustomisationImportTestImportService()
        {
            PrepareTests();

            var requests = TestCustomisationImportRequest.GetTestRequests(ExecutionPath);

            DeleteRelationships(requests);
            DeleteEntities(requests);
            DeleteOptionSets(requests);

            XrmRecordService.Publish();

            var importService =
                new XrmCustomisationImportService(XrmRecordService);

            foreach (var request in requests)
            {
                var response = importService.Execute(request, CreateServiceRequestController());
                if (response.HasError)
                {
                    Assert.Fail(response.GetResponseItemsWithError().First().Exception.DisplayString());
                }

                Assert.IsFalse(response.ExcelReadErrors);
                Assert.IsNull(response.Exception);

                XrmRecordService.Publish();
                ClearCache();

                VerifyRelationships(request);
                VerifyRecordTypes(request);
                VerifyFields(request);
                VerifyOptionSets(request);
                VerifyViews(request);
            }
        }
コード例 #13
0
        private void AddReferenceConfigJoins(LinkEntity linkToReferenced, Entity thisEntity, string field)
        {
            var referencedType       = XrmEntity.GetLookupType(thisEntity.GetFieldValue(field));
            var referencedTypeConfig = XrmRecordService.GetTypeConfigs().GetFor(referencedType);

            if (referencedTypeConfig != null && referencedTypeConfig.UniqueChildFields != null)
            {
                foreach (var uniqueField in referencedTypeConfig.UniqueChildFields)
                {
                    var theValue = thisEntity.GetFieldValue($"{field}.{uniqueField}");
                    if (theValue == null)
                    {
                        linkToReferenced.LinkCriteria.AddCondition(new ConditionExpression(uniqueField, ConditionOperator.Null));
                    }
                    else if (theValue is EntityReference)
                    {
                        var name = XrmEntity.GetLookupName(theValue);
                        var type = XrmEntity.GetLookupType(theValue);
                        var nextLinkToReferenced = linkToReferenced.AddLink(type, uniqueField, XrmService.GetPrimaryKeyField(type));
                        if (name == null)
                        {
                            nextLinkToReferenced.LinkCriteria.AddCondition(XrmService.GetPrimaryNameField(type), ConditionOperator.Null);
                        }
                        else
                        {
                            nextLinkToReferenced.LinkCriteria.AddCondition(XrmService.GetPrimaryNameField(type), ConditionOperator.Equal, name);
                            AddReferenceConfigJoins(nextLinkToReferenced, thisEntity, $"{field}.{uniqueField}");
                        }
                    }
                    else
                    {
                        linkToReferenced.LinkCriteria.AddCondition(new ConditionExpression(uniqueField, ConditionOperator.Equal, XrmService.ConvertToQueryValue(uniqueField, referencedType, theValue)));
                    }
                }
            }
        }
コード例 #14
0
        public static bool IsIncludeField(string fieldName, string entityType, XrmRecordService xrmRecordService, bool includeOwner)
        {
            var hardcodeInvalidFields = GetIgnoreFields(includeOwner);

            if (hardcodeInvalidFields.Contains(fieldName))
            {
                return(false);
            }
            //these are just hack since they are not updateable fields (IsWriteable)
            if (fieldName == "parentbusinessunitid")
            {
                return(true);
            }
            if (fieldName == "businessunitid")
            {
                return(true);
            }
            if (fieldName == "pricelevelid")
            {
                return(true);
            }
            if (fieldName == "salesliteratureid")
            {
                return(true);
            }
            if (fieldName == "transactioncurrencyid")
            {
                return(true);
            }
            if (fieldName == Fields.product_.productstructure)
            {
                return(true);
            }
            return
                (xrmRecordService.FieldExists(fieldName, entityType) && xrmRecordService.GetFieldMetadata(fieldName, entityType).Writeable);
        }
コード例 #15
0
        public void VsixDeployAssemblyDialogTest()
        {
            var pluginAssembly  = GetTestPluginAssemblyFile();
            var packageSettings = GetTestPackageSettings();

            DeleteTestPluginAssembly();

            Assert.IsFalse(GetTestPluginAssemblyRecords().Any());

            var dialog = new DeployAssemblyDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings);

            dialog.Controller.BeginDialog();

            var objectEntry = (ObjectEntryViewModel)dialog.Controller.UiItems.First();

            objectEntry.OnSave();

            Assert.AreEqual(1, GetTestPluginAssemblyRecords().Count());

            dialog = new DeployAssemblyDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings);
            dialog.Controller.BeginDialog();

            objectEntry = (ObjectEntryViewModel)dialog.Controller.UiItems.First();
            objectEntry.OnSave();

            Assert.AreEqual(1, GetTestPluginAssemblyRecords().Count());

            var pluginAssemblyRecord = GetTestPluginAssemblyRecords().First();

            var pluginTypes = XrmRecordService.RetrieveAllAndClauses(Entities.plugintype, new[]
            {
                new Condition(Fields.plugintype_.pluginassemblyid, ConditionType.Equal, pluginAssemblyRecord.Id)
            });

            Assert.IsTrue(pluginTypes.Any());
        }
コード例 #16
0
        private void AddBrowseButtonToSavedConnectionsGrid()
        {
            var customGridFunction = new CustomGridFunction("CRUD", "Browse Selected", (g) =>
            {
                if (g.SelectedRows.Count() != 1)
                {
                    g.ApplicationController.UserMessage("Please Select One Row To Browse The Connection");
                }
                else
                {
                    var selectedRow = g.SelectedRows.First();
                    var instance    = ((ObjectRecord)selectedRow.Record).Instance as SavedXrmRecordConfiguration;
                    if (instance != null)
                    {
                        var xrmRecordService = new XrmRecordService(instance, formService: new XrmFormService());
                        var dialog           = new CrudDialog(new DialogController(ApplicationController), xrmRecordService);
                        dialog.SetTabLabel("Browse " + instance.Name);
                        g.LoadDialog(dialog);
                    }
                }
            }, (g) => g.GridRecords != null && g.GridRecords.Any());

            this.AddCustomGridFunction(customGridFunction, typeof(SavedXrmRecordConfiguration));
        }
コード例 #17
0
        public static IEnumerable <string> GetComparisonFieldsFor(string type, XrmRecordService xrmRecordService)
        {
            var config = GetFor(type);
            var fields = new List <string>();

            if (config != null)
            {
                if (config.ParentLookupField != null)
                {
                    fields.Add(config.ParentLookupField);
                }
                if (config.UniqueChildFields != null)
                {
                    fields.AddRange(config.UniqueChildFields);
                }
                var parentComparisonFields = GetParentFieldsRequiredForComparison(type);
                if (parentComparisonFields != null)
                {
                    fields.AddRange(parentComparisonFields.Select(pc => config.ParentLookupField + "." + pc));
                }
            }
            fields.Add(xrmRecordService.GetPrimaryField(type));
            return(fields);
        }
コード例 #18
0
        public void VsixDeployAssemblyDialogTest()
        {
            //delete the plugin assembly so we verify it gets deployed
            DeleteTestPluginAssembly();
            Assert.IsFalse(GetTestPluginAssemblyRecords().Any());

            //test app do the deploy assembly dialog
            var testApplication = CreateAndLoadTestApplication <DeployAssemblyModule>(loadXrmConnection: false);
            var module          = testApplication.GetModule <DeployAssemblyModule>();

            module.DialogCommand();
            var dialog      = testApplication.GetNavigatedDialog <DeployAssemblyDialog>();
            var objectEntry = (ObjectEntryViewModel)dialog.Controller.UiItems.First();

            objectEntry.OnSave();
            //and verify the assembly now deployed
            Assert.AreEqual(1, GetTestPluginAssemblyRecords().Count());

            //test app do the deploy assembly again
            module = testApplication.GetModule <DeployAssemblyModule>();
            module.DialogCommand();
            dialog      = testApplication.GetNavigatedDialog <DeployAssemblyDialog>();
            objectEntry = (ObjectEntryViewModel)dialog.Controller.UiItems.First();
            objectEntry.OnSave();
            //verify still one assembly deployed
            Assert.AreEqual(1, GetTestPluginAssemblyRecords().Count());

            //verify plugin type records were created for the assmbly
            var pluginAssemblyRecord = GetTestPluginAssemblyRecords().First();
            var pluginTypes          = XrmRecordService.RetrieveAllAndClauses(Entities.plugintype, new[]
            {
                new Condition(Fields.plugintype_.pluginassemblyid, ConditionType.Equal, pluginAssemblyRecord.Id)
            });

            Assert.IsTrue(pluginTypes.Any());
        }
コード例 #19
0
 public DeploySolutionDialog(DeploySolutionService service,
                             IDialogController dialogController, XrmRecordService lookupService)
     : base(service, dialogController, lookupService)
 {
 }
        public void DeploymentMigrateRecordsMatchByNameTest()
        {
            var migrateName = "MIGRATESCRIPTNAME";

            DeleteAll(Entities.account);
            var account1 = CreateTestRecord(Entities.account);

            account1.SetField(Fields.account_.name, migrateName);
            account1 = UpdateFieldsAndRetreive(account1, Fields.account_.name);
            var account2 = CreateTestRecord(Entities.account);

            account2.SetField(Fields.account_.name, migrateName);
            account2 = UpdateFieldsAndRetreive(account2, Fields.account_.name);

            var altConnection = GetAltSavedXrmRecordConfiguration();
            var altService    = new XrmRecordService(altConnection, ServiceFactory);
            var accountsAlt   = altService.RetrieveAllAndClauses(Entities.account, null);

            foreach (var account in accountsAlt)
            {
                altService.Delete(account);
            }

            var application = CreateAndLoadTestApplication <MigrateRecordsModule>();

            var instance = new MigrateRecordsRequest();

            instance.SourceConnection = GetSavedXrmRecordConfiguration();
            instance.TargetConnection = GetAltSavedXrmRecordConfiguration();
            instance.IncludeNotes     = true;
            instance.IncludeNNRelationshipsBetweenEntities = true;
            instance.MatchByName          = false;
            instance.RecordTypesToMigrate = new[]
            {
                new ExportRecordType()
                {
                    Type             = ExportType.AllRecords,
                    RecordType       = new RecordType(Entities.account, Entities.account),
                    IncludeAllFields = true,
                }
            };

            var response = application.NavigateAndProcessDialog <MigrateRecordsModule, MigrateRecordsDialog, MigrateRecordsResponse>(instance);

            if (response.HasError)
            {
                Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString());
            }
            var summary = response.ImportSummary;

            Assert.AreEqual(1, summary.Count());

            Assert.AreEqual(2, summary.First().Created);

            accountsAlt = altService.RetrieveAllAndClauses(Entities.account, null);
            Assert.AreEqual(2, accountsAlt.Count());

            XrmService.Delete(account1);
            altService.Delete(accountsAlt.First(a => a.Id != account1.Id.ToString()));

            instance = new MigrateRecordsRequest();
            instance.SourceConnection = GetSavedXrmRecordConfiguration();
            instance.TargetConnection = GetAltSavedXrmRecordConfiguration();
            instance.IncludeNotes     = true;
            instance.IncludeNNRelationshipsBetweenEntities = true;
            instance.MatchByName          = true;
            instance.RecordTypesToMigrate = new[]
            {
                new ExportRecordType()
                {
                    Type             = ExportType.AllRecords,
                    RecordType       = new RecordType(Entities.account, Entities.account),
                    IncludeAllFields = true,
                }
            };

            response = application.NavigateAndProcessDialog <MigrateRecordsModule, MigrateRecordsDialog, MigrateRecordsResponse>(instance);
            if (response.HasError)
            {
                Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString());
            }

            summary = response.ImportSummary;
            Assert.AreEqual(1, summary.Count());
            Assert.AreEqual(1, summary.First().NoChange);

            accountsAlt = altService.RetrieveAllAndClauses(Entities.account, null);
            Assert.AreEqual(1, accountsAlt.Count());

            DeleteMyToday();
        }
コード例 #21
0
 public XrmTextSearchDialog(XrmTextSearchService service, IDialogController dialogController,
                            XrmRecordService xrmRecordService)
     : base(service, dialogController, xrmRecordService)
 {
 }
コード例 #22
0
 public XrmCrudDialog(XrmRecordService recordService, IDialogController dialogController)
     : base(dialogController, recordService)
 {
 }
コード例 #23
0
 public SolutionImportService(XrmRecordService xrmRecordService)
 {
     XrmRecordService = xrmRecordService;
 }
        public void VsixRefreshSettingsDialogTest()
        {
            var testApplication = CreateAndLoadTestApplication <XrmPackageSettingsModule>();
            var dialog          = testApplication.NavigateToDialog <XrmPackageSettingsModule, XrmPackageSettingsDialog>();

            //okay this one doesn't just auto enter an object
            //I am going to create a new publisher and solution
            //in the lookup fields

            //get the settings entry form
            var entryViewModel = GetEntryForm(dialog);

            entryViewModel.LoadFormSections();

            //set dummy prefix values
            entryViewModel.GetStringFieldFieldViewModel(nameof(XrmPackageSettings.SolutionDynamicsCrmPrefix)).Value = "Foo";
            entryViewModel.GetStringFieldFieldViewModel(nameof(XrmPackageSettings.SolutionObjectPrefix)).Value      = "Foo";

            DeleteTestNewLookupSolution();
            //invoke new on the solution lookup field
            var solutionField = entryViewModel.GetLookupFieldFieldViewModel(nameof(XrmPackageSettings.Solution));
            var Loo           = solutionField.LookupService;
            var For           = solutionField.LookupFormService;

            Assert.IsTrue(solutionField.AllowNew);
            solutionField.Value = null;
            solutionField.NewButton.Invoke();

            //get the new solution entry form
            var solutionEntryForm = entryViewModel.ChildForms.First() as RecordEntryFormViewModel;

            Assert.IsNotNull(solutionEntryForm);
            solutionEntryForm.LoadFormSections();
            solutionEntryForm.GetStringFieldFieldViewModel(Fields.solution_.uniquename).Value   = "TESTNEWLOOKUPSOLUTION";
            solutionEntryForm.GetStringFieldFieldViewModel(Fields.solution_.friendlyname).Value = "TESTNEWLOOKUPSOLUTION";
            solutionEntryForm.GetStringFieldFieldViewModel(Fields.solution_.version).Value      = "1.0.0.0";

            DeleteTestNewLookupPublisher();
            //invoke new on the publisher field
            var publisherField = solutionEntryForm.GetLookupFieldFieldViewModel(Fields.solution_.publisherid);

            Assert.IsTrue(publisherField.AllowNew);
            publisherField.NewButton.Invoke();

            //get the new publisher entry form enter some details and save
            var publisherEntryForm = solutionEntryForm.ChildForms.First() as RecordEntryFormViewModel;

            Assert.IsNotNull(publisherEntryForm);
            publisherEntryForm.LoadFormSections();
            publisherEntryForm.GetStringFieldFieldViewModel(Fields.publisher_.uniquename).Value                      = "TESTNEWLOOKUPPUBLISHER";
            publisherEntryForm.GetStringFieldFieldViewModel(Fields.publisher_.friendlyname).Value                    = "TESTNEWLOOKUPPUBLISHER";
            publisherEntryForm.GetStringFieldFieldViewModel(Fields.publisher_.customizationprefix).Value             = "abc";
            publisherEntryForm.GetIntegerFieldFieldViewModel(Fields.publisher_.customizationoptionvalueprefix).Value = 12345;
            publisherEntryForm.SaveButtonViewModel.Invoke();
            //verify publisher form closed
            Assert.IsFalse(solutionEntryForm.ChildForms.Any(), publisherEntryForm.GetValidationSummary());

            //verify the solution entry form is populated with the created publisher
            Assert.IsNotNull(publisherField.Value);
            Assert.IsNotNull(XrmRecordService.Get(publisherField.Value.RecordType, publisherField.Value.Id));

            //save the solution and verify form closed
            solutionEntryForm.SaveButtonViewModel.Invoke();
            Assert.IsFalse(entryViewModel.ChildForms.Any(), solutionEntryForm.GetValidationSummary());

            //verify the package entry form is populated with the created solution
            Assert.IsNotNull(solutionField.Value);
            Assert.IsNotNull(XrmRecordService.Get(solutionField.Value.RecordType, solutionField.Value.Id));
            //save package entry form
            SubmitEntryForm(dialog);

            var completionScreen = dialog.Controller.UiItems.First() as CompletionScreenViewModel;

            completionScreen.CloseButton.Invoke();
            Assert.IsNull(dialog.FatalException);

            //verify the package settings now have the solution we created when resolved
            var settingsManager = testApplication.Controller.ResolveType(typeof(ISettingsManager)) as ISettingsManager;

            Assert.IsNotNull(settingsManager);
            Assert.AreEqual(solutionField.Value.Id, settingsManager.Resolve <XrmPackageSettings>().Solution.Id);
        }
コード例 #25
0
        private IEnumerable <Entity> MapToEntities(IEnumerable <IRecord> queryRows, IMapSpreadsheetImport mapping, ParseIntoEntitiesResponse response, bool useAmericanDates)
        {
            var result = new List <Entity>();

            var nNRelationshipEntityNames = XrmRecordService
                                            .GetManyToManyRelationships()
                                            .Select(m => m.IntersectEntityName)
                                            .ToArray();

            var duplicateLogged = false;

            var rowNumber = 0;

            foreach (var row in queryRows)
            {
                rowNumber++;
                var targetType = mapping.TargetType;
                try
                {
                    var isNnRelation = nNRelationshipEntityNames.Contains(targetType);
                    var entity       = new Entity(targetType);
                    //this is used in the import to output the rownumber
                    //if the import throws an error
                    foreach (var fieldMapping in mapping.FieldMappings)
                    {
                        var targetField = fieldMapping.TargetField;
                        if (fieldMapping.TargetField != null)
                        {
                            var stringValue = row.GetStringField(fieldMapping.SourceField);
                            if (stringValue != null)
                            {
                                stringValue = stringValue.Trim();
                            }
                            if (isNnRelation)
                            {
                                //bit of hack
                                //for csv relationships just set to a string and map it later
                                //as the referenced record may not be created yet
                                entity.SetField(targetField, stringValue);
                            }
                            else if (XrmRecordService.XrmService.IsLookup(targetField, targetType))
                            {
                                //for lookups am going to set to a empty guid and allow the import part to replace with a correct guid
                                if (!stringValue.IsNullOrWhiteSpace())
                                {
                                    entity.SetField(targetField,
                                                    new EntityReference(XrmRecordService.XrmService.GetLookupTargetEntity(targetField, targetType),
                                                                        Guid.Empty)
                                    {
                                        Name = stringValue
                                    });
                                }
                            }
                            else
                            {
                                try
                                {
                                    entity.SetField(targetField, XrmRecordService.XrmService.ParseField(targetField, targetType, stringValue, useAmericanDates));
                                }
                                catch (Exception ex)
                                {
                                    response.AddResponseItem(new ParseIntoEntitiesResponse.ParseIntoEntitiesError(rowNumber, targetType, targetField, null, stringValue, "Error Parsing Field - " + ex.Message, ex));
                                }
                            }
                        }
                    }
                    if (entity.GetFieldsInEntity().All(f => XrmEntity.FieldsEqual(null, entity.GetField(f))))
                    {
                        //ignore any where all fields emopty
                        continue;
                    }
                    //okay any which are exact duplicates to previous ones lets ignore
                    if (result.Any(r => r.GetFieldsInEntity().Except(new[] { "Sheet.RowNumber" }).All(f =>
                    {
                        //since for entity references we just load the name with empty guids
                        //we check the dipslay name for them
                        var fieldValue1 = r.GetField(f);
                        var fieldValue2 = entity.GetField(f);
                        if (fieldValue1 is EntityReference && fieldValue2 is EntityReference)
                        {
                            return(((EntityReference)fieldValue1).Name == ((EntityReference)fieldValue2).Name);
                        }
                        else
                        {
                            return(XrmRecordService.FieldsEqual(fieldValue1, fieldValue2));
                        }
                    })))
                    {
                        if (!duplicateLogged)
                        {
                            response.AddResponseItem(new ParseIntoEntitiesResponse.ParseIntoEntitiesError(rowNumber, targetType, null, null, null, "At Least One Duplicate Removed", null));
                            duplicateLogged = true;
                        }
                        continue;
                    }
                    result.Add(entity);
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(new ParseIntoEntitiesResponse.ParseIntoEntitiesError("Mapping Error", ex));
                }
            }
            return(result);
        }
コード例 #26
0
 public SpreadsheetImportService(XrmRecordService xrmRecordService)
 {
     XrmRecordService = xrmRecordService;
 }
コード例 #27
0
 protected XrmFormController(XrmRecordService recordService, FormServiceBase formService,
                             IApplicationController appplicationController)
     : base(recordService, formService, appplicationController)
 {
 }
コード例 #28
0
 public ExportXmlDialog(ExportXmlService service,
                        IDialogController dialogController, XrmRecordService lookupService)
     : base(service, dialogController, lookupService)
 {
     SetTabLabel("Export XML");
 }
コード例 #29
0
        public IEnumerable <SolutionImportResult> ImportSolutions(IEnumerable <string> solutionFiles, LogController controller, XrmRecordService xrmRecordService)
        {
            var solutionFilesDictionary = new Dictionary <string, byte[]>();

            foreach (var item in solutionFiles)
            {
                solutionFilesDictionary.Add(new FileInfo(item).Name, File.ReadAllBytes(item));
            }
            var solutionImportService = new SolutionImportService(xrmRecordService);

            return(solutionImportService.ImportSolutions(solutionFilesDictionary, controller));
        }
コード例 #30
0
 public CreatePackageDialog(CreatePackageService service, IDialogController dialogController, XrmRecordService lookupService)
     : base(service, dialogController, lookupService)
 {
 }