public async Task WhenUncommittedRecordHasZeroAmount_ItShouldPersistTheData() { byte guidIndex = 0; byte sequentialGuidIndex = 0; this.guidCreator.Setup(v => v.Create()).Returns(() => this.CreateGuid(0, guidIndex++)); this.guidCreator.Setup(v => v.CreateSqlSequential()).Returns(() => this.CreateGuid(1, sequentialGuidIndex++)); var dataId = this.CreateGuid(0, 0); var transactionId1 = this.CreateGuid(0, 1); var transactionId2 = this.CreateGuid(0, 2); var transactionId3 = this.CreateGuid(0, 3); var resultItems = new List <PaymentProcessingResult>(Results.Items); var uncommitted = resultItems.Last(); resultItems[resultItems.Count - 1] = new PaymentProcessingResult( uncommitted.StartTimeInclusive, uncommitted.EndTimeExclusive, new AggregateCostSummary(0), uncommitted.CreatorPercentageOverride, false); var results = new PaymentProcessingResults(Results.CommittedAccountBalance, resultItems); this.persistPaymentProcessingData.Setup( v => v.ExecuteAsync(new PersistedPaymentProcessingData(dataId, Data, results))) .Returns(Task.FromResult(0)); IReadOnlyList <AppendOnlyLedgerRecord> actualCommittedRecords = null; UncommittedSubscriptionPayment actualUncommittedRecord = null; this.persistCommittedAndUncommittedRecords.Setup(v => v.ExecuteAsync(SubscriberId, CreatorId, It.IsAny <IReadOnlyList <AppendOnlyLedgerRecord> >(), It.IsAny <UncommittedSubscriptionPayment>())) .Callback <UserId, UserId, IReadOnlyList <AppendOnlyLedgerRecord>, UncommittedSubscriptionPayment>( (s, c, a, b) => { actualCommittedRecords = a; actualUncommittedRecord = b; }) .Returns(Task.FromResult(0)); await this.target.ExecuteAsync(Data, results); CollectionAssert.AreEqual( new List <AppendOnlyLedgerRecord> { new AppendOnlyLedgerRecord(this.CreateGuid(1, 0), SubscriberId.Value, CreatorId.Value, StartTimeInclusive.AddDays(1), -1m, LedgerAccountType.FifthweekCredit, LedgerTransactionType.SubscriptionPayment, transactionId1, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 1), Guid.Empty, CreatorId.Value, StartTimeInclusive.AddDays(1), 1m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId1, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 2), Guid.Empty, CreatorId.Value, StartTimeInclusive.AddDays(1), -0.9m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId1, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 3), CreatorId.Value, CreatorId.Value, StartTimeInclusive.AddDays(1), 0.9m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId1, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 4), SubscriberId.Value, CreatorId.Value, StartTimeInclusive.AddDays(2), -2m, LedgerAccountType.FifthweekCredit, LedgerTransactionType.SubscriptionPayment, transactionId2, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 5), Guid.Empty, CreatorId.Value, StartTimeInclusive.AddDays(2), 2m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId2, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 6), Guid.Empty, CreatorId.Value, StartTimeInclusive.AddDays(2), -1.6m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId2, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 7), CreatorId.Value, CreatorId.Value, StartTimeInclusive.AddDays(2), 1.6m, LedgerAccountType.FifthweekRevenue, LedgerTransactionType.SubscriptionPayment, transactionId2, dataId, null, null, null), new AppendOnlyLedgerRecord(this.CreateGuid(1, 8), SubscriberId.Value, CreatorId.Value, StartTimeInclusive.AddDays(3), 0m, LedgerAccountType.FifthweekCredit, LedgerTransactionType.SubscriptionPayment, transactionId3, dataId, null, null, null), }, actualCommittedRecords.ToList()); Assert.IsNull(actualUncommittedRecord); }
public async Task WhenMultipleUncommittedRecords_ItShouldThrowAnException() { var resultItems = new List <PaymentProcessingResult>(Results.Items); resultItems.Add(resultItems.Last()); var results = new PaymentProcessingResults(Results.CommittedAccountBalance, resultItems); await this.target.ExecuteAsync(Data, results); }
public async Task WhenNoCommittedRecords_ItShouldPersistTheDataButNotSaveBlob() { byte guidIndex = 0; byte sequentialGuidIndex = 0; this.guidCreator.Setup(v => v.Create()).Returns(() => this.CreateGuid(0, guidIndex++)); this.guidCreator.Setup(v => v.CreateSqlSequential()).Returns(() => this.CreateGuid(1, sequentialGuidIndex++)); var dataId = this.CreateGuid(0, 0); var resultItems = new List <PaymentProcessingResult>(Results.Items); resultItems.Remove(resultItems.First()); resultItems.Remove(resultItems.First()); resultItems.Remove(resultItems.First()); var results = new PaymentProcessingResults(Results.CommittedAccountBalance, resultItems); IReadOnlyList <AppendOnlyLedgerRecord> actualCommittedRecords = null; UncommittedSubscriptionPayment actualUncommittedRecord = null; this.persistCommittedAndUncommittedRecords.Setup(v => v.ExecuteAsync(SubscriberId, CreatorId, It.IsAny <IReadOnlyList <AppendOnlyLedgerRecord> >(), It.IsAny <UncommittedSubscriptionPayment>())) .Callback <UserId, UserId, IReadOnlyList <AppendOnlyLedgerRecord>, UncommittedSubscriptionPayment>( (s, c, a, b) => { actualCommittedRecords = a; actualUncommittedRecord = b; }) .Returns(Task.FromResult(0)); await this.target.ExecuteAsync(Data, results); CollectionAssert.AreEqual( new List <AppendOnlyLedgerRecord>(), actualCommittedRecords.ToList()); Assert.AreEqual( new UncommittedSubscriptionPayment( SubscriberId.Value, CreatorId.Value, StartTimeInclusive.AddDays(3), StartTimeInclusive.AddDays(4), 3, dataId), actualUncommittedRecord); }