public void MapMultipleTypesTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            config.RegisterClassMap <AMap>();
            config.RegisterClassMap <BMap>();

            Assert.IsNotNull(config.Maps[typeof(A)]);
            Assert.IsNotNull(config.Maps[typeof(B)]);
        }
        public void RegisterClassInstanceTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            Assert.IsNull(config.Maps[typeof(TestClass)]);
            config.RegisterClassMap(new TestClassMappings());
            Assert.IsNotNull(config.Maps[typeof(TestClass)]);
        }
        public void AddingMappingsWithInstanceMethodTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            config.RegisterClassMap(new TestClassMappings());

            Assert.AreEqual(2, config.Maps[typeof(TestClass)].MemberMaps.Count);
        }
        /// <summary>
        /// Process the user request
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            try
            {
                if (System.IO.File.Exists(this.MetaDataCsvFile))
                {
                    var CSVConfig = new CSVConfig.CsvConfiguration(CultureInfo.CurrentCulture)
                    {
                        Delimiter       = ",",
                        HasHeaderRecord = true
                    };
                    CSVConfig.RegisterClassMap <FileTagModelMap>();


                    using var fileInfo = System.IO.File.OpenText(this.MetaDataCsvFile);

                    var csv = new CsvReader(fileInfo, CSVConfig);

                    this.MetadataList.AddRange(csv.GetRecords <FileTagModel>());
                }
            }
            catch (System.IO.FileNotFoundException fex)
            {
                LogError(fex, "Failed to reach CSV file");
            }

            try
            {
                var onlineLibrary = Library.GetList(this.ClientContext.Web, ol => ol.RootFolder, ol => ol.Title, ol => ol.EnableVersioning);
                if (onlineLibrary.EnableVersioning)
                {
                    onlineLibrary.UpdateListVersioning(false, false, true);
                }

                // Parse Top Directory, enumerate files and upload them to root folder
                if (this.UploadFiles)
                {
                    UploadFileToSharePointFolder(onlineLibrary.RootFolder, this.DirectoryPath);
                }

                // Loop through all folders (recursive) that exist within the folder supplied by the operator
                var firstLevelFolders = System.IO.Directory.GetDirectories(this.DirectoryPath, "*", System.IO.SearchOption.TopDirectoryOnly);
                foreach (var folder in firstLevelFolders)
                {
                    var createdFolder = PopulateSharePointFolderWithFiles(onlineLibrary.RootFolder, this.DirectoryPath, folder);
                    if (!createdFolder)
                    {
                        LogDebugging("Folder {0} was not created successfully.", folder);
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Failed in SetDirectoryUpload {0} directory", DirectoryPath);
            }
        }
        public void PropertyMapAccessTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            config.RegisterClassMap <AMap>();
            config.Maps.Find <A>().Map(m => m.AId).Ignore();

            Assert.AreEqual(true, config.Maps[typeof(A)].MemberMaps[0].Data.Ignore);
        }
        public void UnregisterClassNonMapGenericTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);

            Assert.IsNull(config.Maps[typeof(TestClass)]);
            config.RegisterClassMap(typeof(TestClassMappings));
            Assert.IsNotNull(config.Maps[typeof(TestClass)]);

            config.UnregisterClassMap(typeof(TestClassMappings));
            Assert.IsNull(config.Maps[typeof(TestClass)]);
        }
        /// <summary>
        /// Queries the reporting endpoint with the specified filters and interpolated classes
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="reportingFilters"></param>
        /// <param name="betaEndPoint"></param>
        /// <returns></returns>
        private ICollection <T> QueryBetaOrCSVMap <T, U>(QueryFilter reportingFilters, bool betaEndPoint = false)
            where T : JSONResult
            where U : CSVConfig.ClassMap
        {
            var successOrWillTry = false;
            var results          = new List <T>();

            if (betaEndPoint)
            {
                // Switch to JSON Output
                try
                {
                    reportingFilters.FormattedOutput = ReportUsageFormatEnum.JSON;

                    var activityresults = ResponseReader.RetrieveData <T>(reportingFilters);
                    results.AddRange(activityresults);
                    successOrWillTry = true;
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, $"Failed for JSON Format with message {ex.Message}");
                }
            }

            if (!successOrWillTry)
            {
                // Switch to CSV Output
                reportingFilters.FormattedOutput = ReportUsageFormatEnum.Default;
                reportingFilters.BetaEndPoint    = false;
                var CSVConfig = new CSVConfig.CsvConfiguration(CultureInfo.CurrentCulture)
                {
                    Delimiter       = ",",
                    HasHeaderRecord = true
                };
                CSVConfig.RegisterClassMap <U>();
                var resultscsv = new CSV.CsvReader(ResponseReader.RetrieveDataAsStream(reportingFilters), CSVConfig);
                results.AddRange(resultscsv.GetRecords <T>());
            }

            Logger.LogInformation($"Found {results.Count} while querying successOrWillTry:{successOrWillTry}");

            return(results);
        }