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 XrmLookupServiceVerifyDoesNotCrashIfReferencedRecordDeleted() { //create object referencing a deleted record var solution = ReCreateTestSolution(); var testEntryObject = new TestXrmObjectEntryClass() { XrmLookupField = solution.ToLookup() }; XrmRecordService.Delete(solution); //verify the form loads and the invalid value is lceared var objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), XrmRecordService)); objectEntryViewModel.LoadFormSections(); Assert.IsNull(testEntryObject.XrmLookupField); //lets just verify the cascade worked if we had not deleted it solution = ReCreateTestSolution(); testEntryObject = new TestXrmObjectEntryClass() { XrmLookupField = solution.ToLookup() }; objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), XrmRecordService)); objectEntryViewModel.LoadFormSections(); Assert.IsNotNull(testEntryObject.XrmLookupField); Assert.IsNotNull(testEntryObject.XrmLookupFieldCascaded); }
public void DeletePluginTriggers(IRecord assemblyRecord) { var pluginTriggers = GetPluginTriggers(assemblyRecord); foreach (var item in pluginTriggers) { XrmRecordService.Delete(item); } }
private void DeleteJavaScriptFileRecords() { var deployed = GetJavaScriptFileRecords(); foreach (var item in deployed) { XrmRecordService.Delete(item); } }
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 DeleteTestPluginAssembly() { var assemblyRecords = GetTestPluginAssemblyRecords(); foreach (var assembly in assemblyRecords) { DeletePluginTriggers(assembly); XrmRecordService.Delete(assembly); } }
public void DeleteTestPluginAssembly(string useAssemblyName = null) { var assemblyRecords = GetTestPluginAssemblyRecords(useAssemblyName); foreach (var assembly in assemblyRecords) { DeletePluginTriggers(assembly); XrmRecordService.Delete(assembly); } }
public void DeleteTestNewLookupPublisher() { while (true) { var test = XrmRecordService.GetFirst(JosephM.Xrm.Schema.Entities.publisher, JosephM.Xrm.Schema.Fields.publisher_.uniquename, "TESTNEWLOOKUPPUBLISHER"); if (test != null) { XrmRecordService.Delete(test); } else { break; } } }
public void DeleteTestNewLookupSolution() { while (true) { var test = XrmRecordService.GetFirst(JosephM.Xrm.Schema.Entities.solution, JosephM.Xrm.Schema.Fields.solution_.uniquename, "TESTNEWLOOKUPSOLUTION"); if (test != null) { XrmRecordService.Delete(test); } else { break; } } }
public IRecord ReCreateTestSolution() { var testSolution = XrmRecordService.GetFirst(JosephM.Xrm.Schema.Entities.solution, JosephM.Xrm.Schema.Fields.solution_.uniquename, "TESTSCRIPTSOLUTION"); if (testSolution != null) { XrmRecordService.Delete(testSolution); } var publisher = XrmRecordService.GetFirst(JosephM.Xrm.Schema.Entities.publisher, JosephM.Xrm.Schema.Fields.publisher_.uniquename, "josephmcgregor"); testSolution = XrmRecordService.NewRecord(JosephM.Xrm.Schema.Entities.solution); testSolution.SetField(JosephM.Xrm.Schema.Fields.solution_.publisherid, publisher.ToLookup(), XrmRecordService); testSolution.SetField(JosephM.Xrm.Schema.Fields.solution_.uniquename, "TESTSCRIPTSOLUTION", XrmRecordService); testSolution.SetField(JosephM.Xrm.Schema.Fields.solution_.friendlyname, "TESTSCRIPTSOLUTION", XrmRecordService); testSolution.SetField(JosephM.Xrm.Schema.Fields.solution_.version, "1.0.0.0", XrmRecordService); testSolution.Id = XrmRecordService.Create(testSolution); return(testSolution); }
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()); }
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(); }
public void SavedRequestModuleTest() { var testApplication = CreateAndLoadTestApplication <SavedRequestModule>(); testApplication.AddModule <TestSavedRequestModule>(); //set to no previously saved ones var savedRequests = new SavedSettings(); var settingsManager = testApplication.Controller.ResolveType <ISettingsManager>(); settingsManager.SaveSettingsObject(savedRequests, typeof(TestSavedRequestDialogRequest)); //navigate to the request and populate the string field var entryForm = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestModule, TestSavedRequestDialog>(); var request = new TestSavedRequestDialogRequest() { SomeArbitraryString = nameof(TestSavedRequestDialogRequest.SomeArbitraryString) }; testApplication.EnterObject(request, entryForm); var loadDropDownButtons = entryForm.CustomFunctions.Where(f => f.Id == "LOADREQUESTDROPDOWN"); Assert.AreEqual(0, loadDropDownButtons.Count()); //trigger save request var saveRequestButton = entryForm.GetButton("SAVEREQUEST"); saveRequestButton.Invoke(); //enter and save details including autoload var saveRequestForm = testApplication.GetSubObjectEntryViewModel(entryForm); var detailsEntered = new SaveAndLoadFields() { Name = "TestName", Autoload = true }; testApplication.EnterAndSaveObject(detailsEntered, saveRequestForm); Assert.IsFalse(entryForm.ChildForms.Any()); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); //okay lets verify that the dropdown of saved requests loaded loadDropDownButtons = entryForm.CustomFunctions.Where(f => f.Id == "LOADREQUESTDROPDOWN"); Assert.AreEqual(1, loadDropDownButtons.Count()); Assert.AreEqual(1, loadDropDownButtons.First().ChildButtons.Count()); Assert.AreEqual("TestName", loadDropDownButtons.First().ChildButtons.First().Label); //reopen app/dialog and verify autoloads testApplication = CreateAndLoadTestApplication <SavedRequestModule>(); testApplication.AddModule <TestSavedRequestModule>(); entryForm = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestModule, TestSavedRequestDialog>(); Assert.AreEqual(nameof(TestSavedRequestDialogRequest.SomeArbitraryString), entryForm.GetStringFieldFieldViewModel(nameof(TestSavedRequestDialogRequest.SomeArbitraryString)).Value); //clear the loaded string value entryForm.GetStringFieldFieldViewModel(nameof(TestSavedRequestDialogRequest.SomeArbitraryString)).Value = "Something Else"; //invoke load request dialog in the dropdown loadDropDownButtons = entryForm.CustomFunctions.Where(f => f.Id == "LOADREQUESTDROPDOWN"); Assert.AreEqual(1, loadDropDownButtons.Count()); Assert.AreEqual(1, loadDropDownButtons.First().ChildButtons.Count()); Assert.AreEqual("TestName", loadDropDownButtons.First().ChildButtons.First().Label); loadDropDownButtons.First().ChildButtons.First().Invoke(); //verify loads Assert.IsFalse(entryForm.ChildForms.Any()); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); Assert.AreEqual(nameof(TestSavedRequestDialogRequest.SomeArbitraryString), entryForm.GetStringFieldFieldViewModel(nameof(TestSavedRequestDialogRequest.SomeArbitraryString)).Value); //clear the loaded string value entryForm.GetStringFieldFieldViewModel(nameof(TestSavedRequestDialogRequest.SomeArbitraryString)).Value = "Something Else"; //invoke load request dialog in the edit form var loadRequestButton = entryForm.GetButton("LOADREQUEST"); loadRequestButton.Invoke(); var loadRequestForm = testApplication.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); Assert.AreEqual(nameof(TestSavedRequestDialogRequest.SomeArbitraryString), entryForm.GetStringFieldFieldViewModel(nameof(TestSavedRequestDialogRequest.SomeArbitraryString)).Value); //verify if delete on the load form //invoke load form loadRequestButton = entryForm.GetButton("LOADREQUEST"); loadRequestButton.Invoke(); loadRequestForm = testApplication.GetSubObjectEntryViewModel(entryForm); //delete the saved request in the grid subGrid = loadRequestForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests)); subGrid.DynamicGridViewModel.DeleteRow(subGrid.GridRecords.First()); loadRequestForm.SaveButtonViewModel.Invoke(); Assert.IsFalse(entryForm.ChildForms.Any()); Assert.IsFalse(entryForm.LoadingViewModel.IsLoading); //no saved dropdown loadDropDownButtons = entryForm.CustomFunctions.Where(f => f.Id == "LOADREQUESTDROPDOWN"); Assert.AreEqual(0, loadDropDownButtons.Count()); //verify no longer a saved request resolved by the settings manager settingsManager = testApplication.Controller.ResolveType <ISettingsManager>(); savedRequests = settingsManager.Resolve <SavedSettings>(typeof(TestSavedRequestDialogRequest)); Assert.IsFalse(savedRequests.SavedRequests.Any()); //verify does not throw fatal error if lookup referenced is deleted in the saved requests //create a saved request for a deleted solution var solution = ReCreateTestSolution(); request = new TestSavedRequestDialogRequest() { Name = "Foo", Autoload = true, SomeArbitraryString = nameof(TestSavedRequestDialogRequest.SomeArbitraryString), XrmLookupField = solution.ToLookup() }; savedRequests = new SavedSettings() { SavedRequests = new[] { request } }; settingsManager.SaveSettingsObject(savedRequests, typeof(TestSavedRequestDialogRequest)); XrmRecordService.Delete(solution); //verify a user message is thrown when the autoload fires testApplication = CreateAndLoadTestApplication <SavedRequestModule>(); testApplication.AddModule <TestSavedRequestModule>(); try { entryForm = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestModule, TestSavedRequestDialog>(); } catch (Exception ex) { Assert.IsTrue(ex is FakeUserMessageException); } //verify saved requests load when a saved request has a deleted solution //create a saved request with a solution solution = ReCreateTestSolution(); request = new TestSavedRequestDialogRequest() { Name = "Foo", SomeArbitraryString = nameof(TestSavedRequestDialogRequest.SomeArbitraryString), XrmLookupField = solution.ToLookup() }; savedRequests = new SavedSettings() { SavedRequests = new[] { request } }; settingsManager.SaveSettingsObject(savedRequests, typeof(TestSavedRequestDialogRequest)); //load the dialog testApplication = CreateAndLoadTestApplication <SavedRequestModule>(); testApplication.AddModule <TestSavedRequestModule>(); entryForm = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestModule, TestSavedRequestDialog>(); //delete the solution XrmRecordService.Delete(solution); //invoke the load request form loadRequestButton = entryForm.GetButton("LOADREQUEST"); loadRequestButton.Invoke(); //veirfy a user message is thrown if try to load the one with the deleted solution loadRequestForm = testApplication.GetSubObjectEntryViewModel(entryForm); subGrid = loadRequestForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests)); Assert.IsTrue(subGrid.GridRecords.Count() == 1); subGrid.GridRecords.First().IsSelected = true; loadButton = subGrid.DynamicGridViewModel.GetButton("LOADREQUEST"); try { loadButton.Invoke(); } catch (Exception ex) { Assert.IsTrue(ex is FakeUserMessageException); } }