Ejemplo n.º 1
0
        public void GetLocationsAsync()
        {
            var locations = _locationsService.GetActiveLocationsAsync(CancellationToken.None, Mark.CreateNew()).Result;

            Assert.IsNotNull(locations);
            Assert.AreNotEqual(0, locations.Count());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///	Returns orders created/modified between the start and end date
        /// </summary>
        /// <param name="startDateUtc"></param>
        /// <param name="endDateUtc"></param>
        /// <param name="token">Cancellation token for cancelling call to endpoint</param>
        /// <returns></returns>
        public async Task <IEnumerable <SquareOrder> > GetOrdersAsync(DateTime startDateUtc, DateTime endDateUtc, CancellationToken token)
        {
            Condition.Requires(startDateUtc).IsLessThan(endDateUtc);

            var mark = Mark.CreateNew();

            if (token.IsCancellationRequested)
            {
                var exceptionDetails = CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo());
                var squareException  = new SquareException(string.Format("{0}. Get orders request was cancelled", exceptionDetails));
                SquareLogger.LogTraceException(squareException);
                throw squareException;
            }

            IEnumerable <SquareOrder> response = null;

            try
            {
                SquareLogger.LogStarted(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo()));

                var locations = await _locationsService.GetActiveLocationsAsync(token, mark).ConfigureAwait(false);

                SquareLogger.LogTrace(this.CreateMethodCallInfo("", mark, payload: locations.ToJson(), additionalInfo: this.AdditionalLogInfo()));

                response = await CollectOrdersFromAllPagesAsync(startDateUtc, endDateUtc, locations,
                                                                (requestBody) => GetOrdersWithRelatedDataAsync( requestBody, token, mark ), this.Config.OrdersPageSize).ConfigureAwait(false);

                SquareLogger.LogEnd(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo()));
            }
            catch (Exception ex)
            {
                var squareException = new SquareException(this.CreateMethodCallInfo("", mark, additionalInfo: this.AdditionalLogInfo()), ex);
                SquareLogger.LogTraceException(squareException);
                throw squareException;
            }

            return(response);
        }