public void DeploymentDeploySolutionTest() { var altConnection = GetAltSavedXrmRecordConfiguration(); var sourceSolution = ReCreateTestSolution(); var request = new DeploySolutionRequest(); request.SourceConnection = GetSavedXrmRecordConfiguration(); request.TargetConnection = GetAltSavedXrmRecordConfiguration(); request.Solution = sourceSolution.ToLookup(); request.ThisReleaseVersion = "3.0.0.0"; request.SetVersionPostRelease = "4.0.0.0"; var altService = new XrmRecordService(altConnection); var targetSolution = altService.GetFirst(Entities.solution, Fields.solution_.uniquename, sourceSolution.GetStringField(Fields.solution_.uniquename)); if (targetSolution != null) { altService.Delete(targetSolution); } var createApplication = CreateAndLoadTestApplication <DeploySolutionModule>(); var response = createApplication.NavigateAndProcessDialog <DeploySolutionModule, DeploySolutionDialog, DeploySolutionResponse>(request); Assert.IsFalse(response.HasError); targetSolution = altService.GetFirst(Entities.solution, Fields.solution_.uniquename, sourceSolution.GetStringField(Fields.solution_.uniquename)); Assert.IsTrue(targetSolution != null); Assert.AreEqual("3.0.0.0", targetSolution.GetStringField(Fields.solution_.version)); sourceSolution = XrmRecordService.Get(sourceSolution.Type, sourceSolution.Id); Assert.AreEqual("4.0.0.0", sourceSolution.GetStringField(Fields.solution_.version)); }
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); }
public void XrmCrudModuleTestScript() { // this script runs through several scenarios in the crud module // opening and running quickfind // opening a record updating a field and saving // selecting 2 records and doing a bulk update on them // doing a bulk update on all records // selecting 2 records and doing a bulk delete on them // doing a bulk delete on all records // create a new record // create a new record with an error thrown var count = XrmRecordService.GetFirstX(Entities.account, 3, null, null).Count(); while (count < 3) { CreateAccount(); count++; } //Create test app and load query var app = CreateAndLoadTestApplication <XrmCrudModule>(); var dialog = app.NavigateToDialog <XrmCrudModule, XrmCrudDialog>(); var queryViewModel = dialog.Controller.UiItems[0] as QueryViewModel; Assert.IsNotNull(queryViewModel); //select account type and run query queryViewModel.SelectedRecordType = queryViewModel.RecordTypeItemsSource.First(r => r.Key == Entities.account); queryViewModel.DynamicGridViewModel.GetButton("QUERY").Invoke(); Assert.IsTrue(queryViewModel.GridRecords.Any()); //select first record and open it queryViewModel.DynamicGridViewModel.EditRow(queryViewModel.DynamicGridViewModel.GridRecords.First()); var editAccountForm = queryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(editAccountForm); editAccountForm.LoadFormSections(); var id = editAccountForm.GetRecord().Id; //set its name var newName = "Updated " + DateTime.Now.ToFileTime(); editAccountForm.GetStringFieldFieldViewModel(Fields.account_.name).Value = newName; Assert.IsTrue(editAccountForm.ChangedPersistentFields.Count == 1); Assert.IsTrue(editAccountForm.ChangedPersistentFields.First() == Fields.account_.name); //save editAccountForm.SaveButtonViewModel.Invoke(); Assert.IsFalse(queryViewModel.ChildForms.Any()); //verify record updated var record = XrmRecordService.Get(Entities.account, id); Assert.AreEqual(newName, record.GetStringField(Fields.account_.name)); //now do bulk updates selected //select 2 record for bulk update queryViewModel.GridRecords.First().IsSelected = true; queryViewModel.GridRecords.ElementAt(1).IsSelected = true; id = queryViewModel.GridRecords.First().GetRecord().Id; var id2 = queryViewModel.GridRecords.ElementAt(1).GetRecord().Id; //this triggered by ui event queryViewModel.DynamicGridViewModel.OnSelectionsChanged(); //trigger and enter bulk update queryViewModel.DynamicGridViewModel.GetButton("BULKUPDATESELECTED").Invoke(); var newAddressLine1 = "Bulk Selected " + DateTime.Now.ToFileTime(); DoBulkUpdate(dialog, newAddressLine1, Fields.account_.address1_line1); //verify records updated record = XrmRecordService.Get(Entities.account, id); Assert.AreEqual(newAddressLine1, record.GetStringField(Fields.account_.address1_line1)); record = XrmRecordService.Get(Entities.account, id2); Assert.AreEqual(newAddressLine1, record.GetStringField(Fields.account_.address1_line1)); Assert.IsFalse(queryViewModel.ChildForms.Any()); //now do bulk updates all queryViewModel.DynamicGridViewModel.GetButton("BULKUPDATEALL").Invoke(); newAddressLine1 = "Bulk Update All " + DateTime.Now.ToFileTime(); DoBulkUpdate(dialog, newAddressLine1, Fields.account_.address1_line1); var allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); foreach (var account in allAccounts) { Assert.AreEqual(newAddressLine1, account.GetStringField(Fields.account_.address1_line1)); } //select 2 record for bulk delete queryViewModel.GridRecords.First().IsSelected = true; queryViewModel.GridRecords.ElementAt(1).IsSelected = true; id = queryViewModel.GridRecords.First().GetRecord().Id; id2 = queryViewModel.GridRecords.ElementAt(1).GetRecord().Id; //this triggered by ui event queryViewModel.DynamicGridViewModel.OnSelectionsChanged(); //trigger and enter bulk update queryViewModel.DynamicGridViewModel.GetButton("BULKDELETESELECTED").Invoke(); DoBulkDelete(dialog); //verify records deleted Assert.IsFalse(queryViewModel.ChildForms.Any()); Assert.IsNull(XrmRecordService.Get(Entities.account, id)); Assert.IsNull(XrmRecordService.Get(Entities.account, id2)); //now do bulk delete all queryViewModel.DynamicGridViewModel.GetButton("BULKDELETEALL").Invoke(); DoBulkDelete(dialog); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.AreEqual(0, allAccounts.Count()); //verify records deleted //add a new row enytering it into the child form queryViewModel.DynamicGridViewModel.AddRow(); EnterNewRecord(dialog); //verify created allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.AreEqual(1, allAccounts.Count()); //okay well this just verifies an error is thrown to the user if the create fails (i set an explicit duplicate id) queryViewModel.DynamicGridViewModel.AddRow(); var entryForm = dialog.QueryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(entryForm); entryForm.LoadFormSections(); entryForm.GetFieldViewModel(Fields.account_.accountid).ValueObject = allAccounts.First().Id; try { entryForm.SaveButtonViewModel.Invoke(); } catch (Exception ex) { Assert.IsTrue(ex is FakeUserMessageException); } //verify we are still on the child entry form entryForm = dialog.QueryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(entryForm); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); }
public void VsixManagePluginTriggersTest() { var packageSettings = GetTestPackageSettings(); DeployAssembly(packageSettings); var assemblyRecord = GetTestPluginAssemblyRecords().First(); DeletePluginTriggers(assemblyRecord); //add one update trigger RunDialogAndAddMessage("Update"); //verify trigger created var triggers = GetPluginTriggers(assemblyRecord); Assert.AreEqual(1, triggers.Count()); Assert.IsTrue(triggers.First().GetBoolField(Fields.sdkmessageprocessingstep_.asyncautodelete)); Assert.IsNull(triggers.First().GetStringField(Fields.sdkmessageprocessingstep_.filteringattributes)); Assert.IsNull(triggers.First().GetStringField(Fields.sdkmessageprocessingstep_.impersonatinguserid)); //verify preimage created for update with all fields var image = XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, triggers.First().Id); Assert.IsNotNull(image); Assert.IsNull(image.GetStringField(Fields.sdkmessageprocessingstepimage_.attributes)); Assert.AreEqual("PreImage", image.GetStringField(Fields.sdkmessageprocessingstepimage_.entityalias)); //add one create trigger RunDialogAndAddMessage("Create"); //verify created triggers = GetPluginTriggers(assemblyRecord); Assert.AreEqual(2, triggers.Count()); //delete a trigger var dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); var entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); var triggersSubGrid = entryViewModel.SubGrids.First(); triggersSubGrid.GridRecords.First().DeleteRow(); Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); //verify deleted triggers = GetPluginTriggers(assemblyRecord); Assert.AreEqual(1, triggers.Count()); //add 2 update triggers RunDialogAndAddMessage("Update"); RunDialogAndAddMessage("Update"); triggers = GetPluginTriggers(assemblyRecord); Assert.AreEqual(3, triggers.Count()); //okay now lets inspect and adjust the filtering attributes and preimages and impersonating user in one of the update messages dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); triggersSubGrid = entryViewModel.SubGrids.First(); var updateRows = triggersSubGrid.GridRecords.Where(r => r.GetLookupFieldFieldViewModel(nameof(PluginTrigger.Message)).Value.Name == "Update"); var letsAdjustThisOne = updateRows.First(); //set no not all preimage fields letsAdjustThisOne.GetBooleanFieldFieldViewModel(nameof(PluginTrigger.PreImageAllFields)).Value = false; //set some arbitrary other image name letsAdjustThisOne.GetStringFieldFieldViewModel(nameof(PluginTrigger.PreImageName)).Value = "FooOthername"; //set some specific fields in the preimage var preImageFieldsField = letsAdjustThisOne.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.PreImageFields)); SelectItems(preImageFieldsField, 1, 3); //set some specific filtering attributes var filteringAttributesField = letsAdjustThisOne.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.FilteringFields)); SelectItems(filteringAttributesField, 1, 3); //set impersonating user var impersonatingUserField = letsAdjustThisOne.GetLookupFieldFieldViewModel(nameof(PluginTrigger.SpecificUserContext)); impersonatingUserField.SelectedItem = impersonatingUserField.ItemsSource.First(p => p.Record?.Id == CurrentUserId.ToString()); //save Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); //verify still 3 triggers triggers = GetPluginTriggers(assemblyRecord); Assert.AreEqual(3, triggers.Count()); //get the record we updated var updatedTriggerMatches = triggers.Where(t => t.GetStringField(Fields.sdkmessageprocessingstep_.filteringattributes) != null); Assert.AreEqual(1, updatedTriggerMatches.Count()); var updatedTrigger = updatedTriggerMatches.First(); //verify the filtering and image fields we set got saved correctly Assert.IsNotNull(updatedTrigger.GetStringField(Fields.sdkmessageprocessingstep_.filteringattributes)); Assert.AreEqual(CurrentUserId.ToString(), updatedTrigger.GetLookupId(Fields.sdkmessageprocessingstep_.impersonatinguserid)); image = XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, updatedTrigger.Id); Assert.IsNotNull(image); Assert.IsNotNull(image.GetStringField(Fields.sdkmessageprocessingstepimage_.attributes)); Assert.AreEqual("FooOthername", image.GetStringField(Fields.sdkmessageprocessingstepimage_.entityalias)); //lets just verify if we go through te dialog without touching the record we adjusted that it is still the same after the save dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); updatedTrigger = XrmRecordService.Get(updatedTrigger.Type, updatedTrigger.Id); Assert.IsNotNull(updatedTrigger.GetStringField(Fields.sdkmessageprocessingstep_.filteringattributes)); Assert.AreEqual(CurrentUserId.ToString(), updatedTrigger.GetLookupId(Fields.sdkmessageprocessingstep_.impersonatinguserid)); XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, triggers.First().Id); Assert.IsNotNull(image); Assert.IsNotNull(image.GetStringField(Fields.sdkmessageprocessingstepimage_.attributes)); Assert.AreEqual("FooOthername", image.GetStringField(Fields.sdkmessageprocessingstepimage_.entityalias)); //now lets verify deletion of an image if changed to not have one (image deleted) as well as clear impersonating user dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); triggersSubGrid = entryViewModel.SubGrids.First(); letsAdjustThisOne = triggersSubGrid.GridRecords.First(r => r.GetRecord().GetStringField(nameof(PluginTrigger.Id)) == updatedTrigger.Id); impersonatingUserField = letsAdjustThisOne.GetLookupFieldFieldViewModel(nameof(PluginTrigger.SpecificUserContext)); impersonatingUserField.SelectedItem = impersonatingUserField.ItemsSource.First(p => p.Record == null); //set no not all preimage fields letsAdjustThisOne.GetBooleanFieldFieldViewModel(nameof(PluginTrigger.PreImageAllFields)).Value = false; //set no fields on the preimage preImageFieldsField = letsAdjustThisOne.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.PreImageFields)); DeselectAll(preImageFieldsField); //save Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); //verify now no impersonation updatedTrigger = XrmRecordService.Get(updatedTrigger.Type, updatedTrigger.Id); Assert.IsNull(updatedTrigger.GetLookupId(Fields.sdkmessageprocessingstep_.impersonatinguserid)); //verify no image image = XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, updatedTrigger.Id); Assert.IsNull(image); //lets just verify if we go through te dialog without touching the record still doesn't have one dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); //verify still no impersonation updatedTrigger = XrmRecordService.Get(updatedTrigger.Type, updatedTrigger.Id); Assert.IsNull(updatedTrigger.GetLookupId(Fields.sdkmessageprocessingstep_.impersonatinguserid)); //verify still no image image = XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, updatedTrigger.Id); Assert.IsNull(image); //add the image again dialog = new ManagePluginTriggersDialog(CreateDialogController(), new FakeVisualStudioService(), XrmRecordService, packageSettings); dialog.Controller.BeginDialog(); entryViewModel = (ObjectEntryViewModel)dialog.Controller.UiItems.First(); triggersSubGrid = entryViewModel.SubGrids.First(); letsAdjustThisOne = triggersSubGrid.GridRecords.First(r => r.GetRecord().GetStringField(nameof(PluginTrigger.Id)) == updatedTrigger.Id); //set no not all preimage fields letsAdjustThisOne.GetBooleanFieldFieldViewModel(nameof(PluginTrigger.PreImageAllFields)).Value = true; //save Assert.IsTrue(entryViewModel.Validate()); entryViewModel.OnSave(); //verify image created image = XrmRecordService.GetFirst(Entities.sdkmessageprocessingstepimage, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, updatedTrigger.Id); Assert.IsNotNull(image); Assert.IsNull(image.GetStringField(Fields.sdkmessageprocessingstepimage_.attributes)); var solutionComponents = XrmRecordService.GetSolutionComponents(packageSettings.Solution.Id, OptionSets.SolutionComponent.ObjectTypeCode.SDKMessageProcessingStep); Assert.IsTrue(triggers.All(t => solutionComponents.Contains(t.Id))); }
public void XrmCrudModuleTestScript() { // this script runs through several scenarios in the crud module // opening and running quickfind // opening a record updating a field and saving // selecting 2 records and doing a bulk update on them // doing a bulk update on all records // selecting 2 records and doing a bulk delete on them // doing a bulk delete on all records // create a new record // create a new record with an error thrown DeleteAll(Entities.account); var count = XrmRecordService.GetFirstX(Entities.account, 3, null, null).Count(); while (count < 3) { CreateAccount(); count++; } //Create test app and load query var app = CreateAndLoadTestApplication <XrmCrudModule>(); var settingsFolder = app.Controller.SettingsPath; if (settingsFolder != null) { FileUtility.DeleteFiles(settingsFolder); } //okay adding this here because I added a redirect to connection entry if none is entered var xrmRecordService = app.Controller.ResolveType <XrmRecordService>(); //okay this is the service which will get resolve by the dialog - so lets clear out its connection details //then the dialog should redirect to entry var originalConnection = xrmRecordService.XrmRecordConfiguration; xrmRecordService.XrmRecordConfiguration = new XrmRecordConfiguration(); var dialog = app.NavigateToDialog <XrmCrudModule, XrmCrudDialog>(); //okay we should have been directed to a connection entry var connectionEntryViewModel = dialog.Controller.UiItems[0] as ObjectEntryViewModel; var newConnection = connectionEntryViewModel.GetObject() as SavedXrmRecordConfiguration; newConnection.AuthenticationProviderType = originalConnection.AuthenticationProviderType; newConnection.DiscoveryServiceAddress = originalConnection.DiscoveryServiceAddress; newConnection.OrganizationUniqueName = originalConnection.OrganizationUniqueName; newConnection.Domain = originalConnection.Domain; newConnection.Username = originalConnection.Username; newConnection.Password = originalConnection.Password; newConnection.Name = "RedirectScriptEntered"; connectionEntryViewModel.SaveButtonViewModel.Invoke(); //cool if has worked then now we will be at the query view model with the connection var queryViewModel = dialog.Controller.UiItems[0] as QueryViewModel; Assert.IsNotNull(queryViewModel); //lets just verify the connection was saved as well var savedConnections = app.Controller.ResolveType <ISavedXrmConnections>(); Assert.IsTrue(savedConnections.Connections.Any(c => c.Name == "RedirectScriptEntered")); var appXrmRecordService = app.Controller.ResolveType <XrmRecordService>(); Assert.IsTrue(appXrmRecordService.XrmRecordConfiguration.ToString() == "RedirectScriptEntered"); var appXrmRecordConnection = app.Controller.ResolveType <IXrmRecordConfiguration>(); Assert.IsTrue(appXrmRecordConnection.ToString() == "RedirectScriptEntered"); var savedSetingsManager = app.Controller.ResolveType <ISettingsManager>(); var savedXrmRecordService = savedSetingsManager.Resolve <SavedXrmConnections.SavedXrmConnections>(); Assert.IsTrue(appXrmRecordService.XrmRecordConfiguration.ToString() == "RedirectScriptEntered"); var savedXrmRecordConnection = savedSetingsManager.Resolve <XrmRecordConfiguration>(); //select account type and run query queryViewModel.SelectedRecordType = queryViewModel.RecordTypeItemsSource.First(r => r.Key == Entities.account); queryViewModel.DynamicGridViewModel.GetButton("QUERY").Invoke(); Assert.IsTrue(queryViewModel.GridRecords.Any()); //select first record and open it queryViewModel.DynamicGridViewModel.EditRow(queryViewModel.DynamicGridViewModel.GridRecords.First()); var editAccountForm = queryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(editAccountForm); editAccountForm.LoadFormSections(); var id = editAccountForm.GetRecord().Id; //set its name var newName = "Updated " + DateTime.Now.ToFileTime(); editAccountForm.GetStringFieldFieldViewModel(Fields.account_.name).Value = newName; Assert.IsTrue(editAccountForm.ChangedPersistentFields.Count == 1); Assert.IsTrue(editAccountForm.ChangedPersistentFields.First() == Fields.account_.name); //save editAccountForm.SaveButtonViewModel.Invoke(); Assert.IsFalse(queryViewModel.ChildForms.Any()); //verify record updated var record = XrmRecordService.Get(Entities.account, id); Assert.AreEqual(newName, record.GetStringField(Fields.account_.name)); //now do bulk updates selected //select 2 record for bulk update queryViewModel.GridRecords.First().IsSelected = true; queryViewModel.GridRecords.ElementAt(1).IsSelected = true; id = queryViewModel.GridRecords.First().GetRecord().Id; var id2 = queryViewModel.GridRecords.ElementAt(1).GetRecord().Id; //this triggered by ui event queryViewModel.DynamicGridViewModel.OnSelectionsChanged(); //trigger and enter bulk update queryViewModel.DynamicGridViewModel.GetButton("BULKUPDATESELECTED").Invoke(); var newAddressLine1 = "Bulk Selected " + DateTime.Now.ToFileTime(); DoBulkUpdate(dialog, newAddressLine1, Fields.account_.address1_line1); //verify records updated record = XrmRecordService.Get(Entities.account, id); Assert.AreEqual(newAddressLine1, record.GetStringField(Fields.account_.address1_line1)); record = XrmRecordService.Get(Entities.account, id2); Assert.AreEqual(newAddressLine1, record.GetStringField(Fields.account_.address1_line1)); Assert.IsFalse(queryViewModel.ChildForms.Any()); //now do bulk updates all queryViewModel.DynamicGridViewModel.GetButton("BULKUPDATEALL").Invoke(); newAddressLine1 = "Bulk Update All " + DateTime.Now.ToFileTime(); DoBulkUpdate(dialog, newAddressLine1, Fields.account_.address1_line1); var allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); foreach (var account in allAccounts) { Assert.AreEqual(newAddressLine1, account.GetStringField(Fields.account_.address1_line1)); } //now do bulk copy field value //select 2 record for bulk copy field value queryViewModel.GridRecords.First().IsSelected = true; queryViewModel.GridRecords.ElementAt(1).IsSelected = true; id = queryViewModel.GridRecords.First().GetRecord().Id; id2 = queryViewModel.GridRecords.ElementAt(1).GetRecord().Id; record = XrmRecordService.Get(Entities.account, id); record.SetField(Fields.account_.description, "WTF", XrmRecordService); XrmRecordService.Update(record, new[] { Fields.account_.description }); record = XrmRecordService.Get(Entities.account, id2); Assert.IsNull(record.GetStringField(Fields.account_.description)); //this triggered by ui event queryViewModel.DynamicGridViewModel.OnSelectionsChanged(); //trigger and enter bulk update queryViewModel.DynamicGridViewModel.GetButton("BULKCOPYFIELDVALUESELECTED").Invoke(); DoBulkCopyFieldValue(dialog, Fields.account_.name, Fields.account_.description); //verify records updated //this dude doesnt get copied because already populated record = XrmRecordService.Get(Entities.account, id); Assert.AreEqual("WTF", record.GetStringField(Fields.account_.description)); record = XrmRecordService.Get(Entities.account, id2); Assert.AreEqual(record.GetStringField(Fields.account_.name), record.GetStringField(Fields.account_.description)); Assert.IsFalse(queryViewModel.ChildForms.Any()); //now do bulk copy field value all queryViewModel.DynamicGridViewModel.GetButton("BULKCOPYFIELDVALUEALL").Invoke(); DoBulkCopyFieldValue(dialog, Fields.account_.name, Fields.account_.description); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); //this dude doesnt get copied because already populated Assert.IsTrue(allAccounts.Any(a => a.GetStringField(Fields.account_.description) == "WTF")); foreach (var account in allAccounts) { if (account.Id == id) { Assert.AreEqual("WTF", account.GetStringField(Fields.account_.description)); } else { Assert.AreEqual(account.GetStringField(Fields.account_.name), account.GetStringField(Fields.account_.description)); } } //okay lets just verify options //do bulk copy field with overwrite queryViewModel.DynamicGridViewModel.GetButton("BULKCOPYFIELDVALUEALL").Invoke(); DoBulkCopyFieldValue(dialog, Fields.account_.name, Fields.account_.description, overwriteIfPopulated: true); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); foreach (var account in allAccounts) { //all got updated Assert.AreEqual(account.GetStringField(Fields.account_.name), account.GetStringField(Fields.account_.description)); account.SetField(Fields.account_.description, "WTF", XrmRecordService); XrmRecordService.Update(account, new[] { Fields.account_.description }); //set the name null to check doesnt copy next call if (account.Id == id) { account.SetField(Fields.account_.name, null, XrmRecordService); XrmRecordService.Update(account, new[] { Fields.account_.name }); } } //do another and verify the desciption wasnt cleared queryViewModel.DynamicGridViewModel.GetButton("BULKCOPYFIELDVALUEALL").Invoke(); DoBulkCopyFieldValue(dialog, Fields.account_.name, Fields.account_.description, overwriteIfPopulated: true); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.IsTrue(allAccounts.Any(a => a.GetStringField(Fields.account_.name) == null)); foreach (var account in allAccounts) { Assert.IsNotNull(account.GetStringField(Fields.account_.description)); } //do one more with include nulls and verify we now have an empty description queryViewModel.DynamicGridViewModel.GetButton("BULKCOPYFIELDVALUEALL").Invoke(); DoBulkCopyFieldValue(dialog, Fields.account_.name, Fields.account_.description, copyIfNull: true, overwriteIfPopulated: true); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.IsTrue(allAccounts.Any(a => a.GetStringField(Fields.account_.description) == null)); //select 2 record for bulk delete queryViewModel.GridRecords.First().IsSelected = true; queryViewModel.GridRecords.ElementAt(1).IsSelected = true; id = queryViewModel.GridRecords.First().GetRecord().Id; id2 = queryViewModel.GridRecords.ElementAt(1).GetRecord().Id; //this triggered by ui event queryViewModel.DynamicGridViewModel.OnSelectionsChanged(); //trigger and enter bulk update queryViewModel.DynamicGridViewModel.GetButton("BULKDELETESELECTED").Invoke(); DoBulkDelete(dialog); //verify records deleted Assert.IsFalse(queryViewModel.ChildForms.Any()); Assert.IsNull(XrmRecordService.Get(Entities.account, id)); Assert.IsNull(XrmRecordService.Get(Entities.account, id2)); //now do bulk delete all queryViewModel.DynamicGridViewModel.GetButton("BULKDELETEALL").Invoke(); DoBulkDelete(dialog); allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.AreEqual(0, allAccounts.Count()); //verify records deleted //add a new row enytering it into the child form queryViewModel.DynamicGridViewModel.AddRow(); EnterNewRecord(dialog); //verify created allAccounts = XrmRecordService.RetrieveAll(Entities.account, null); Assert.AreEqual(1, allAccounts.Count()); //okay well this just verifies an error is thrown to the user if the create fails (i set an explicit duplicate id) queryViewModel.DynamicGridViewModel.AddRow(); var entryForm = dialog.QueryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(entryForm); entryForm.LoadFormSections(); entryForm.GetFieldViewModel(Fields.account_.accountid).ValueObject = allAccounts.First().Id; try { entryForm.SaveButtonViewModel.Invoke(); } catch (Exception ex) { Assert.IsTrue(ex is FakeUserMessageException); } //verify we are still on the child entry form entryForm = dialog.QueryViewModel.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(entryForm); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); }
public void DeploymentExportXmlModuleTestExportWithSpecificValues() { DeleteAll(Entities.account); var account = CreateRecordAllFieldsPopulated(Entities.account); FileUtility.DeleteFiles(TestingFolder); var accountRecord = XrmRecordService.Get(account.LogicalName, account.Id.ToString()); var application = CreateAndLoadTestApplication <ExportXmlModule>(); application.AddModule <SavedRequestModule>(); var instance = new ExportXmlRequest(); instance.IncludeNotes = true; instance.IncludeNNRelationshipsBetweenEntities = true; instance.Folder = new Folder(TestingFolder); instance.RecordTypesToExport = new[] { new ExportRecordType() { Type = ExportType.AllRecords, RecordType = new RecordType(Entities.account, Entities.account), SpecificRecordsToExport = new LookupSetting[0] } }; var entryForm = application.NavigateToDialogModuleEntryForm <ExportXmlModule, ExportXmlDialog>(); application.EnterObject(instance, entryForm); var recordTypesGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport)); var row = recordTypesGrid.GridRecords.First(); row.EditRow(); var exportTypeEntry = entryForm.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(exportTypeEntry); exportTypeEntry.LoadFormSections(); //okay so at this point we aere in the export type form //need to add a row to the explicit value grid which will open the form var specificValuesGrid = exportTypeEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.ExplicitValuesToSet)); specificValuesGrid.AddRow(); var specificValueEntry = exportTypeEntry.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(specificValueEntry); specificValueEntry.LoadFormSections(); var fieldSelectionViewModel = specificValueEntry.GetRecordFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.FieldToSet)); var clearValueViewModel = specificValueEntry.GetBooleanFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ClearValue)); //select several field types and verify the field control changes to the correct type for that field fieldSelectionViewModel.Value = fieldSelectionViewModel.ItemsSource.First(f => f.Key == Fields.account_.customertypecode); Assert.IsTrue(specificValueEntry.GetFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)) is PicklistFieldViewModel); Assert.IsTrue(specificValueEntry.GetPicklistFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)).ItemsSource.Any()); fieldSelectionViewModel.Value = fieldSelectionViewModel.ItemsSource.First(f => f.Key == Fields.account_.primarycontactid); Assert.IsTrue(specificValueEntry.GetFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)) is LookupFieldViewModel); specificValueEntry.GetLookupFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)).Search(); Assert.IsTrue(specificValueEntry.GetLookupFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)).LookupGridViewModel.DynamicGridViewModel.GridRecords.Any()); //verify the field value hidden if we select to clear the value clearValueViewModel.Value = true; Assert.IsFalse(specificValueEntry.GetFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)).IsVisible); clearValueViewModel.Value = false; //okay so this is the specific field and value we will set var fakeExplicitExportValue = "fakeExplicitExportValue"; fieldSelectionViewModel.Value = fieldSelectionViewModel.ItemsSource.First(f => f.Key == Fields.account_.address1_line1); Assert.IsTrue(specificValueEntry.GetFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)) is StringFieldViewModel); var descriptionViewModel = specificValueEntry.GetStringFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)); descriptionViewModel.Value = fakeExplicitExportValue; Assert.IsTrue(specificValueEntry.Validate()); specificValueEntry.SaveButtonViewModel.Invoke(); Assert.IsFalse(exportTypeEntry.ChildForms.Any()); //okay lets add an explicit lookup value as well specificValuesGrid = exportTypeEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.ExplicitValuesToSet)); specificValuesGrid.AddRow(); specificValueEntry = exportTypeEntry.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(specificValueEntry); specificValueEntry.LoadFormSections(); fieldSelectionViewModel = specificValueEntry.GetRecordFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.FieldToSet)); fieldSelectionViewModel.Value = fieldSelectionViewModel.ItemsSource.First(f => f.Key == Fields.account_.primarycontactid); var lookupFieldViewModel = specificValueEntry.GetLookupFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)); lookupFieldViewModel.Search(); Assert.IsTrue(lookupFieldViewModel.LookupGridViewModel.DynamicGridViewModel.GridRecords.Any()); lookupFieldViewModel.LookupGridViewModel.DynamicGridViewModel.SelectedRow = lookupFieldViewModel.LookupGridViewModel.DynamicGridViewModel.GridRecords.First(); lookupFieldViewModel.OnRecordSelected(lookupFieldViewModel.LookupGridViewModel.DynamicGridViewModel.GridRecords.First().Record); Assert.IsTrue(specificValueEntry.Validate()); specificValueEntry.SaveButtonViewModel.Invoke(); Assert.IsFalse(exportTypeEntry.ChildForms.Any()); //okay lets add an explicit picklist value as well specificValuesGrid = exportTypeEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.ExplicitValuesToSet)); specificValuesGrid.AddRow(); specificValueEntry = exportTypeEntry.ChildForms.First() as RecordEntryFormViewModel; Assert.IsNotNull(specificValueEntry); specificValueEntry.LoadFormSections(); fieldSelectionViewModel = specificValueEntry.GetRecordFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.FieldToSet)); fieldSelectionViewModel.Value = fieldSelectionViewModel.ItemsSource.First(f => f.Key == Fields.account_.customertypecode); var picklistFieldViewModel = specificValueEntry.GetPicklistFieldFieldViewModel(nameof(ExportRecordType.ExplicitFieldValues.ValueToSet)); Assert.IsTrue(picklistFieldViewModel.ItemsSource.Any()); picklistFieldViewModel.Value = picklistFieldViewModel.ItemsSource.First(); Assert.IsTrue(specificValueEntry.Validate()); specificValueEntry.SaveButtonViewModel.Invoke(); Assert.IsFalse(exportTypeEntry.ChildForms.Any()); Assert.IsTrue(exportTypeEntry.Validate()); exportTypeEntry.SaveButtonViewModel.Invoke(); Assert.IsFalse(entryForm.ChildForms.Any()); //okay lets verify save and load object as well //initially the dynamic object property for setting san explicit type //did not seralise due to known types in the serialiser //lets remove any saved requests as this part relies on it being the only saved one var savedRequests = new SavedSettings() { SavedRequests = new object[0] }; var settingsManager = application.Controller.ResolveType <ISettingsManager>(); settingsManager.SaveSettingsObject(savedRequests, typeof(ExportXmlRequest)); //trigger save request var saveRequestButton = entryForm.GetButton("SAVEREQUEST"); saveRequestButton.Invoke(); //enter and save details var saveRequestForm = application.GetSubObjectEntryViewModel(entryForm); var detailsEntered = new SaveAndLoadFields() { Name = "TestName" }; application.EnterAndSaveObject(detailsEntered, saveRequestForm); Assert.IsFalse(entryForm.ChildForms.Any()); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); //trigger load request var loadRequestButton = entryForm.GetButton("LOADREQUEST"); loadRequestButton.Invoke(); var loadRequestForm = application.GetSubObjectEntryViewModel(entryForm); //select and load the saved request var subGrid = loadRequestForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests)); Assert.IsTrue(subGrid.GridRecords.Count() == 1); subGrid.GridRecords.First().IsSelected = true; var loadButton = subGrid.DynamicGridViewModel.GetButton("LOADREQUEST"); loadButton.Invoke(); //verify loads Assert.IsFalse(entryForm.ChildForms.Any()); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); //this one will invoke the export Assert.IsTrue(entryForm.Validate()); entryForm.SaveButtonViewModel.Invoke(); //verify the exported records had the explicit value we set in them var importServoice = new ImportXmlService(XrmRecordService); var loadEntities = importServoice.LoadEntitiesFromXmlFiles(TestingFolder); foreach (var entity in loadEntities) { Assert.AreEqual(fakeExplicitExportValue, entity.GetStringField(Fields.account_.address1_line1)); } }
protected override void CompleteDialogExtention() { var responses = new List <PluginTriggerError>(); //delete any removed plugins var removedPlugins = SdkMessageStepsPre.Where(smsp => EntryObject.Triggers.All(pt => pt.Id != smsp.Id)).ToArray(); var deletions = XrmRecordService.DeleteInCrm(removedPlugins); foreach (var trigger in deletions.Errors) { var error = new PluginTriggerError() { Type = "Deletion", Name = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid), Exception = trigger.Value }; responses.Add(error); } //load the filter entities which exist for each entity type, message combination var filters = EntryObject.Triggers.Select(t => { var filter = new Filter(); filter.AddCondition(Fields.sdkmessagefilter_.primaryobjecttypecode, ConditionType.Equal, t.RecordType == null ? "none" : t.RecordType.Key); filter.AddCondition(Fields.sdkmessagefilter_.sdkmessageid, ConditionType.Equal, t.Message.Id); return(filter); }).ToArray(); var pluginFilters = XrmRecordService.RetrieveAllOrClauses(Entities.sdkmessagefilter, filters); //unload the triggers into an entity object referencing it in a dictionary var unloadedObjects = new Dictionary <IRecord, PluginTrigger>(); foreach (var item in EntryObject.Triggers) { var matchingPluginFilters = pluginFilters.Where(f => f.GetLookupId(Fields.sdkmessagefilter_.sdkmessageid) == item.Message.Id && ((item.RecordType == null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == "none") || (item.RecordType != null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == item.RecordType.Key))) .ToArray(); var record = XrmRecordService.NewRecord(Entities.sdkmessageprocessingstep); var name = string.Format("{0} {1} {2} {3} {4}", item.Plugin, item.RecordType?.Key ?? "none", item.Message, item.Stage, item.Mode).Left(XrmRecordService.GetMaxLength(Fields.sdkmessageprocessingstep_.name, Entities.sdkmessageprocessingstep)); record.SetField(Fields.sdkmessageprocessingstep_.name, name, XrmRecordService); record.SetField(Fields.sdkmessageprocessingstep_.rank, item.Rank, XrmRecordService); if (item.Stage != null) { record.SetField(Fields.sdkmessageprocessingstep_.stage, (int)item.Stage, XrmRecordService); } if (item.Mode != null) { record.SetField(Fields.sdkmessageprocessingstep_.mode, (int)item.Mode, XrmRecordService); } record.SetField(Fields.sdkmessageprocessingstep_.plugintypeid, item.Plugin, XrmRecordService); record.SetField(Fields.sdkmessageprocessingstep_.sdkmessagefilterid, !matchingPluginFilters.Any() ? null : matchingPluginFilters.First().ToLookup(), XrmRecordService); record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageid, item.Message, XrmRecordService); record.SetField(Fields.sdkmessageprocessingstep_.impersonatinguserid, item.SpecificUserContext == null || item.SpecificUserContext.Id == null ? null : item.SpecificUserContext, XrmRecordService); if (item.Id != null) { record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid, item.Id, XrmRecordService); } record.SetField(Fields.sdkmessageprocessingstep_.asyncautodelete, item.Mode == PluginTrigger.PluginMode.Asynchronous, XrmRecordService); record.SetField(Fields.sdkmessageprocessingstep_.filteringattributes, item.FilteringFields != null && item.FilteringFields.Any() ? string.Join(",", item.FilteringFields.OrderBy(r => r.Key).Select(r => r.Key)) : null, XrmRecordService); unloadedObjects.Add(record, item); } //submit them to crm create/update var triggerLoads = XrmRecordService.LoadIntoCrm(unloadedObjects.Keys, Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid); var updatesAndDeletes = unloadedObjects.Keys.Where( r => new[] { "Update", "Delete" }.Contains( r.GetLookupName(Fields.sdkmessageprocessingstep_.sdkmessageid))) .ToArray(); var solutionItemsToAdd = new List <string>(); //update/delete pre-images var imagesToCreateOrUpdate = new List <IRecord>(); var imagesToDelete = new List <IRecord>(); foreach (var item in updatesAndDeletes .Where(i => !triggerLoads.Errors.Keys.Contains(CompletionItem))) { var matchingPluginTrigger = unloadedObjects[item]; //the plugin will only have an image if all fields, or there are specific fields selected var hasImage = matchingPluginTrigger.PreImageAllFields || (matchingPluginTrigger.PreImageFields != null && matchingPluginTrigger.PreImageFields.Any()); if (!hasImage) { //delete the existing image if is has been changed to not have an image if (matchingPluginTrigger.PreImageId != null) { try { imagesToDelete.Add(XrmRecordService.Get(Entities.sdkmessageprocessingstepimage, matchingPluginTrigger.PreImageId)); solutionItemsToAdd.Add(matchingPluginTrigger.Id); } catch (Exception ex) { var error = new PluginTriggerError() { Type = "Image Deletion", Name = matchingPluginTrigger.PreImageId, Exception = ex }; responses.Add(error); } } } else { //set the details to create/update in the pre-image var isUpdate = triggerLoads.Updated.Contains(item); var imageRecord = XrmRecordService.NewRecord(Entities.sdkmessageprocessingstepimage); imageRecord.Id = matchingPluginTrigger.PreImageId; if (matchingPluginTrigger.PreImageId != null) { imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageid, matchingPluginTrigger.PreImageId, XrmRecordService); } imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.name, matchingPluginTrigger.PreImageName, XrmRecordService); imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.entityalias, matchingPluginTrigger.PreImageName, XrmRecordService); imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.messagepropertyname, "Target", XrmRecordService); imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, XrmRecordService.ToLookup(item), XrmRecordService); imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.imagetype, OptionSets.SdkMessageProcessingStepImage.ImageType.PreImage, XrmRecordService); var attributesString = matchingPluginTrigger.PreImageAllFields || matchingPluginTrigger.PreImageFields == null || !matchingPluginTrigger.PreImageFields.Any() ? null : string.Join(",", matchingPluginTrigger.PreImageFields.Select(f => f.Key).OrderBy(s => s).ToArray()); imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.attributes, attributesString, XrmRecordService); imagesToCreateOrUpdate.Add(imageRecord); } } //submit create/update/deletion of pre-images var imageLoads = XrmRecordService.LoadIntoCrm(imagesToCreateOrUpdate, Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageid); var imageDeletions = XrmRecordService.DeleteInCrm(imagesToDelete); //add any errors to the response object foreach (var trigger in imageDeletions.Errors) { var error = new PluginTriggerError() { Type = "Image Deletion", Name = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid), Exception = trigger.Value }; responses.Add(error); } foreach (var trigger in triggerLoads.Errors) { var error = new PluginTriggerError() { Type = "Plugin Step", Name = trigger.Key.GetStringField(Fields.sdkmessageprocessingstep_.name), Exception = trigger.Value }; responses.Add(error); } foreach (var trigger in imageLoads.Errors) { var error = new PluginTriggerError() { Type = "Image", Name = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid), Exception = trigger.Value }; responses.Add(error); } //add plugin steps to the solution var componentType = OptionSets.SolutionComponent.ObjectTypeCode.SDKMessageProcessingStep; solutionItemsToAdd.AddRange(triggerLoads.Created.Union(triggerLoads.Updated).Select(r => r.Id).ToList()); var imagesReferences = imageLoads.Created.Union(imageLoads.Updated) .Select(i => i.GetLookupId(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid)) .Where(id => !string.IsNullOrWhiteSpace(id)); solutionItemsToAdd.AddRange(imagesReferences); if (PackageSettings.AddToSolution) { XrmRecordService.AddSolutionComponents(PackageSettings.Solution.Id, componentType, solutionItemsToAdd); } CompletionItem = new Completionresponse { Errors = responses }; if (responses.Any()) { CompletionMessage = "There Were Errors Thrown Updating The Plugins"; } else { CompletionMessage = "Plugins Updated"; } }
public void DeploymentExportXmlModuleTestExportWithBulkAddToGridField() { DeleteAll(Entities.account); var account = CreateRecordAllFieldsPopulated(Entities.account); FileUtility.DeleteFiles(TestingFolder); var accountRecord = XrmRecordService.Get(account.LogicalName, account.Id.ToString()); var application = CreateAndLoadTestApplication <ExportXmlModule>(); var instance = new ExportXmlRequest(); instance.IncludeNotes = true; instance.IncludeNNRelationshipsBetweenEntities = true; instance.Folder = new Folder(TestingFolder); instance.RecordTypesToExport = new[] { new ExportRecordType() { Type = ExportType.AllRecords, RecordType = new RecordType(Entities.account, Entities.account), SpecificRecordsToExport = new LookupSetting[0] } }; var entryForm = application.NavigateToDialogModuleEntryForm <ExportXmlModule, ExportXmlDialog>(); application.EnterObject(instance, entryForm); var recordTypesGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport)); //okay so we will be doing bulk adds on fields in this grid row var row = recordTypesGrid.GridRecords.First(); row.GetPicklistFieldFieldViewModel(nameof(ExportRecordType.Type)).Value = PicklistOption.EnumToPicklistOption(ExportType.SpecificRecords); //first do it for an Enumerable lookup field (specific records for export) var specificRecordsGridField = row.GetEnumerableFieldViewModel(nameof(ExportRecordType.SpecificRecordsToExport)); Assert.IsTrue(string.IsNullOrWhiteSpace(specificRecordsGridField.StringDisplay)); Assert.IsNull(specificRecordsGridField.DynamicGridViewModel); Assert.IsNotNull(specificRecordsGridField.BulkAddButton); //trigger the add multiple option specificRecordsGridField.BulkAddButton.Invoke(); var bulkAddForm = entryForm.ChildForms.First() as QueryViewModel; //verify a quickfind finds a record bulkAddForm.QuickFindText = account.GetStringField(Fields.account_.name); bulkAddForm.QuickFind(); //select and add bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true; //this triggered by the grid event bulkAddForm.DynamicGridViewModel.OnSelectionsChanged(); //this is supposed to be the add selected button bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke(); //verify we now have a record selected and displayed for the field Assert.IsFalse(string.IsNullOrWhiteSpace(specificRecordsGridField.StringDisplay)); //now do it for an Enumerable field (fields for inlcusion) //this sets it in context row.GetBooleanFieldFieldViewModel(nameof(ExportRecordType.IncludeAllFields)).Value = false; var excludeFieldsGrid = row.GetEnumerableFieldViewModel(nameof(ExportRecordType.IncludeOnlyTheseFields)); Assert.IsTrue(string.IsNullOrWhiteSpace(excludeFieldsGrid.StringDisplay)); //trigger the add multiple option excludeFieldsGrid.BulkAddButton.Invoke(); bulkAddForm = entryForm.ChildForms.First() as QueryViewModel; Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.QuickFindText = Fields.account_.name; bulkAddForm.QuickFind(); Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true; //this triggered by the grid event bulkAddForm.DynamicGridViewModel.OnSelectionsChanged(); //this is supposed to be the add selected button bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke(); Assert.IsFalse(entryForm.ChildForms.Any()); //verify we now have a record selected and displayed for the field Assert.IsFalse(string.IsNullOrWhiteSpace(excludeFieldsGrid.StringDisplay)); }
public void DeploymentExportXmlModuleTestExportWithBulkAddToGridAndQuery() { DeleteAll(Entities.account); var account = CreateRecordAllFieldsPopulated(Entities.account); FileUtility.DeleteFiles(TestingFolder); var accountRecord = XrmRecordService.Get(account.LogicalName, account.Id.ToString()); //okay create/navigate to a new entry form entering an ExportXmlRequest var application = CreateAndLoadTestApplication <ExportXmlModule>(); var instance = new ExportXmlRequest(); instance.IncludeNotes = true; instance.IncludeNNRelationshipsBetweenEntities = true; instance.Folder = new Folder(TestingFolder); instance.RecordTypesToExport = new[] { new ExportRecordType() { Type = ExportType.SpecificRecords, RecordType = new RecordType(Entities.account, Entities.account), SpecificRecordsToExport = new [] { new LookupSetting() { Record = accountRecord.ToLookup() } } } }; var entryForm = application.NavigateToDialogModuleEntryForm <ExportXmlModule, ExportXmlDialog>(); application.EnterObject(instance, entryForm); //get the record types subgrid var recordTypesGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport)); var row = recordTypesGrid.GridRecords.First(); //edit the accounts export record row row.EditRow(); var specificRecordEntry = entryForm.ChildForms.First() as RecordEntryFormViewModel; specificRecordEntry.LoadFormSections(); var specificRecordsGrid = specificRecordEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.SpecificRecordsToExport)); //delete the row we added specificRecordsGrid.GridRecords.First().DeleteRow(); Assert.IsFalse(specificRecordsGrid.GridRecords.Any()); //now add using the add multiple option var customFunction = specificRecordsGrid.DynamicGridViewModel.AddMultipleRowButton; customFunction.Invoke(); var bulkAddForm = specificRecordEntry.ChildForms.First() as QueryViewModel; //verify a quickfind finds a record bulkAddForm.QuickFindText = account.GetStringField(Fields.account_.name); bulkAddForm.QuickFind(); Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); //now do an and query on every field in the entity and verify it works bulkAddForm.QueryTypeButton.Invoke(); var lastCondition = bulkAddForm.FilterConditions.Conditions.Last(); Assert.AreEqual(Entities.account, lastCondition.GetRecordTypeFieldViewModel(nameof(ConditionViewModel.QueryCondition.RecordType)).Value.Key); var fieldViewModel = lastCondition.GetRecordFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.FieldName)); var validSearchFields = fieldViewModel.ItemsSource.Select(i => i.Key).ToArray(); foreach (var field in validSearchFields) { var fieldvalue = accountRecord.GetField(field); if (fieldvalue != null) { lastCondition = bulkAddForm.FilterConditions.Conditions.Last(); Assert.AreEqual(Entities.account, lastCondition.GetRecordTypeFieldViewModel(nameof(ConditionViewModel.QueryCondition.RecordType)).Value.Key); fieldViewModel = lastCondition.GetRecordFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.FieldName)); fieldViewModel.Value = fieldViewModel.ItemsSource.ToArray().First(i => i.Key == field); var conditionTypeViewModel = lastCondition.GetPicklistFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.ConditionType)); conditionTypeViewModel.Value = conditionTypeViewModel.ItemsSource.First(i => i.Value == ConditionType.Equal.ToString()); var valueViewModel = lastCondition.GetFieldViewModel(nameof(ConditionViewModel.QueryCondition.Value)); valueViewModel.ValueObject = fieldvalue; //bulkAddForm.QuickFind(); //Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); //Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); } } bulkAddForm.QuickFind(); Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); //select and add bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true; //this triggered by the grid event bulkAddForm.DynamicGridViewModel.OnSelectionsChanged(); //this is supposed to be the add selected button bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke(); //and verify the row was added to the records for export Assert.IsTrue(specificRecordsGrid.GridRecords.Any()); //okay now lets do the equivalent for a grid of fields //set this false so the selection of fields is in context specificRecordEntry.GetBooleanFieldFieldViewModel(nameof(ExportRecordType.IncludeAllFields)).Value = false; //get the fields grid and trigger bulk add function var excludeFieldsGrid = specificRecordEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.IncludeOnlyTheseFields)); //now add using the add multiple option excludeFieldsGrid.DynamicGridViewModel.AddMultipleRowButton.Invoke(); bulkAddForm = specificRecordEntry.ChildForms.First() as QueryViewModel; Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.QuickFindText = Fields.account_.name; bulkAddForm.QuickFind(); Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true; //this triggered by the grid event bulkAddForm.DynamicGridViewModel.OnSelectionsChanged(); //this is supposed to be the add selected button bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke(); Assert.IsFalse(specificRecordEntry.ChildForms.Any()); //and verify the row was added to the records for export Assert.IsTrue(excludeFieldsGrid.GridRecords.Any()); specificRecordEntry.SaveButtonViewModel.Invoke(); Assert.IsFalse(entryForm.ChildForms.Any()); //okay now lets to bulk add on the record types grid var subGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport)); subGrid.DynamicGridViewModel.AddMultipleRowButton.Invoke(); bulkAddForm = entryForm.ChildForms.First() as QueryViewModel; Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.QuickFindText = Entities.contact; bulkAddForm.QuickFind(); Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage); Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any()); bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true; //this triggered by the grid event bulkAddForm.DynamicGridViewModel.OnSelectionsChanged(); //this is supposed to be the add selected button bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke(); Assert.IsFalse(entryForm.ChildForms.Any()); }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); var app = CreateAndLoadTestApplication <VsixCreatePackageModule>(); //run the dialog - including a redirect to enter the package settings first var originalConnection = HijackForPackageEntryRedirect(app); var dialog = app.NavigateToDialog <VsixCreatePackageModule, VsixCreatePackageDialog>(); VerifyPackageEntryRedirect(originalConnection, dialog); //okay no should be at the entry the create package details var packageEntry = dialog.Controller.UiItems.First() as ObjectEntryViewModel; //create package request var request = new CreatePackageRequest(); request.HideTypeAndFolder = true; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; app.EnterObject(request, packageEntry); //lets set explicit versions packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.ThisReleaseVersion)).Value = "3.0.0.0"; packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.SetVersionPostRelease)).Value = "4.0.0.0"; if (!packageEntry.Validate()) { throw new Exception(packageEntry.GetValidationSummary()); } packageEntry.SaveButtonViewModel.Invoke(); var createResponse = dialog.CompletionItem as ServiceResponseBase <DataImportResponseItem>; Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //run create package dialog var request = CreatePackageRequest.CreateForCreatePackage(tempFolder, packageSettings.Solution); request.ThisReleaseVersion = "3.0.0.0"; request.SetVersionPostRelease = "4.0.0.0"; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createTestApplication = CreateAndLoadTestApplication <VsixCreatePackageModule>(); var createResponse = createTestApplication.NavigateAndProcessDialog <VsixCreatePackageModule, VsixCreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(request); Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
public void DeploymentCreateAndDeployPackageModuleTest() { DeleteAll(Entities.account); DeleteAll(Entities.contact); var account = CreateAccount(); var solution = XrmRecordService.GetFirst("solution", XrmRecordService.GetPrimaryField("solution"), "Test Components"); Assert.IsNotNull(solution); FileUtility.DeleteFiles(TestingFolder); var createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords, }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); var response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); Assert.IsTrue(FileUtility.GetFiles(TestingFolder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(TestingFolder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(TestingFolder).First())).Any()); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for recreation XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.FolderContainingPackage = new Folder(TestingFolder); deployRequest.Connection = GetSavedXrmRecordConfiguration(); var deployApplication = CreateAndLoadTestApplication <DeployPackageModule>(); response = deployApplication.NavigateAndProcessDialog <DeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //should be recreated account = Refresh(account); createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DeployPackageInto = GetSavedXrmRecordConfiguration(); createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; //error if already .zips on the folder FileUtility.WriteToFile(TestingFolder, "Fake.zip", "FakeContent"); createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); try { createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } FileUtility.DeleteFiles(TestingFolder); FileUtility.DeleteSubFolders(TestingFolder); response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); }