コード例 #1
0
        public async Task <ImportResponse> ImportCsv()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            ImportResponse response = new ImportResponse();

            var provider = new MultipartMemoryStreamProvider();

            await Request.Content.ReadAsMultipartAsync(provider);

            var file = provider.Contents.FirstOrDefault();

            if (file != null)
            {
                response.Filename = file.Headers.ContentDisposition.FileName.Trim('\"');

                string csv = await file.ReadAsStringAsync();

                var csvService = new CsvService(ApplicationContext);

                response = csvService.ImportCsv(csv);
            }

            return(response);
        }
コード例 #2
0
        public async Task Load_Success()
        {
            // ARRANGE
            var    requestMock = new Mock <HttpMessageHandler>(MockBehavior.Default);
            string csvString   =
                @"productId, name,  description, price, currency,category
45848, shorts, short pants,  8, USD, pants
";

            requestMock.SetupGetMethod(HttpStatusCode.OK, "001-experts-inputs.csv", csvString);

            var         httpClient = new HttpClient(requestMock.Object);
            ICsvService srv        = new CsvService(httpClient);

            // ACT
            var productList = await srv.DownloadCsv(new Uri("https://henrybeen.nl/wp-content/uploads/2020/10/001-experts-inputs.csv"));

            // ASSESS
            Assert.Single <Product>(productList);
            var product = productList.Single();

            Assert.Equal(45848, product.Id);
            Assert.Equal("shorts", product.Name);
            Assert.Equal("short pants", product.Description);
            Assert.Equal(8, product.Price.Value);
            Assert.Equal(Currency.USD, product.Price.Currency);
            Assert.Equal(ProductCategory.Pants, product.Category);
        }
コード例 #3
0
        public async Task GetCumulativeCsv_ValidInput_ReturnsByteArray()
        {
            // Arrange
            var service = new CsvService();

            var cumulativeData = new CumulativeData
            {
                Header = new CumulativeHeader {
                    MinOriginYear = 2000, DevelopmentYears = 5
                },
                CumulativeValues = new List <CumulativeValue>
                {
                    new CumulativeValue
                    {
                        Type   = ProductType.Comp,
                        Values = new List <double> {
                            1, 2, 3
                        }
                    }
                }
            };

            // Act
            var result = await service.GetCumulativeCsv(cumulativeData);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.Length > 0);
        }
        public override void Given()
        {
            expectedStage2Response = new List <AssessmentCsvRecordResponse>
            {
                new AssessmentCsvRecordResponse {
                    RowNum = 1, ValidationErrors = new List <BulkProcessValidationError>
                    {
                        new BulkProcessValidationError {
                            RowNum = "1", ErrorMessage = "TestErrorMessage1"
                        }
                    }
                },
                new AssessmentCsvRecordResponse {
                    RowNum = 2, ValidationErrors = new List <BulkProcessValidationError>
                    {
                        new BulkProcessValidationError {
                            RowNum = "2", ErrorMessage = "TestErrorMessage2"
                        }
                    }
                }
            };

            var csvResponse = new CsvResponseModel <AssessmentCsvRecordResponse> {
                Rows = expectedStage2Response
            };

            CsvService.ReadAndParseFileAsync(Arg.Any <AssessmentCsvRecordRequest>()).Returns(csvResponse);
            BlobService.DownloadFileAsync(Arg.Any <BlobStorageData>()).Returns(new MemoryStream(Encoding.ASCII.GetBytes("Test File")));

            var expectedWriteFileBytes = new byte[5];

            CsvService.WriteFileAsync(Arg.Any <List <BulkProcessValidationError> >()).Returns(expectedWriteFileBytes);
        }
コード例 #5
0
        public void MatchOnHeader()
        {
            var localSubject = new CsvService <CsvTestObject>();

            using (var writer = new StreamWriter(new MemoryStream()))
            {
                //Assemble
                writer.WriteLine(
                    "FirstName,LastName,Quantity,DateOfBirth");

                writer.WriteLine("Test, User, 1, 2018-1-1");
                writer.WriteLine("Second Test, Second User, 2, 2018-2-1");
                writer.WriteLine("Third Test, Third User, 3, 2018-3-1");
                writer.Flush();
                writer.BaseStream.Position = 0;

                //Act
                var records = localSubject.GetRecords(writer.BaseStream, null);

                //Assert
                Assert.Equal(3, records.Count);
                Assert.Equal("Test", records[0].FirstName);
                Assert.Equal("User", records[0].LastName);
                Assert.Equal(1, records[0].Quantity);
                Assert.Equal(new DateTime(2018, 1, 1), records[0].DateOfBirth);
                Assert.Equal("Second Test", records[1].FirstName);
                Assert.Equal("Second User", records[1].LastName);
                Assert.Equal(2, records[1].Quantity);
                Assert.Equal(new DateTime(2018, 2, 1), records[1].DateOfBirth);
                Assert.Equal("Third Test", records[2].FirstName);
                Assert.Equal("Third User", records[2].LastName);
                Assert.Equal(3, records[2].Quantity);
                Assert.Equal(new DateTime(2018, 3, 1), records[2].DateOfBirth);
            }
        }
コード例 #6
0
ファイル: CsvServiceTest.cs プロジェクト: Aspect26/socneto
        public void TestNotEmptyWithHeaders()
        {
            var csvService = new CsvService();

            var data = new List <MockModel>()
            {
                new MockModel {
                    Identifier = "Wrathchild", Count = 25
                },
                new MockModel {
                    Identifier = "The Number of the Beast", Count = 666
                },
                new MockModel {
                    Identifier = "The Prisoner", Count = 6
                },
            };

            var resultCsv   = csvService.GetCsv(data, true);
            var expectedCsv = $"{MockModel.IdentifierHeader},{MockModel.CountHeader}\n" +
                              $"{data[0].Identifier},{data[0].Count}\n" +
                              $"{data[1].Identifier},{data[1].Count}\n" +
                              $"{data[2].Identifier},{data[2].Count}\n";

            Assert.AreEqual(expectedCsv, resultCsv, "Incorrectly encoded data objects to CSV");
        }
コード例 #7
0
 public MapCssFile(AccountService accountService, CsvService csvService, TransactionService transactionService, IOutputWriter outputWriter)
 {
     _accountService     = accountService;
     _csvService         = csvService;
     _transactionService = transactionService;
     _outputWriter       = outputWriter;
 }
コード例 #8
0
        public void WebsiteService_ParseWebsiteCsvList()
        {
            //Arrange
            var csvFile = "Domain Name,Domain Type,Agency,Organization,City,State,Security Contact Email\n" +
                          "ABERDEENMD.GOV,City,Non - Federal Agency,City of Aberdeen,Aberdeen,MD,(blank)\n" +
                          "ADAMSCOUNTYMS.GOV,County,Non-Federal Agency,Adams County Board of Supervisors,Natchez,MS,(blank)\n" +
                          "511TX.GOV,State/Local Govt,Non-Federal Agency,Tx. Dept. of Transportation,Austin,TX,(blank)\n" +
                          "BOONECOUNTYFPDMO.GOV,Interstate Agency,Non-Federal Agency,Boone County Fire Protection District,Columbia,MO,(blank)\n" +
                          "AOC.GOV,Federal Agency - Legislative,Architect of the Capitol,The Architect of the Capitol,Washington,DC,(blank)\n" +
                          "ACUS.GOV,Federal Agency - Executive,Administrative Conference of the United States,ADMINISTRATIVE CONFERENCE OF THE UNITED STATES,Washington,DC,(blank)\n" +
                          "SC-US.GOV,Federal Agency - Judicial,The Supreme Court,Supreme Court of the United States,Washington,DC,(blank)\n" +
                          "29PALMSBOMI-NSN.GOV,Native Sovereign Nation,Indian Affairs,Twenty-Nine Palms Band of Mission Indians,Coachella,CA,(blank)\n";

            var csvService = new CsvService();
            //Act
            var websiteEntries = csvService.ParseWebsiteCsvList(csvFile);

            //Assert
            Assert.AreEqual(8, websiteEntries.Count);
            AssertHelper.AssertWebsiteEntry(websiteEntries[0], "ABERDEENMD.GOV", GovernmentType.CITY, "Non - Federal Agency", "City of Aberdeen", "Aberdeen", "MD", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[1], "ADAMSCOUNTYMS.GOV", GovernmentType.COUNTY, "Non-Federal Agency", "Adams County Board of Supervisors", "Natchez", "MS", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[2], "511TX.GOV", GovernmentType.STATE_LOCAL, "Non-Federal Agency", "Tx. Dept. of Transportation", "Austin", "TX", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[3], "BOONECOUNTYFPDMO.GOV", GovernmentType.INTERSTATE_AGENCY, "Non-Federal Agency", "Boone County Fire Protection District", "Columbia", "MO", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[4], "AOC.GOV", GovernmentType.FEDERAL_LEGISLATIVE, "Architect of the Capitol", "The Architect of the Capitol", "Washington", "DC", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[5], "ACUS.GOV", GovernmentType.FEDERAL_EXECUTIVE, "Administrative Conference of the United States", "ADMINISTRATIVE CONFERENCE OF THE UNITED STATES", "Washington", "DC", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[6], "SC-US.GOV", GovernmentType.FEDERAL_JUDICIAL, "The Supreme Court", "Supreme Court of the United States", "Washington", "DC", "(blank)");
            AssertHelper.AssertWebsiteEntry(websiteEntries[7], "29PALMSBOMI-NSN.GOV", GovernmentType.NATIVE_SOVEREIGN_NATION, "Indian Affairs", "Twenty-Nine Palms Band of Mission Indians", "Coachella", "CA", "(blank)");
        }
コード例 #9
0
        public void SaveInvestmentTotalsInDb()
        {
            var filePath   = @"Investments.csv";
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <DatabaseContext>()
                              .UseSqlite(connection)
                              .Options;
                using var context = new DatabaseContext(options);
                context.Database.EnsureCreated();
                _databaseService = new DatabaseService(context);
                var csvService = new CsvService();
                _uploaderService = new UploaderService(csvService, new Aggregator(), _databaseService);

                _uploaderService.UploadInvestmentsFromCsvToDb(filePath);

                var investmentsAfter = _databaseService.GetInvestmentTotals();
                investmentsAfter.SingleOrDefault().Should().NotBeNull();
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #10
0
        public void ResetDatabase()
        {
            ClearDatabase();

            TeamDataService tds = new TeamDataService();

            tds.InsertTeams();

            //past
            CsvService csvs = new CsvService();

            csvs.InsertMatches("13-14.csv");
            csvs.InsertScores("13-14.csv");
            csvs.InsertMatches("14-15.csv");
            csvs.InsertScores("14-15.csv");
            csvs.InsertMatches("15-16.csv");
            csvs.InsertScores("15-16.csv");
            csvs.InsertMatches("16-17.csv");
            csvs.InsertScores("16-17.csv");

            CsvDownloader csvd = new CsvDownloader();

            csvd.GetScoresCsv(DateTime.Now);

            ApiService aps = new ApiService();

            aps.InsertAllMatches();
            csvs.InsertScores("DebugCurrentScores.csv");
        }
コード例 #11
0
        public async Task WriteAsCsv(IEnumerable <TradingHourlyData> dayTradingData,
                                     string[] headers, Func <DateTime, DateTime> fnToLocalTime, CsvSettings csvSettings,
                                     string[] expectedCsvRows)
        {
            // arrange
            var csvService = new CsvService();

            // act
            string csv = null;

            using (MemoryStream ms = new MemoryStream())
            {
                await csvService.WriteAsCsv(dayTradingData, headers, fnToLocalTime, csvSettings,
                                            new StreamWriter(ms, Encoding.UTF8));

                ms.Seek(0, SeekOrigin.Begin);
                csv = new StreamReader(ms, Encoding.UTF8).ReadToEnd();
            }

            // assert
            csv.Should().NotBeNullOrEmpty();

            var csvRows = csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            csvRows.Length.Should().Be(dayTradingData.Count() + 1);             // data rows + header row

            if (expectedCsvRows != null)
            {
                for (int i = 0; i < expectedCsvRows.Length; i++)
                {
                    csvRows[i].Should().BeEquivalentTo(expectedCsvRows[i]);
                }
            }
        }
コード例 #12
0
        public void Save_Success()
        {
            // ARRANGE
            var p1 = new Product()
            {
                Id          = 1,
                Name        = "hmm",
                Description = "Desc",
                Price       = new ProductPrice {
                    Value = 1, Currency = Currency.USD
                },
                Category = ProductCategory.Pants
            };
            var productList = new List <Product>()
            {
                p1
            };

            var         textWriterMock = new Mock <TextWriter>();
            ICsvService srv            = new CsvService(new HttpClient());

            // ACT
            srv.SaveCsv(productList, textWriterMock.Object);

            // ASSERT
            textWriterMock.Verify(mock => mock.Write(It.Is <string>(arg => arg == "USD")), Times.Once());
        }
        public override void Given()
        {
            expectedStage2Response = new List <ResultCsvRecordResponse>
            {
                new ResultCsvRecordResponse {
                    RowNum = 1, Uln = 1111111111, CoreCode = "1234567", CoreAssessmentSeries = "Summer 2021", CoreGrade = "A", ValidationErrors = new List <BulkProcessValidationError>
                    {
                        new BulkProcessValidationError {
                            RowNum = "1", Uln = "1111111111", ErrorMessage = "Core component code must have 8 digits only"
                        }
                    }
                },
                new ResultCsvRecordResponse {
                    RowNum = 2, Uln = 1111111112, CoreCode = "", CoreAssessmentSeries = "Summer 2021", CoreGrade = "A", ValidationErrors = new List <BulkProcessValidationError>
                    {
                        new BulkProcessValidationError {
                            RowNum = "2", Uln = "1111111112", ErrorMessage = "Core component code required when result is included"
                        }
                    }
                }
            };

            var csvResponse = new CsvResponseModel <ResultCsvRecordResponse> {
                Rows = expectedStage2Response
            };

            CsvService.ReadAndParseFileAsync(Arg.Any <ResultCsvRecordRequest>()).Returns(csvResponse);
            ResultService.ValidateResultsAsync(AoUkprn, Arg.Any <IEnumerable <ResultCsvRecordResponse> >()).Returns(new List <ResultRecordResponse>());
            BlobService.DownloadFileAsync(Arg.Any <BlobStorageData>()).Returns(new MemoryStream(Encoding.ASCII.GetBytes("Test File")));

            var expectedWriteFileBytes = new byte[5];

            CsvService.WriteFileAsync(Arg.Any <List <BulkProcessValidationError> >()).Returns(expectedWriteFileBytes);
        }
コード例 #14
0
        public BloodDonationController(IHostingEnvironment environment)
        {
            _environment = environment;

            _context   = new EFDbContext();
            _csvReader = new CsvService();
        }
コード例 #15
0
        public async Task GenerateIntradayReportAsync_TransitionToSummerTime(ITradingDataAdapter tradingDataAdapter)
        {
            // arrange
            var reportRepository = new ReportRepository(tradingDataAdapter);
            var csvService       = new CsvService();
            var reportService    = new IntradayReportServiceImpl(reportRepository, csvService);

            // act
            string csv = null;

            using (MemoryStream ms = new MemoryStream())
            {
                await reportService.GenerateIntradayReportAsync(_utcDateOfTransitionToSummerTime, _csvSettings, ms);

                ms.Seek(0, SeekOrigin.Begin);
                csv = new StreamReader(ms, Encoding.UTF8).ReadToEnd();
            }

            // assert:

            csv.Should().NotBeNullOrEmpty();

            var csvRows = csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            // Spec.: "CSV should only contain local time, use the GMT time zone periods as the number in the CSV (23 in this case)"
            csvRows.Length.Should().Be(23 + 1);             // data rows + header row

            // Check that report doesn't contain 1am period
            DateTime excludedPeriodDate = new DateTime(2020, 3, 29, 1, 0, 0);

            Assert.IsTrue(!csvRows.Any(r => r.Contains(excludedPeriodDate.ToString(_csvSettings.TimeFormat))));
        }
コード例 #16
0
        public void GetIncrementalClaims_InvalidInput_ThrowsException()
        {
            // Arrange
            var service = new CsvService();

            var fileMock = new Mock <IFormFile>();

            // Content missing Product
            const string content  = @"
                            Product, Origin Year, Development Year, Incremental Value
                            1992, 1992, 110.0";
            const string fileName = "incremental.csv";

            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write(content);
            writer.Flush();

            ms.Position = 0;

            fileMock.Setup(_ => _.OpenReadStream()).Returns(ms);
            fileMock.Setup(_ => _.FileName).Returns(fileName);
            fileMock.Setup(_ => _.Length).Returns(ms.Length);

            var file = fileMock.Object;

            // Act
            Task AsyncTest() => service.GetIncrementalClaims(file);

            // Assert
            var ex = Assert.ThrowsAsync <CsvException>(AsyncTest);

            Assert.AreEqual(CsvExceptionType.FailedToRead, ex.Type);
        }
コード例 #17
0
        public async Task GetIncrementalClaims_ValidInput_ReturnsClaims()
        {
            // Arrange
            var service = new CsvService();

            var fileMock = new Mock <IFormFile>();

            const string content  = @"
                            Product, Origin Year, Development Year, Incremental Value
                            Comp, 1992, 1992, 110.0";
            const string fileName = "incremental.csv";

            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write(content);
            writer.Flush();

            ms.Position = 0;

            fileMock.Setup(_ => _.OpenReadStream()).Returns(ms);
            fileMock.Setup(_ => _.FileName).Returns(fileName);
            fileMock.Setup(_ => _.Length).Returns(ms.Length);

            var file = fileMock.Object;

            // Act
            var result = await service.GetIncrementalClaims(file);

            // Assert
            Assert.True(result.Count() == 1);
        }
コード例 #18
0
 public CsvContext(IConfigurationService configurationService)
 {
     _csvService           = new CsvService();
     _configurationService = configurationService;
     _delimeter            = ',';
     _usersDirty           = true;
     _userStorageFilePath  = configurationService.UserStoragePath;
 }
コード例 #19
0
ファイル: Comonet.cs プロジェクト: PiotrWu1984/JazzOpsApp
        public IEnumerable <Measurements> FeedMeasurementsFromCSV(CsvService csvService)
        {
            var csvFile      = csvService.loadCsvFileFromFile(@"./comonet/data.csv");
            var list         = csvService.SplitCSVLines(csvFile);
            var measurements = CreateListOfMeasurementsFromStringTable(list);

            return(measurements);
        }
コード例 #20
0
ファイル: Comonet.cs プロジェクト: PiotrWu1984/JazzOpsApp
        public IEnumerable <Measurements> GetData()
        {
            CsvService csvService = new CsvService();
            Comonet    comonet    = new Comonet();
            var        data       = comonet.FeedMeasurementsFromCSV(csvService);

            return(data);
        }
コード例 #21
0
ファイル: CsvServiceTest.cs プロジェクト: Aspect26/socneto
        public void TestGetEmptyWithoutHeaders()
        {
            var csvService = new CsvService();

            var resultCsv   = csvService.GetCsv(new List <MockModel>(), false);
            var expectedCsv = string.Empty;

            Assert.AreEqual(expectedCsv, resultCsv, "CSV for empty list without headers should be empty string");
        }
コード例 #22
0
        public void TestFormattingCsv()
        {
            var csvService = new CsvService();
            var ms         = StreamHelper.GenerateStreamFromString(Text);
            var list       = csvService.FormatCsv(ms);

            Assert.Equal("test", list[0].FirstLanguageWord);
            Assert.Equal(3, list.Count);
        }
コード例 #23
0
        public void ShouldReturnElementCountFromCsv()
        {
            var csv = "UKPRN\n10001309\n10031241";
            var sut = new CsvService();

            var models = sut.CsvTo <CsvTestModel>(csv);

            Assert.AreEqual(2, models.Count);
        }
コード例 #24
0
ファイル: CsvServiceTest.cs プロジェクト: Aspect26/socneto
        public void TestGetEmptyWithHeaders()
        {
            var csvService = new CsvService();

            var resultCsv   = csvService.GetCsv(new List <MockModel>(), true);
            var expectedCsv = $"{MockModel.IdentifierHeader},{MockModel.CountHeader}\n";

            Assert.AreEqual(expectedCsv, resultCsv, "CSV for empty list with headers should contain the headers");
        }
コード例 #25
0
        public void ShouldReturnEmptyEnumerableIfCsvDoesntContainAnything()
        {
            var csv = string.Empty;
            var sut = new CsvService();

            var models = sut.CsvTo <CsvTestModel>(csv);

            Assert.AreEqual(0, models.Count);
        }
コード例 #26
0
        public void ShouldFindTheValueOfACellInACSV()
        {
            var csv = "UKPRN\n10001309\n10031241";
            var sut = new CsvService();

            var models = sut.CsvTo <CsvTestModel>(csv);

            Assert.AreEqual("10001309", models.First().UkPrn);
        }
コード例 #27
0
        static async Task <int> Main(string[] args)
        {
            var tw = new TextWriterTraceListener(Console.Out);

            tw.TraceOutputOptions |= TraceOptions.None;
            Trace.Listeners.Add(tw);
            Trace.AutoFlush = true;
            Trace.Indent();

            var app = new CommandLineApplication
            {
                Name        = "TW ING Coding Challenge",
                Description = "The TeamWildenberg console app for the different assignments in the ING Coding Challenge"
            };

            app.HelpOption("-?|-h|--help");
            var versionOption = app.Option("-v|--version", "Check which version we are running", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                return(0);
            });
            app.Execute(args);

            if (versionOption.HasValue())
            {
                var assemblyVersion = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;
                TraceExtensions.DoMessage($"Version: {assemblyVersion}");
                return(0);
            }
            else
            {
                // instantiate services
                ICurrencyConverterService converterService = new CurrencyConverterService();
                ICsvService csvService = new CsvService(new HttpClient());

                // execute command
                try
                {
                    ICommandAsync cmd = new ChallengeCommand(csvService, converterService);
                    await cmd.Execute().ConfigureAwait(false);

                    return(0);
                }
                catch (CsvServiceException x)
                {
                    TraceExtensions.DoError(x.Message);
                    return(-1);
                }
                catch (Exception)
                {
                    TraceExtensions.DoError($"Something fishy happened, exiting.");
                    throw;
                }
            }
        }
コード例 #28
0
        static void Main(string[] args)
        {
            CsvService.WriteToFile(@"d:\files\persons.csv", "Samuel; Wessen; 34; Örebro");
            var persons = CsvService.ReadFromFile(@"d:\files\persons.csv");

            foreach (var person in persons)
            {
                Console.WriteLine($"{ person.FirstName} {person.LastName} is {person.Age} years old and lives in {person.City}");
            }
        }
コード例 #29
0
        public void SaveAnalysisIntoCsvFile_ReturnsDataIntoCsv()
        {
            string mockFilePath = $"{MOCK_FOLDER_PATH}/save_analysis_snippet.csv";

            //arrange
            Mock <IOptions <Settings> > mockSettings = new Mock <IOptions <Settings> >();

            mockSettings.Setup(ap => ap.Value).Returns(new Settings
            {
                LifeCycleRange          = 7,
                CohortDateFormat        = "MM/dd/yy",
                DataFilesFolderPath     = MOCK_FOLDER_PATH,
                OutputResultsFolderPath = MOCK_FOLDER_PATH,
            });
            CsvService             csvService             = new CsvService();
            CustomerService        customerService        = new CustomerService(csvService);
            OrderService           orderService           = new OrderService(csvService);
            CohortCalculationLogic cohortCalculationLogic = new CohortCalculationLogic(mockSettings.Object);

            CohortAnalysisService service =
                new CohortAnalysisService(
                    mockSettings.Object,
                    customerService,
                    orderService,
                    cohortCalculationLogic,
                    csvService
                    );

            //act
            IEnumerable <CohortGroup> cohortGroups = service.RunAnalysis(new CohortAnalysisSetup
            {
                OrderFilePath    = $"{MOCK_FOLDER_PATH}/orders_mock_snippet.csv",
                CustomerFilePath = $"{MOCK_FOLDER_PATH}/customers_mock_snippet.csv",
                TimeZone         = "America/New_York"
            });

            bool result = service
                          .SaveAnalysisIntoCsvFile(mockFilePath, cohortGroups);

            //assert
            Assert.True(result);
            using (var streamReader = new StreamReader(mockFilePath))
            {
                CsvReader             reader  = new CsvReader(streamReader);
                IEnumerable <dynamic> records = reader.GetRecords <dynamic>();

                List <dynamic> recordList = records.ToList();

                Assert.Equal("06/28/15 - 07/01/15", recordList.First().Cohort);
                Assert.Equal("363 customers", recordList.First().Customers);
                Assert.Equal("01/21/15 - 01/24/15", recordList.Last().Cohort);
                Assert.Equal("81 customers", recordList.Last().Customers);
            }
        }
コード例 #30
0
        public void Then_Returns_Expected_Results()
        {
            CsvService.Received(1).ReadAndParseFileAsync(Arg.Any <AssessmentCsvRecordRequest>());
            CsvService.Received(1).WriteFileAsync(Arg.Any <List <BulkProcessValidationError> >());
            BlobService.Received(1).UploadFromByteArrayAsync(Arg.Any <BlobStorageData>());
            BlobService.Received(1).MoveFileAsync(Arg.Any <BlobStorageData>());
            DocumentUploadHistoryService.Received(1).CreateDocumentUploadHistory(Arg.Any <DocumentUploadHistoryDetails>());

            Response.IsSuccess.Should().BeFalse();
            Response.BlobUniqueReference.Should().Be(BlobUniqueRef);
        }