public void FiltersForLineItemType() { // Arrange var sw = new StringWriter(); using (var csv = new CsvWriter(sw)) { var lineItems = new[] { new LineItem {RecordType = "Dummy"}, new LineItem {RecordType = "LineItem", RecordId = "Hoojey"} }; csv.WriteHeader<LineItem>(); csv.WriteRecords(lineItems); } // Act List<LineItem> parsedItems; using (var reader = new StringReader(sw.ToString())) { using (var parser = new LineItemCsvParser(reader)) { parsedItems = parser.GetLineItems().ToList(); } } // Assert parsedItems.Count.Should().Be(1); parsedItems[0].RecordId.Should().Be("Hoojey"); }
public void Parse_Ok() { using (var stream = new MemoryStream(Resources.LineItems)) { using (var streamReader = new StreamReader(stream)) { using (var parser = new LineItemCsvParser(streamReader)) { List<LineItem> items = parser.GetLineItems().Take(5).ToList(); items.Count.Should().Be(5); foreach (LineItem lineItem in items) { lineItem.RecordType.Should().Be("LineItem"); lineItem.RecordId.Should().NotBeEmpty(); lineItem.ResourceId.Should().NotBeEmpty(); lineItem.UsageStartDate.Year.Should().BeGreaterOrEqualTo(2014); lineItem.UsageEndDate.Year.Should().BeGreaterOrEqualTo(2014); } } } } }
private void RefreshDataForPeriod(AwsProfile profile, string period, IAwsClient client, DateTime currentTime) { string s3Url = MonthlyCsvUrl.Create(profile.DetailedBillingS3Bucket, profile.Account, period); var lastModified = new DateTime(); if (profile.BillingMetadata.ContainsKey(period)) { lastModified = profile.BillingMetadata[period].LastModified; } DateTime newLastModified; Stream file = client.StorageService.GetFileIfChangedSince(s3Url, lastModified, out newLastModified); if (file == null) { return; } using (file) { using (Stream zipStream = OpenFirstZipEntry(file)) { using (var streamReader = new StreamReader(zipStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 32768, leaveOpen: true)) { using (var parser = new LineItemCsvParser(streamReader)) { _billingManager.LoadLineItems(parser.GetLineItems(), period); } } } } BillingMetadata metadata; if (! profile.BillingMetadata.ContainsKey(period)) { metadata = new BillingMetadata(); profile.BillingMetadata.Add(period, metadata); } else { metadata = profile.BillingMetadata[period]; } metadata.LastModified = newLastModified; metadata.LastLoaded = currentTime; }