Exemple #1
0
        public async Task WhenIParseTheDetailsOfTheFiles(string filePath)
        {
            string[] files = { filePath };

            var attr = File.GetAttributes(filePath);

            if (attr.HasFlag(FileAttributes.Directory))
            {
                files = Directory.GetFiles(filePath, "*.csv");
            }

            var readTasks = files.Select(s =>
            {
                var sourceKind = CsvAccountOperationManager.DetectFileSourceKindFromFileName(s);
                var fmd        = FileStructureMetadataFactory.CreateDefault(sourceKind);
                using (var fs = File.OpenRead(s))
                {
                    return(_context.CsvAccountOperationManager.ReadAsync(fs, fmd)
                           .ContinueWith(t =>
                                         t.Result.Select(op => _context.Transformer.Apply(op, fmd.GetCultureInfo()))));
                }
            });

            var operationsBatches = await Task.WhenAll(readTasks);

            _context.UnifiedOperations =
                operationsBatches.SelectMany(operations => operations)
                .SortByOperationIdDesc()
                .ToList();
        }
Exemple #2
0
        public async Task ThenDeserializationIsConsistentAndOriginalDataIsPreservedWithInternalExport(
            CsvAccountOperationManager operationManager,
            List <AccountOperationBase> operations)
        {
            var ms = new MemoryStream();
            await operationManager.WriteAsync(ms, operations);

            var fileStructureMetadata = FileStructureMetadataFactory.CreateDefault(operations[0].SourceKind);

            ms.Seek(0, SeekOrigin.Begin);
            var operationsState2 = await operationManager.ReadAsync(ms, fileStructureMetadata);

            operationsState2.ShouldBeEquivalentTo(operations, o => o.IncludingAllRuntimeProperties());
        }
        public ClassificationStepsContext()
        {
            CsvAccountOperationManager = new CsvAccountOperationManager();
            Transformer = new UnifiedAccountOperationPatternTransformer(
                new PlaceInfoResolver(PlaceProvider.Load(new PlacesRepository())));
            WorkingCopy = new WorkingCopy(new FileSystemAdapter(new MockFileSystem()), @"c:\WorkingCopy");

            AccountCommandRepository = new AccountCommandRepository(WorkingCopy);
            var operationsRepository = new OperationsRepository(WorkingCopy, CsvAccountOperationManager, Transformer);

            var cacheManager = new CacheManager(new NoCache());

            OperationsManager = new OperationsManager(cacheManager, operationsRepository);
            ImportManager     = new ImportManager(cacheManager, AccountCommandRepository, OperationsManager);

            AccountId = Guid.NewGuid();
        }