Пример #1
0
        public async Task TestGetDomainsCurrentAllocatedBillings()
        {
            var quota = new Domain.ValueObjects.Resources(1, 20, 30);

            nju.Quota = quota.Clone();
            pku.Quota = quota.Clone();
            db.BillingCycleEntries.Add(new BillingCycleEntry(nju.BillingCycleSubject));
            db.BillingCycleEntries.Add(new BillingCycleEntry(pku.BillingCycleSubject));
            await db.SaveChangesAsync();

            var(service, billingTask, _) = CreateService(systemTokenClaims);

            await WaitForTaskForExecuteCycles(billingTask, billingConfiguration.CheckCycleMs, 2);

            var resp = await service.GetCurrentAllocatedBillings(new GetCurrentAllocatedBillingsRequest
            {
                SubjectType = Protos.Common.SubjectType.Domain
            }, TestContext);

            Assert.Equal(2, resp.Billings.Count);

            // the content should be the same with GetCurrentUsedBilling
        }
Пример #2
0
        public async Task TestChangeProjectUserResourcesOnSocialProject()
        {
            var socialDomain                 = db.Domains.Find(Constants.SocialDomainId);
            var lqsocialproject              = new Project(Guid.NewGuid(), lq, socialDomain, Domain.ValueObjects.Resources.QuotaForSocialProject);
            var lqlqsocialproject            = new UserProjectAssignment(Guid.NewGuid(), lq, lqsocialproject, Domain.ValueObjects.Resources.QuotaForSocialProject);
            var lqlqsocialprojectTokenClaims = new TokenClaims(false, true, lq.Id, Constants.SocialDomainId, lqsocialproject.Id, lqlqsocialproject.Id, UserRole.Admin);

            // set this token as a social project token.
            var initial = new Domain.ValueObjects.Resources(3, 4, 5);

            lqlqsocialproject.Resources = initial.Clone();
            db.UseCycleEntries.Add(new UseCycleEntry(lqlqsocialproject.UseCycleSubject));
            db.UseCycleEntries.Add(new UseCycleEntry(lqsocialproject.UseCycleSubject));
            db.BillingCycleEntries.Add(new BillingCycleEntry(lqlqsocialproject.BillingCycleSubject));
            db.BillingCycleEntries.Add(new BillingCycleEntry(lqsocialproject.BillingCycleSubject));
            await db.SaveChangesAsync();

            var service = CreateService(lqlqsocialprojectTokenClaims);
            // change delta
            var delta = new Domain.ValueObjects.Resources(-3, -4, -5);

            await service.ChangeProjectUserResources(new Protos.Interop.ChangeProjectUserResourcesRequest
            {
                ResourcesDelta = delta.ToGrpc()
            }, TestContext);

            // 1 allocated billing with 0 amount to be allocated to user.
            var billing = Assert.Single(lqlqsocialproject.BillingCycleRecords);

            Assert.Equal(0, billing.Amount);


            // No resources is now being used
            Assert.Equal(Domain.ValueObjects.Resources.Zero, lqsocialproject.Resources);

            // lq should pay the resources price
            // the previous 0 allocated billing should also be included
            AssertIEnumerableIgnoreOrder(new[] { PricePlan.Instance.Calculate(initial), 0 }, lq.PayedUserTransactions.Select(x => x.Amount));
        }
Пример #3
0
        public async Task TestGetProjectsCurrentAllocatedBillings()
        {
            var quota = new Domain.ValueObjects.Resources(1, 20, 30);

            lqproject.Quota = quota.Clone();
            db.BillingCycleEntries.Add(new BillingCycleEntry(lqproject.BillingCycleSubject));
            await db.SaveChangesAsync();

            var(service, billingTask, _) = CreateService(njuadminnjuTokenClaims);

            await WaitForTaskForExecuteCycles(billingTask, billingConfiguration.CheckCycleMs, 2);

            var resp = await service.GetCurrentAllocatedBillings(new GetCurrentAllocatedBillingsRequest
            {
                SubjectType = Protos.Common.SubjectType.Project
            }, TestContext);

            var billing = Assert.Single(resp.Billings);

            Assert.Equal(PricePlan.Instance.Calculate(quota), (decimal)billing.Amount);
            Assert.Equal(lq.Id.ToString(), billing.PayerId);
            Assert.Equal(quota.ToGrpc(), billing.Quota);
        }
Пример #4
0
        public async Task TestGetUsersCurrentAllocatedBillings()
        {
            var quota = new Domain.ValueObjects.Resources(1, 20, 30);

            cjd67project.Quota = quota.Clone();
            db.BillingCycleEntries.Add(new BillingCycleEntry(cjd67project.BillingCycleSubject));
            await db.SaveChangesAsync();

            var(service, billingTask, _) = CreateService(lqlqTokenClaims);

            await WaitForTaskForExecuteCycles(billingTask, billingConfiguration.CheckCycleMs, 2);

            var resp = await service.GetCurrentAllocatedBillings(new GetCurrentAllocatedBillingsRequest
            {
                SubjectType = Protos.Common.SubjectType.UserProjectAssignment
            }, TestContext);

            var billing = Assert.Single(resp.Billings);

            // User does not pay, but will know how much they should have paid.
            Assert.Equal(PricePlan.Instance.Calculate(quota), (decimal)billing.Amount);
            Assert.Equal(cjd.Id.ToString(), billing.PayerId);
            Assert.Equal(quota.ToGrpc(), billing.Quota);
        }