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 app = CreateAndLoadTestApplication <DeployWebResourceModule>(); //run the deploy including a redirect to enter package settings first var originalConnection = HijackForPackageEntryRedirect(app); //lets delete the settings files, then verify they are recreated during the redirect entry var solutionItemsFolder = Path.Combine(VisualStudioService.SolutionDirectory, VisualStudioService.ItemFolderName); FileUtility.DeleteFiles(solutionItemsFolder); var solutionSettingFiles = FileUtility.GetFiles(solutionItemsFolder); Assert.AreEqual(0, solutionSettingFiles.Count()); //run the dialog var dialog = app.NavigateToDialog <DeployWebResourceModule, DeployWebResourceDialog>(); VerifyPackageEntryRedirect(originalConnection, dialog); //verify the 2 settings files recreated solutionSettingFiles = FileUtility.GetFiles(solutionItemsFolder); Assert.AreEqual(2, solutionSettingFiles.Count()); Assert.AreEqual(GetJavaScriptFiles().Count(), GetJavaScriptFileRecords().Count()); var records = GetJavaScriptFileRecords(); var currentComponentIds = XrmRecordService.GetSolutionComponents(dialog.Service.PackageSettings.Solution.Id, OptionSets.SolutionComponent.ObjectTypeCode.WebResource).ToList(); Assert.IsTrue(records.All(r => currentComponentIds.Contains(r.Id))); //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 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()); app = CreateAndLoadTestApplication <DeployWebResourceModule>(); dialog = app.NavigateToDialog <DeployWebResourceModule, DeployWebResourceDialog>(); Assert.AreEqual(GetJavaScriptFiles().Count(), GetJavaScriptFileRecords().Count()); }
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))); }