Exemple #1
0
        public async Task WhenCreatorPercentageIsSetWithNoExpiry_ItShouldReturnTheCreatorPercentage()
        {
            var creatorPercentageOverride = new CreatorPercentageOverrideData(0.9m, null);

            this.getAccountSettings.Setup(v => v.ExecuteAsync(UserId, FreePostTimestamp, PostConstants.MaximumFreePostsPerInterval))
            .ReturnsAsync(new GetAccountSettingsDbResult(
                              Username, Email, null, AccountBalance, PaymentStatus, HasPaymentInformation, creatorPercentageOverride, FreePostsRemaining))
            .Verifiable();

            var result = await this.target.HandleAsync(new GetAccountSettingsQuery(Requester, UserId, Now));

            this.getAccountSettings.Verify();

            var expectedResult = new GetAccountSettingsResult(
                Username,
                Email,
                null,
                AccountBalance,
                PaymentStatus,
                HasPaymentInformation,
                creatorPercentageOverride.Percentage,
                null,
                FreePostsRemaining);

            Assert.AreEqual(expectedResult, result);
        }
Exemple #2
0
        public async Task WhenCreatorPercentageIsSetWithExpiredExpiry_ItShouldReturnTheCreatorPercentageWithNumberOfWeeks1()
        {
            var paymentProcessingStartDateInclusive = PaymentProcessingUtilities.GetPaymentProcessingStartDate(Now);
            var creatorPercentageOverride           = new CreatorPercentageOverrideData(0.9m, paymentProcessingStartDateInclusive.AddDays(7).AddTicks(-1));

            this.getAccountSettings.Setup(v => v.ExecuteAsync(UserId, FreePostTimestamp, PostConstants.MaximumFreePostsPerInterval))
            .ReturnsAsync(new GetAccountSettingsDbResult(
                              Username, Email, null, AccountBalance, PaymentStatus, HasPaymentInformation, creatorPercentageOverride, FreePostsRemaining))
            .Verifiable();

            var result = await this.target.HandleAsync(new GetAccountSettingsQuery(Requester, UserId, Now));

            this.getAccountSettings.Verify();

            var expectedResult = new GetAccountSettingsResult(
                Username,
                Email,
                null,
                AccountBalance,
                PaymentStatus,
                HasPaymentInformation,
                Payments.Constants.DefaultCreatorPercentage,
                null,
                FreePostsRemaining);

            Assert.AreEqual(expectedResult, result);
        }
        public async Task WhenExaclyTwoWeeksAndCreatorPercentageOverrideSpecifiedAndExpiredInCommittedWeek_ItShouldNotIncludeInResults()
        {
            var creatorPercentageOverride = new CreatorPercentageOverrideData(
                0.9m,
                StartTimeInclusive.AddDays(7).AddTicks(-1));

            var data = this.CreateData(
                StartTimeInclusive,
                StartTimeInclusive.AddDays(14),
                creatorPercentageOverride);

            var cost1 = new AggregateCostSummary(10);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     data.CreatorPosts,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive,
                                                     data.StartTimeInclusive.AddDays(7))).Returns(cost1);

            var cost2 = new AggregateCostSummary(20);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     null,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive.AddDays(7),
                                                     data.EndTimeExclusive)).Returns(cost2);

            var result = await this.target.ExecuteAsync(data);

            Assert.AreEqual(
                new PaymentProcessingResults(
                    InitialCommittedAccountBalance.Subtract(cost1.Cost),
                    new List <PaymentProcessingResult>
            {
                new PaymentProcessingResult(
                    data.StartTimeInclusive,
                    data.StartTimeInclusive.AddDays(7),
                    cost1,
                    null,
                    true),
                new PaymentProcessingResult(
                    data.StartTimeInclusive.AddDays(7),
                    data.EndTimeExclusive,
                    cost2,
                    null,
                    false),
            }),
                result);
        }
Exemple #4
0
        internal static CreatorPercentageOverrideData GetCreatorPercentage(CreatorPercentageOverrideData creatorPercentageOverride, DateTime now)
        {
            var paymentProcessingStartDateInclusive = PaymentProcessingUtilities.GetPaymentProcessingStartDate(now);
            var paymentProcessingEndDateExclusive   = paymentProcessingStartDateInclusive.AddDays(7);

            var creatorPercentageOverrideResult = PaymentProcessingUtilities.GetCreatorPercentageOverride(
                creatorPercentageOverride, paymentProcessingEndDateExclusive);

            return(creatorPercentageOverrideResult
                   ?? new CreatorPercentageOverrideData(
                       Fifthweek.Payments.Constants.DefaultCreatorPercentage,
                       null));
        }
        public async Task WhenCreatorPercentageOverrideSpecifiedAndNoExpiry_ItShouldIncludeInResults()
        {
            var creatorPercentageOverride = new CreatorPercentageOverrideData(
                0.9m,
                null);

            var data = this.CreateData(
                StartTimeInclusive,
                StartTimeInclusive.AddDays(14).AddTicks(-1),
                creatorPercentageOverride);

            var cost = new AggregateCostSummary(10);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     null,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive,
                                                     data.EndTimeExclusive)).Returns(cost);

            var result = await this.target.ExecuteAsync(data);

            Assert.AreEqual(
                new PaymentProcessingResults(
                    InitialCommittedAccountBalance,
                    new List <PaymentProcessingResult>
            {
                new PaymentProcessingResult(
                    data.StartTimeInclusive,
                    data.EndTimeExclusive,
                    new AggregateCostSummary(10),
                    creatorPercentageOverride,
                    false),
            }),
                result);
        }
 private PaymentProcessingData CreateData(DateTime startTimeInclusive, DateTime endTimeExclusive, CreatorPercentageOverrideData creatorPercentageOverride = null)
 {
     return(new PaymentProcessingData(
                SubscriberId,
                CreatorId,
                startTimeInclusive,
                endTimeExclusive,
                InitialCommittedAccountBalance,
                new List <SubscriberChannelsSnapshot>
     {
         new SubscriberChannelsSnapshot(
             DateTime.UtcNow,
             UserId.Random(),
             new List <SubscriberChannelsSnapshotItem>
         {
             new SubscriberChannelsSnapshotItem(ChannelId.Random(), 100, DateTime.UtcNow),
             new SubscriberChannelsSnapshotItem(ChannelId.Random(), 110, DateTime.UtcNow),
         }),
     },
                new List <SubscriberSnapshot>
     {
         new SubscriberSnapshot(DateTime.UtcNow, UserId.Random(), "*****@*****.**"),
         new SubscriberSnapshot(DateTime.UtcNow, UserId.Random(), "*****@*****.**"),
     },
                new List <CalculatedAccountBalanceSnapshot>
     {
         new CalculatedAccountBalanceSnapshot(DateTime.UtcNow, UserId.Random(), LedgerAccountType.FifthweekCredit, 10),
     },
                new List <CreatorChannelsSnapshot>
     {
         new CreatorChannelsSnapshot(
             DateTime.UtcNow,
             UserId.Random(),
             new List <CreatorChannelsSnapshotItem>
         {
             new CreatorChannelsSnapshotItem(ChannelId.Random(), 200),
             new CreatorChannelsSnapshotItem(ChannelId.Random(), 300),
         }),
     },
                new List <CreatorFreeAccessUsersSnapshot>
     {
         new CreatorFreeAccessUsersSnapshot(
             DateTime.UtcNow,
             UserId.Random(),
             new List <string> {
             "*****@*****.**", "*****@*****.**"
         }),
     },
                new List <CreatorPost>
     {
         new CreatorPost(ChannelId.Random(), DateTime.UtcNow),
         new CreatorPost(ChannelId.Random(), DateTime.UtcNow),
     },
                creatorPercentageOverride));
 }
        public async Task WhenDataRepresentsMultipleWeeks_AndExceedsCommittedCredit_ItShouldReturnAdjustedResults()
        {
            var creatorPercentageOverride = new CreatorPercentageOverrideData(
                0.9m,
                StartTimeInclusive.AddDays(9));

            var data = this.CreateData(
                StartTimeInclusive,
                StartTimeInclusive.AddDays(23),
                creatorPercentageOverride);

            var cost1 = new AggregateCostSummary(60);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     data.CreatorPosts,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive,
                                                     data.StartTimeInclusive.AddDays(7))).Returns(cost1);

            var cost2 = new AggregateCostSummary(60);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     data.CreatorPosts,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive.AddDays(7),
                                                     data.StartTimeInclusive.AddDays(14))).Returns(cost2);

            var cost3 = new AggregateCostSummary(60);

            this.subscriberPaymentPipeline.Setup(v => v.CalculatePayment(
                                                     data.GetOrderedSnapshots(),
                                                     null,
                                                     SubscriberId,
                                                     CreatorId,
                                                     data.StartTimeInclusive.AddDays(14),
                                                     data.EndTimeExclusive)).Returns(cost3);

            var result = await this.target.ExecuteAsync(data);

            Assert.AreEqual(
                new PaymentProcessingResults(
                    new CommittedAccountBalance(0),
                    new List <PaymentProcessingResult>
            {
                new PaymentProcessingResult(
                    data.StartTimeInclusive,
                    data.StartTimeInclusive.AddDays(7),
                    new AggregateCostSummary(60),
                    creatorPercentageOverride,
                    true),
                new PaymentProcessingResult(
                    data.StartTimeInclusive.AddDays(7),
                    data.StartTimeInclusive.AddDays(14),
                    new AggregateCostSummary(40),
                    null,
                    true),
                new PaymentProcessingResult(
                    data.StartTimeInclusive.AddDays(14),
                    data.EndTimeExclusive,
                    new AggregateCostSummary(60),
                    null,
                    false),
            }),
                result);
        }