private string SerializeToString(SubscriptionWS sub)
        {
            var textWriter = new StringWriter();

            _xmlSerializer.Serialize(textWriter, sub);
            var xml = textWriter.ToString();

            return(xml);
        }
Пример #2
0
        public void SubscribeThrowsErrorForNullCompany()
        {
            var _subscriptionWs = new SubscriptionWS();
            var user            = new UserWS()
            {
                id = "1"
            };

            _subscriptionWs.paymentPlanId = "0";
            _subscriptionWs.user          = user;

            Assert.Throws <ArgumentNullException>(() => _appDirectApi.SubscribeUser(_subscriptionWs));
        }
Пример #3
0
        public void SubscribeThrowsErrorForNullUser()
        {
            var _subscriptionWs = new SubscriptionWS();
            var company         = new CompanyWS()
            {
                id = "2"
            };

            _subscriptionWs.paymentPlanId = "0";
            _subscriptionWs.company       = company;

            Assert.Throws <ArgumentNullException>(() => _appDirectApi.SubscribeUser(_subscriptionWs));
        }
Пример #4
0
        public void SubscribeUserNullWhenNotAuthenticated()
        {
            var _subscriptionWs = new SubscriptionWS();
            var user            = new UserWS()
            {
                id = "1"
            };
            var company = new CompanyWS()
            {
                id = "2"
            };

            _subscriptionWs.paymentPlanId = "0";
            _subscriptionWs.user          = user;
            _subscriptionWs.company       = company;

            Assert.IsNull(_appDirectApi.SubscribeUser(_subscriptionWs));
        }
        public void Init()
        {
            _xmlSerializer = new XmlSerializer(typeof(SubscriptionWS));

            _subscriptionWs = new SubscriptionWS();
            var user = new UserWS()
            {
                id = "1"
            };
            var company = new CompanyWS()
            {
                id = "2"
            };

            _subscriptionWs.paymentPlanId = "0";
            _subscriptionWs.user          = user;
            _subscriptionWs.company       = company;

            _serializedXml = SerializeToString(_subscriptionWs);
        }
Пример #6
0
        public string ProvisionApplication(string userId, string companyId, string pricingPlanId)
        {
            if (!IsAuthenticated)
            {
                return(null);
            }

            var subscriptionWs = new SubscriptionWS();

            subscriptionWs.paymentPlanId = pricingPlanId;
            subscriptionWs.user          = new UserWS()
            {
                id = userId
            };
            subscriptionWs.company = new CompanyWS()
            {
                id = companyId
            };

            var resultSubscription = _appDirectApi.SubscribeUser(subscriptionWs);

            return(resultSubscription.id);
        }
Пример #7
0
        public SubscriptionWS SubscribeUser(SubscriptionWS subscriptionWs)
        {
            if (subscriptionWs == null)
            {
                throw new ArgumentNullException("subscriptionWs");
            }

            if (subscriptionWs.user == null)
            {
                throw new ArgumentNullException("subscriptionWs.user");
            }

            if (subscriptionWs.company == null)
            {
                throw new ArgumentNullException("subscriptionWs.company");
            }

            if (subscriptionWs.paymentPlanId == null)
            {
                throw new ArgumentNullException("subscriptionWs.paymentPlanId");
            }

            if (!IsAuthenticated)
            {
                return(null);
            }

            var requestUrl = OAuthBase.GetOAuthSignedUrl(SubscribeTemplateUrl, postMethod);

            Console.WriteLine(requestUrl);

            var request = BuildHttpWebRequestForUrl(requestUrl, true, false);

            request.ContentType = "application/xml";

            var outStream = request.GetRequestStream();

            _subscriptionSerializer.Serialize(outStream, subscriptionWs);
            outStream.Close();

            HttpWebResponse response;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                var exceptionResponse = (HttpWebResponse)ex.Response;

                if (exceptionResponse.StatusCode == HttpStatusCode.Conflict)
                {
                    throw new ConflictException();
                }
                if ((int)exceptionResponse.StatusCode == 424)
                {
                    throw new FailedDependencyException();
                }

                throw;
            }

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(null);
            }

            var responseStream = response.GetResponseStream();

            if (responseStream == null)
            {
                throw new IOException("No response stream returned");
            }

            var result = _subscriptionSerializer.Deserialize(responseStream) as SubscriptionWS;

            return(result);
        }