예제 #1
0
        public void Check_TimeResolution_Hour_Should_Return_String_h()
        {
            var type = TimeResolution.HOUR;

            var name = EnumLookup.GetTimeResolutionName(type);

            Assert.Equal("h", name);
        }
예제 #2
0
        public void Check_TimeResolution_Day_Should_Return_String_d()
        {
            var type = TimeResolution.DAY;

            var name = EnumLookup.GetTimeResolutionName(type);

            Assert.Equal("d", name);
        }
예제 #3
0
        public void Check_TimeResolution_Month_Should_Return_String_m()
        {
            var type = TimeResolution.MONTH;

            var name = EnumLookup.GetTimeResolutionName(type);

            Assert.Equal("m", name);
        }
예제 #4
0
        ///  <summary>
        ///  Returns the properties as a query string to be used in an HTTP request.
        ///
        ///  Datetime fields start and end window ranges will be converted into unix epoch format.
        ///  </summary>
        /// <exception cref="ArgumentOutOfRangeException">Starting Date cannot be after ending date for datetime range.</exception>
        /// <returns>string value as a http query string.</returns>
        public string ToQueryString()
        {
            var queryStringBuilder = new QueryStringBuilder();

            if (!this.End.HasValue)
            {
                this.End = this.provider.Now();
            }

            if (!this.Start.HasValue)
            {
                this.Start = this.provider.Now().Minus(NodaTime.Duration.FromDays(7));
            }

            if (this.Start.Value.CompareTo(this.End.Value) > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(this.Start), "The starting date range window cannot be after the ending date range.");
            }

            if (this.Duration.HasValue && this.Resolution.HasValue)
            {
                queryStringBuilder.Append("duration", $"{this.Duration.Value}{EnumLookup.GetTimeResolutionName(this.Resolution.Value)}");
            }
            else
            {
                queryStringBuilder.Append("start", this.Start.Value.ToRfc2822DateFormat())
                .Append("end", this.End.Value.ToRfc2822DateFormat());
            }

            if (this.EventTypes != null && this.EventTypes.Count > 0)
            {
                foreach (var eventType in this.EventTypes)
                {
                    queryStringBuilder.Append("event", EnumLookup.GetEventTypeName(eventType));
                }
            }

            return(queryStringBuilder.ToString());
        }