Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ExportDataApp app      = new ExportDataApp();
            Logger        logger   = app.Logger;
            ExitCode      exitCode = ExitCode.None;

            try
            {
                logger.Info("Application started.");

                CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

                Options options = new Options();

                Parser.Default.ParseArgumentsStrict(args, options, CommandLineOptions.ArgumentParsingFailed);

                Connection connection = null;

                if (string.IsNullOrWhiteSpace(options.ConnectionString))
                {
                    connection = new Connection(options.AuthorityUrl, options.OrganizationUrl, options.OrganizationUrlSuffix,
                                                options.TenantId, options.ServicePrincipalId, options.ServicePrincipalSecret, options.ConnectionRetries, options.ConnectionTimeout);
                }
                else
                {
                    connection = new Connection(options.ConnectionString, options.ConnectionRetries, options.ConnectionTimeout);
                }

                using (IDataMigrationService dataMigrationService = new DataMigrationService(connection.CrmServiceClient))
                {
                    bool result = dataMigrationService.ExportData(options.SchemaFileName, options.OutputFileName);
                    exitCode = result == true ? ExitCode.Success : ExitCode.ConfigurationDataExportFailed;
                }
            }
            catch (Exception ex)
            {
                exitCode = new ExceptionHandlingService(ex).GetExitCode();
            }
            finally
            {
                logger.Info(CultureInfo.InvariantCulture, "Application exited with code: {0}", (int)exitCode);
                Environment.Exit((int)exitCode);
            }
        }
Ejemplo n.º 2
0
        public void ExportDataAsCsv()
        {
            var dataFormat     = DataFormat.Csv;
            var exportSettings = new ExportSettings
            {
                // this is not really unit test but it is the quckest way to get this tested as CrmSchemaConfiguration.ReadFromFile actually looks for the file!
                SchemaPath       = "TestData/BusinessUnitSchema.xml",
                DataFormat       = dataFormat,
                ExportConfigPath = "TestData",
                BatchSize        = 5000,
                SavePath         = "TestData"
            };

            var storeReader = new Mock <IDataStoreReader <Entity, EntityWrapper> >().Object;
            var storeWriter = new Mock <IDataStoreWriter <Entity, EntityWrapper> >().Object;

            var genericCrmDataMigrator = new GenericCrmDataMigrator(loggerMock.Object, storeReader, storeWriter);

            var factoryMock = new Mock <ICrmGenericMigratorFactory>();

            factoryMock.Setup(x => x.GetCrmDataMigrator(
                                  dataFormat,
                                  It.IsAny <ILogger>(),
                                  It.IsAny <EntityRepository>(),
                                  It.IsAny <CrmExporterConfig>(),
                                  It.IsAny <CancellationToken>(),
                                  It.IsAny <CrmSchemaConfiguration>()))
            .Returns(genericCrmDataMigrator)
            .Verifiable();

            var localSystemUnderTest = new DataMigrationService(loggerMock.Object, factoryMock.Object);

            FluentActions.Invoking(() => localSystemUnderTest.ExportData(exportSettings))
            .Should()
            .Throw <NullReferenceException>();

            factoryMock.Verify(x => x.GetCrmDataMigrator(dataFormat, It.IsAny <ILogger>(), It.IsAny <EntityRepository>(), It.IsAny <CrmExporterConfig>(), It.IsAny <CancellationToken>(), It.IsAny <CrmSchemaConfiguration>()), Times.Once);
        }
Ejemplo n.º 3
0
 public void ExportDataWithNullExportSettings()
 {
     FluentActions.Invoking(() => systemUnderTest.ExportData(null))
     .Should()
     .Throw <ArgumentNullException>();
 }