public void LoadsRecords() { // Arrange var repo = new Mock <IRepository <ResourceLedger> >(); var billingManager = new BillingManager(repo.Object); var oldLineItem = new LineItem { ResourceId = "abc", BlendedCost = 1.0m, RecordId = "abc-rec" }; var newLineItem = new LineItem { ResourceId = "def", BlendedCost = 2.0m, RecordId = "def-rec" }; var ledger = new ResourceLedger { ResourceId = "abc" }; ledger.GetPeriod("2015-03")[oldLineItem.RecordId] = oldLineItem.BlendedCost; repo.Setup(x => x.CreateQuery()).Returns(new[] { ledger }.AsQueryable()); // Act billingManager.LoadLineItems(new[] { oldLineItem, newLineItem }, "2015-04"); // Assert repo.Verify(x => x.Add(It.Is((ResourceLedger l) => l.ResourceId == "abc")), Times.Never); repo.Verify(x => x.Add(It.Is((ResourceLedger l) => l.ResourceId == "def")), Times.Once); repo.Verify(x => x.Update(It.Is((ResourceLedger l) => l.ResourceId == "abc" && l.Periods["2015-04"]["abc-rec"] == 1.0m)), Times.Once); repo.Verify(x => x.Update(It.Is((ResourceLedger l) => l.ResourceId == "def" && l.Periods["2015-04"]["def-rec"] == 2.0m)), Times.Once); }
public void LoadsRecords() { // Arrange var repo = new Mock<IRepository<ResourceLedger>>(); var billingManager = new BillingManager(repo.Object); var oldLineItem = new LineItem {ResourceId = "abc", BlendedCost = 1.0m, RecordId = "abc-rec"}; var newLineItem = new LineItem {ResourceId = "def", BlendedCost = 2.0m, RecordId = "def-rec"}; var ledger = new ResourceLedger {ResourceId = "abc"}; ledger.GetPeriod("2015-03")[oldLineItem.RecordId] = oldLineItem.BlendedCost; repo.Setup(x => x.CreateQuery()).Returns(new[] {ledger}.AsQueryable()); // Act billingManager.LoadLineItems(new[] {oldLineItem, newLineItem}, "2015-04"); // Assert repo.Verify(x => x.Add(It.Is((ResourceLedger l) => l.ResourceId == "abc")), Times.Never); repo.Verify(x => x.Add(It.Is((ResourceLedger l) => l.ResourceId == "def")), Times.Once); repo.Verify(x => x.Update(It.Is((ResourceLedger l) => l.ResourceId == "abc" && l.Periods["2015-04"]["abc-rec"] == 1.0m)), Times.Once); repo.Verify(x => x.Update(It.Is((ResourceLedger l) => l.ResourceId == "def" && l.Periods["2015-04"]["def-rec"] == 2.0m)), Times.Once); }
private ResourceLedger FindOrCreateLedger(string resourceId) { ResourceLedger record = FindLedger(resourceId); if (record == null) { record = new ResourceLedger {Id = Guid.NewGuid(), ResourceId = resourceId}; _resourceLedgerRepository.Add(record); } return record; }
private ResourceLedger FindOrCreateLedger(string resourceId) { ResourceLedger record = FindLedger(resourceId); if (record == null) { record = new ResourceLedger { Id = Guid.NewGuid(), ResourceId = resourceId }; _resourceLedgerRepository.Add(record); } return(record); }
public virtual void Add(ResourceLedger other) { foreach (var(resource, amount) in other.Contents) { if (Contents.ContainsKey(resource)) { Contents[resource] += amount; } else { Contents.Add(resource, amount); } } }
public void LoadLineItems(IEnumerable <LineItem> lineItems, string period) { var sw = new Stopwatch(); sw.Start(); int records = 0; foreach (IGrouping <string, LineItem> group in lineItems.GroupBy(li => li.ResourceId)) { ResourceLedger record = FindOrCreateLedger(group.Key); foreach (LineItem lineItem in group) { records++; record.GetPeriod(period)[lineItem.RecordId] = lineItem.BlendedCost; } _resourceLedgerRepository.Update(record); } sw.Stop(); Debug.WriteLine("Processed {0} records in {1:0.00} seconds ({2:0.000}/sec)", records, sw.Elapsed.TotalSeconds, records / sw.Elapsed.TotalSeconds); }
public Transaction(ResourceLedger bundle) { Contents = bundle.Contents; }