Пример #1
0
        public async Task WhenRecordsAreNotForSubscriptionPayment_ItShouldThrowAnException()
        {
            byte sequentialGuidIndex = 0;

            this.guidCreator.Setup(v => v.CreateSqlSequential()).Returns(() => CreateGuid(0, sequentialGuidIndex++));

            var transactionReference = TransactionReference.Random();

            var record = new AppendOnlyLedgerRecord(
                CreateGuid(0, 0),
                SubscriberId.Value,
                CreatorId.Value,
                Now,
                100,
                LedgerAccountType.FifthweekCredit,
                LedgerTransactionType.CreditAddition,
                transactionReference.Value,
                null,
                "Performed by " + EnactingUserId + " - comment",
                null,
                null);

            this.getRecordsForTransaction.Setup(v => v.ExecuteAsync(transactionReference))
            .ReturnsAsync(new List <AppendOnlyLedgerRecord> {
                record
            });

            await this.target.ExecuteAsync(EnactingUserId, transactionReference, Now, Comment);
        }
Пример #2
0
        private static AppendOnlyLedgerRecord CreateAppendOnlyLedgerRecord(Random random, UserId accountOwnerId, UserId counterpartyId, decimal amount, LedgerAccountType ledgerAccountType, LedgerTransactionType transactionType, Guid transactionReference)
        {
            var record = new AppendOnlyLedgerRecord(
                Guid.NewGuid(),
                accountOwnerId == null ? Guid.Empty : accountOwnerId.Value,
                counterpartyId == null ? (Guid?)null : counterpartyId.Value,
                Now.AddDays(random.Next(-100, 100)),
                amount,
                ledgerAccountType,
                transactionType,
                transactionReference,
                Guid.NewGuid(),
                null,
                null,
                null);

            return(record);
        }
        private static AppendOnlyLedgerRecord AddAppendOnlyLedgerRecord(
            FifthweekDbContext databaseContext, DateTime timestamp, UserId accountOwnerId, UserId counterpartyId, decimal amount,
            LedgerAccountType ledgerAccountType, LedgerTransactionType transactionType, TransactionReference transactionReference)
        {
            var item = new AppendOnlyLedgerRecord(
                Guid.NewGuid(),
                accountOwnerId == null ? Guid.Empty : accountOwnerId.Value,
                counterpartyId == null ? (Guid?)null : counterpartyId.Value,
                timestamp,
                amount,
                ledgerAccountType,
                transactionType,
                transactionReference.Value,
                Guid.NewGuid(),
                null,
                null,
                null);

            databaseContext.AppendOnlyLedgerRecords.Add(item);

            return(item);
        }
        private static AppendOnlyLedgerRecord AddAppendOnlyLedgerRecord(FifthweekDbContext databaseContext, Random random, UserId accountOwnerId, UserId counterpartyId, decimal amount, LedgerAccountType ledgerAccountType, LedgerTransactionType transactionType, Guid transactionReference, bool save)
        {
            var record = new AppendOnlyLedgerRecord(
                Guid.NewGuid(),
                accountOwnerId == null ? Guid.Empty : accountOwnerId.Value,
                counterpartyId == null ? (Guid?)null : counterpartyId.Value,
                Now.AddDays(random.Next(-100, 100)),
                amount,
                ledgerAccountType,
                transactionType,
                transactionReference,
                Guid.NewGuid(),
                null,
                null,
                null);

            if (save)
            {
                databaseContext.AppendOnlyLedgerRecords.Add(record);
            }

            return record;
        }
        private async Task CreateDataAsync(TestDatabaseContext testDatabase)
        {
            using (var connection = testDatabase.CreateConnection())
            {
                var ledgerEntry = new AppendOnlyLedgerRecord(
                    Guid.NewGuid(),
                    SubscriberId.Value,
                    CreatorId.Value,
                    Now,
                    10,
                    LedgerAccountType.FifthweekCredit,
                    LedgerTransactionType.SubscriptionPayment,
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    null,
                    null,
                    null);

                var ledgerEntry2 = new AppendOnlyLedgerRecord(
                    Guid.NewGuid(),
                    SubscriberId.Value,
                    CreatorId.Value,
                    Now.AddDays(1),
                    10,
                    LedgerAccountType.FifthweekCredit,
                    LedgerTransactionType.SubscriptionPayment,
                    Guid.NewGuid(),
                    Guid.NewGuid(),
                    null,
                    null,
                    null);

                await connection.InsertAsync(ledgerEntry, false);

                await connection.InsertAsync(ledgerEntry2, false);
            }
        }