public override void DialogCommand() { var visualStudioService = ApplicationController.ResolveType(typeof(IVisualStudioService)) as IVisualStudioService; if (visualStudioService == null) { throw new NullReferenceException("visualStudioService"); } var files = visualStudioService.GetSelectedFileNamesQualified(); var request = new ImportCsvsRequest() { FolderOrFiles = ImportCsvsRequest.CsvImportOption.SpecificFiles, MatchByName = true, DateFormat = DateFormat.English, CsvsToImport = files.Select(f => new ImportCsvsRequest.CsvToImport() { Csv = new FileReference(f) }).ToArray() }; var uri = new UriQuery(); uri.AddObject(nameof(ImportCsvsDialog.Request), request); uri.AddObject(nameof(ImportCsvsDialog.SkipObjectEntry), true); ApplicationController.NavigateTo(typeof(ImportCsvsDialog), uri); }
public void DeploymentImportCsvsTestMaskEmails() { PrepareTests(); var workFolder = ClearFilesAndData(); DeleteAll(Entities.account); File.Copy(@"Account.csv", Path.Combine(workFolder, @"Account.csv")); var application = CreateAndLoadTestApplication <ImportCsvsModule>(); var request = new ImportCsvsRequest { CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { SourceCsv = new FileReference(Path.Combine(workFolder, @"Account.csv")) } }, MaskEmails = true }; var response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString()); } var entity = XrmService.GetFirst(Entities.account); Assert.IsTrue(entity.GetStringField(Fields.account_.emailaddress1).Contains("_AT_")); request = new ImportCsvsRequest { CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { SourceCsv = new FileReference(Path.Combine(workFolder, @"Account.csv")) } }, MaskEmails = false }; response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString()); } entity = XrmService.GetFirst(Entities.account); Assert.IsFalse(entity.GetStringField(Fields.account_.emailaddress1).Contains("_AT_")); }
public void DeploymentImportCsvsTestMaskEmails() { PrepareTests(); var workFolder = ClearFilesAndData(); DeleteAll(Entities.account); File.Copy(@"Account.csv", Path.Combine(workFolder, @"Account.csv")); var importerExporterService = new ImportCsvsService(XrmRecordService); var request = new ImportCsvsRequest { Folder = new Folder(workFolder), FolderOrFiles = ImportCsvsRequest.CsvImportOption.SpecificFiles, CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { Csv = new FileReference(Path.Combine(workFolder, @"Account.csv")) } }, MaskEmails = true }; var response = importerExporterService.Execute(request, Controller); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.DisplayString()); } var entity = XrmService.GetFirst(Entities.account); Assert.IsTrue(entity.GetStringField(Fields.account_.emailaddress1).Contains("_AT_")); request = new ImportCsvsRequest { Folder = new Folder(workFolder), FolderOrFiles = ImportCsvsRequest.CsvImportOption.SpecificFiles, CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { Csv = new FileReference(Path.Combine(workFolder, @"Account.csv")) } }, MaskEmails = false }; response = importerExporterService.Execute(request, Controller); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.DisplayString()); } entity = XrmService.GetFirst(Entities.account); Assert.IsFalse(entity.GetStringField(Fields.account_.emailaddress1).Contains("_AT_")); }
public void DeploymentImportCsvsAccountAndContactsTest() { PrepareTests(); var workFolder = ClearFilesAndData(new[] { Entities.account, Entities.contact }); File.Copy(@"Account.csv", Path.Combine(workFolder, @"Account.csv")); File.Copy(@"Contact.csv", Path.Combine(workFolder, @"Contact.csv")); var application = CreateAndLoadTestApplication <ImportCsvsModule>(); var request = new ImportCsvsRequest { CsvsToImport = new [] { new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Contact.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Account.csv")) }, }, DateFormat = DateFormat.American }; var response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString()); } var accounts = XrmService.RetrieveAllEntityType(Entities.account); var contacts = XrmService.RetrieveAllEntityType(Entities.contact); Assert.AreEqual(1, accounts.Count()); Assert.AreEqual(2, contacts.Count()); foreach (var contact in contacts) { Assert.AreEqual(accounts.First().Id, contact.GetLookupGuid(Fields.contact_.parentcustomerid)); Assert.IsNotNull(contact.GetStringField(Fields.contact_.firstname)); Assert.IsNotNull(contact.GetStringField(Fields.contact_.lastname)); } }
private void GenerateProductData() { var workFolder = ClearFilesAndData(); File.Copy(@"Price List Items.csv", Path.Combine(workFolder, @"Price List Items.csv")); File.Copy(@"Price Lists.csv", Path.Combine(workFolder, @"Price Lists.csv")); File.Copy(@"Products.csv", Path.Combine(workFolder, @"Products.csv")); File.Copy(@"uom.csv", Path.Combine(workFolder, @"uom.csv")); File.Copy(@"uomschedule.csv", Path.Combine(workFolder, @"uomschedule.csv")); //run the import and verify no errors var application = CreateAndLoadTestApplication <ImportCsvsModule>(); var request = new ImportCsvsRequest { CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price List Items.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price Lists.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Products.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uom.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uomschedule.csv")) }, }, DateFormat = DateFormat.American }; var response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); if (response.HasError) { Assert.Fail(response.GetResponseItemsWithError().First().Exception.XrmDisplayString()); } }
public void DeploymentImportCsvsTestProductsAndPricings() { //imports product configurations in csv files PrepareTests(); var workFolder = ClearFilesAndData(); File.Copy(@"Price List Items.csv", Path.Combine(workFolder, @"Price List Items.csv")); File.Copy(@"Price Lists.csv", Path.Combine(workFolder, @"Price Lists.csv")); File.Copy(@"Products.csv", Path.Combine(workFolder, @"Products.csv")); File.Copy(@"uom.csv", Path.Combine(workFolder, @"uom.csv")); File.Copy(@"uomschedule.csv", Path.Combine(workFolder, @"uomschedule.csv")); //lets delete all these items var products = CsvUtility .SelectAllRows(Path.Combine(workFolder, @"Products.csv")) .Select(r => r.GetFieldAsString("Name")) .ToArray(); DeleteAllMatchingName(Entities.product, products); var unitGroups = CsvUtility .SelectAllRows(Path.Combine(workFolder, @"uomschedule.csv")) .Select(r => r.GetFieldAsString("Name")) .ToArray(); DeleteAllMatchingName(Entities.uomschedule, unitGroups); var priceLists = CsvUtility .SelectAllRows(Path.Combine(workFolder, @"Price Lists.csv")) .Select(r => r.GetFieldAsString("Name")) .ToArray(); DeleteAllMatchingName(Entities.pricelevel, priceLists); //run the import and verify no errors var application = CreateAndLoadTestApplication <ImportCsvsModule>(); var request = new ImportCsvsRequest { CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price List Items.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price Lists.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Products.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uom.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uomschedule.csv")) }, }, DateFormat = DateFormat.American }; var response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); Assert.IsFalse(response.HasError); //okay lets get the last created price list item var query = XrmService.BuildQuery(Entities.productpricelevel, null, null, null); query.Orders.Add(new OrderExpression(Fields.productpricelevel_.createdon, OrderType.Descending)); var latestPriceListItem = XrmService.RetrieveFirst(query); //verify it has a price var initialPrice = latestPriceListItem.GetMoneyValue(Fields.productpricelevel_.amount); Assert.IsTrue(initialPrice > 0); //now lets set it something else so we can verify it gets updated after the second run latestPriceListItem.SetMoneyField(Fields.productpricelevel_.amount, initialPrice.Value + 1); latestPriceListItem = UpdateFieldsAndRetreive(latestPriceListItem, Fields.productpricelevel_.amount); //run again and verify no errors request = new ImportCsvsRequest { CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price List Items.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Price Lists.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Products.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uom.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"uomschedule.csv")) }, }, DateFormat = DateFormat.American }; response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); Assert.IsFalse(response.HasError); //verify the price list item we updated is changed latestPriceListItem = Refresh(latestPriceListItem); Assert.AreEqual(initialPrice, latestPriceListItem.GetMoneyValue(Fields.productpricelevel_.amount)); }
public void DeploymentImportCsvMultipleTest() { PrepareTests(); var typesExTeam = new[] { Entities.jmcg_testentitytwo, Entities.jmcg_testentitythree, Entities.jmcg_testentity, Entities.account }; var workFolder = ClearFilesAndData(typesExTeam); var testimportTeam = XrmService.GetFirst("team", "name", "TestImportTeam"); if (testimportTeam != null) { XrmService.Delete(testimportTeam); } DeleteAll(Entities.account); File.Copy(@"Account.csv", Path.Combine(workFolder, @"Account.csv")); File.Copy(@"jmcg_testentity_account.csv", Path.Combine(workFolder, @"jmcg_testentity_account.csv")); File.Copy(@"Test Entity.csv", Path.Combine(workFolder, @"Test Entity.csv")); File.Copy(@"Test Entity Two.csv", Path.Combine(workFolder, @"Test Entity Two.csv")); File.Copy(@"Test Entity Three.csv", Path.Combine(workFolder, @"Test Entity Three.csv")); File.Copy(@"Team.csv", Path.Combine(workFolder, @"Team.csv")); var application = CreateAndLoadTestApplication <ImportCsvsModule>(); var request = new ImportCsvsRequest { DateFormat = DateFormat.American, CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Account.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"jmcg_testentity_account.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Test Entity.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Test Entity Two.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Test Entity Three.csv")) }, new ImportCsvsRequest.CsvToImport { SourceCsv = new FileReference(Path.Combine(workFolder, @"Team.csv")) }, } }; var response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); Assert.IsFalse(response.HasError); application = CreateAndLoadTestApplication <ImportCsvsModule>(); request = new ImportCsvsRequest { DateFormat = DateFormat.American, CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { SourceCsv = new FileReference(Path.Combine(workFolder, @"Account.csv")) } } }; response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); Assert.IsFalse(response.HasError); File.Copy(@"jmcg_testentity.csv", Path.Combine(workFolder, @"jmcg_testentity.csv")); //this one sets a record inactive state var accounta = CreateTestRecord(Entities.account, new Dictionary <string, object>() { { Fields.account_.name, "accounta" } }); var accountb = CreateTestRecord(Entities.account, new Dictionary <string, object>() { { Fields.account_.name, "accountb" } }); application = CreateAndLoadTestApplication <ImportCsvsModule>(); request = new ImportCsvsRequest { DateFormat = DateFormat.English, CsvsToImport = new[] { new ImportCsvsRequest.CsvToImport() { SourceCsv = new FileReference(Path.Combine(workFolder, @"jmcg_testentity.csv")) } } }; response = application.NavigateAndProcessDialog <ImportCsvsModule, ImportCsvsDialog, ImportCsvsResponse>(request); Assert.IsFalse(response.HasError); var entity = XrmService.GetFirst(Entities.jmcg_testentity, Fields.jmcg_testentity_.jmcg_name, "BLAH 2"); Assert.AreEqual(XrmPicklists.State.Inactive, entity.GetOptionSetValue(Fields.jmcg_testentity_.statecode)); }