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);
        }
Example #2
0
        public void VsixAddPortalCodeTest()
        {
            RecreatePortalData(createSecondDuplicateSite: true);
            var app = CreateAndLoadTestApplication <AddPortalCodeModule>();

            var fakeProjectName = "FakeProjectName";
            var directoryInfo   = Directory.CreateDirectory(Path.Combine(VisualStudioService.SolutionDirectory, fakeProjectName));

            VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(directoryInfo.FullName));

            var websiteName = "Fake Site 1";
            var webSite     = XrmRecordService.GetFirst(Entities.adx_website, Fields.adx_website_.adx_name, websiteName);
            var request     = new AddPortalCodeRequest
            {
                WebSite = XrmRecordService.ToLookup(webSite),
                ExportWhereFieldEmpty      = true,
                CreateFolderForWebsiteName = true
            };

            var dialog    = app.NavigateToDialog <AddPortalCodeModule, AddPortalCodeDialog>();
            var entryForm = app.GetSubObjectEntryViewModel(dialog);

            entryForm.GetLookupFieldFieldViewModel(nameof(AddPortalCodeRequest.WebSite)).SetValue(entryForm.GetLookupFieldFieldViewModel(nameof(AddPortalCodeRequest.WebSite)).ItemsSourceAsync.First(r => r.Record != null).Record);
            entryForm.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.ExportWhereFieldEmpty)).Value      = true;
            entryForm.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.CreateFolderForWebsiteName)).Value = true;

            var section = entryForm.GetFieldSection(AddPortalCodeRequest.Sections.RecordsToInclude);
            var func    = section.CustomFunctions.First(c => c.Id == "SELECTALL");

            func.Invoke();
            Assert.IsTrue(entryForm.GetEnumerableFieldViewModel(nameof(AddPortalCodeRequest.RecordsToExport)).GridRecords
                          .All(r => r.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.Selected)).Value ?? false));

            var webTemplateRow = entryForm.GetEnumerableFieldViewModel(nameof(AddPortalCodeRequest.RecordsToExport))
                                 .GridRecords
                                 .First(gr => gr.GetRecordTypeFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordType)).Value.Key == Entities.adx_webtemplate);

            webTemplateRow.GetBooleanFieldFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.IncludeAll)).Value = false;
            //this now auto runs when the flag above iunchecked
            //webTemplateRow.GetEnumerableFieldViewModel(nameof(AddPortalCodeRequest.PortalRecordsToExport.RecordsToInclude)).BulkAddButton.Invoke();

            var templateRecordSelectionForm = entryForm.ChildForms.First() as MultiSelectDialogViewModel <PicklistOption>;

            templateRecordSelectionForm.ItemsSource.First().Select = true;
            templateRecordSelectionForm.ItemsSource.Last().Select  = true;
            templateRecordSelectionForm.ApplyButtonViewModel.Invoke();
            Assert.IsFalse(entryForm.ChildForms.Any());

            Assert.IsTrue(entryForm.Validate());
            entryForm.SaveButtonViewModel.Invoke();


            var responseViewModel = app.GetCompletionViewModel(dialog);
            var response          = responseViewModel.GetObject() as AddPortalCodeResponse;

            Assert.IsFalse(response.HasError);

            var rootFolder = Path.Combine(directoryInfo.FullName, websiteName);

            foreach (var typesFolder in new DirectoryInfo(rootFolder).GetDirectories())
            {
                var fileCountInDirectory = typesFolder.GetFiles().Count();
                var typeLabel            = typesFolder.Name;
                var type          = XrmRecordService.GetAllRecordTypes().First(rt => XrmRecordService.GetDisplayName(rt) == typeLabel);
                var recordsOfType = XrmRecordService.RetrieveAll(type, null);
                if (type == Entities.adx_webpage)
                {
                    //web pages have a parent and child where onluy the ch9ild is exported
                    // (multi language not implemented)
                    // + each has html, css & javascript
                    Assert.AreEqual((recordsOfType.Count() / 4) * 3, fileCountInDirectory);
                }
                else if (type == Entities.adx_webtemplate)
                {
                    Assert.AreEqual(2, fileCountInDirectory);
                }
                else
                {
                    Assert.AreEqual(recordsOfType.Count() / 2, fileCountInDirectory);
                }
            }
        }
        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);
        }