Exemple #1
0
        public string GetFreeSubscriptionPlanId(string applicationId)
        {
            var app = _appDirectApi.GetExtendedAppInfo(applicationId);

            foreach (var edition in app.Pricing.Editions)
            {
                foreach (var plan in edition.Plans)
                {
                    var isFreePlan = true;

                    foreach (var cost in plan.Costs)
                    {
                        if (cost.MeteredUsage.HasValue && (cost.MeteredUsage == true))
                        {
                            isFreePlan = false;
                            break;
                        }

                        var isFreeCost = true;

                        foreach (var amount in cost.Amounts)
                        {
                            if (amount.Value.HasValue && (amount.Value > Decimal.Zero))
                            {
                                isFreeCost = false;
                                break;
                            }
                        }

                        if (!isFreeCost)
                        {
                            isFreePlan = false;
                            break;
                        }
                    }

                    if (isFreePlan)
                    {
                        return(plan.Id);
                    }
                }
            }

            return(null);
        }
        public void GetFreeSubscriptionPlanIdReturnsNullForNoFreeProduct()
        {
            string _applicationId = "test352";
            var    testProduct    = _serializer.Deserialize <Product>(_testProductXml);

            foreach (var edition in testProduct.Pricing.Editions)
            {
                foreach (var plan in edition.Plans)
                {
                    foreach (var cost in plan.Costs)
                    {
                        foreach (var amount in cost.Amounts)
                        {
                            amount.Value = 5m;
                        }
                    }
                }
            }

            _appDirectApiMock.GetExtendedAppInfo(_applicationId).Returns(testProduct);

            Assert.IsNull(_cachedAppDirectApi.GetFreeSubscriptionPlanId(_applicationId));
        }