public void SaveInvestmentsInCsv() { var fixture = new Fixture(); List <Investment> investmentsExpected = fixture.Create <List <Investment> >(); var filePath = @"InvestmentsFromDb.csv"; if (File.Exists(filePath)) { File.Delete(filePath); } 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); _databaseService.SaveInvestments(investmentsExpected); var csvService = new CsvService(); _uploaderService = new UploaderService(csvService, new Aggregator(), _databaseService); _uploaderService.UploadInvestmentsFromDbToCsv(filePath); var investmentsInCsv = csvService.GetInvestments(filePath); investmentsInCsv .Select(i => (i.Fund, i.Value, i.Collateral)) .Should().BeEquivalentTo(investmentsExpected .Select(i => (i.Fund, i.Value, i.Collateral))); } finally { connection.Close(); } }
public void ReadInvestmentsFromFile() { var investments = _csvService.GetInvestments(@"Investments.csv"); investments.Should().NotBeEmpty(); }