Example #1
0
        public void Check_Severity_Type_Temporary_Should_Return_string_temporary()
        {
            var type = Severity.TEMPORARY;

            var name = EnumLookup.GetSeverityTypeName(type);

            Assert.Equal("temporary", name);
        }
Example #2
0
        public void Check_Severity_Type_Permanent_Should_Return_string_permanent()
        {
            var type = Severity.PERMANENT;

            var name = EnumLookup.GetSeverityTypeName(type);

            Assert.Equal("permanent", name);
        }
Example #3
0
        /// <summary>
        /// Get the event request object as a query string to be used in an http request.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">The limit cannot have a minimum value less than an one or greater than maximum value 300, and message size cannot be less than 1 byte, if provided.</exception>
        /// <returns>string</returns>
        public string ToQueryString()
        {
            if (this.Limit < 1 || this.Limit > MAX_RESULT_LIMIT)
            {
                throw new ArgumentOutOfRangeException(nameof(this.Limit), this.Limit, "Limit has to be provided and cannot be less than a minimum value of 1 or a maximum value of 300!");
            }

            var queryStringBuilder = new QueryStringBuilder();

            queryStringBuilder.Append("limit", this.Limit.ToString());

            if (this.Begin.HasValue)
            {
                queryStringBuilder.Append("begin", this.Begin.Value.ToRfc2822DateFormat());
            }

            if (this.End.HasValue)
            {
                queryStringBuilder.Append("end", this.End.Value.ToRfc2822DateFormat());
            }

            if (this.Ascending.HasValue)
            {
                queryStringBuilder.Append("ascending", this.Ascending.Value.ToYesNo());
            }

            if (this.Pretty.HasValue)
            {
                queryStringBuilder.Append("pretty", this.Pretty.Value.ToYesNo());
            }

            if (!this.MessageId.IsNullEmptyWhitespace())
            {
                queryStringBuilder.Append("message-id", this.MessageId);
            }

            if (this.Recipient != null)
            {
                queryStringBuilder.Append("recipient", this.Recipient.Address);
            }

            if (this.To != null)
            {
                queryStringBuilder.Append("to", this.To.Address);
            }

            if (this.Size.HasValue)
            {
                if (this.Size.Value < 1)
                {
                    throw new ArgumentOutOfRangeException(nameof(this.Size), this.Size, "Message size cannot be less than 1 byte!");
                }

                queryStringBuilder.Append("size", this.Size.ToString());
            }

            if (!this.AttachmentFileName.IsNullEmptyWhitespace())
            {
                queryStringBuilder.Append("attachment", this.AttachmentFileName);
            }

            if (this.From != null)
            {
                queryStringBuilder.Append("from", this.From.Address);
            }

            if (!this.Subject.IsNullEmptyWhitespace())
            {
                queryStringBuilder.Append("subject", this.Subject);
            }

            var eventTypeCount = this.EventTypes.Count;

            if (this.EventTypes != null && eventTypeCount > 0)
            {
                var stringBuilder = new StringBuilder();

                if (eventTypeCount > 1)
                {
                    stringBuilder.Append("(");
                }

                var i = 0;

                foreach (var type in this.EventTypes)
                {
                    stringBuilder.Append(EnumLookup.GetEventTypeName(type));

                    i++;

                    if (eventTypeCount > 1 && i >= eventTypeCount)
                    {
                        stringBuilder.Append(" or ");
                    }
                }

                if (eventTypeCount > 1)
                {
                    stringBuilder.Append(")");
                }

                if (!stringBuilder.IsEmpty())
                {
                    queryStringBuilder.Append("event", stringBuilder.ToString());
                }
            }

            if (this.SeverityType.HasValue)
            {
                queryStringBuilder.Append("severity", EnumLookup.GetSeverityTypeName(this.SeverityType.Value));
            }

            var tagCount = this.EventTypes.Count;

            if (this.Tags != null && tagCount > 0)
            {
                var stringBuilder = new StringBuilder();

                if (tagCount == 1)
                {
                    stringBuilder.Append("");
                }
                else
                {
                    stringBuilder.Append("(");
                }

                var i = 0;

                foreach (var tag in this.Tags)
                {
                    stringBuilder.Append(tag);

                    i++;

                    if (tagCount > 1 && i >= tagCount)
                    {
                        stringBuilder.Append(" or ");
                    }
                }

                if (tagCount > 1)
                {
                    stringBuilder.Append(")");
                }

                if (!stringBuilder.IsEmpty())
                {
                    queryStringBuilder.Append("tags", stringBuilder.ToString());
                }
            }

            return(queryStringBuilder.ToString());
        }