public void Check_Event_Type_Name_Accepted_Should_Return_String_accepted()
        {
            var type = EventType.ACCEPTED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("accepted", name);
        }
        public void Check_Event_Type_Name_Stored_Should_Return_String_stored()
        {
            var type = EventType.STORED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("stored", name);
        }
        public void Check_Event_Type_Name_Unsubscribed_Should_Return_String_unsubscribed()
        {
            var type = EventType.UNSUBSCRIBED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("unsubscribed", name);
        }
        public void Check_Event_Type_Name_Failed_Should_Return_String_failed()
        {
            var type = EventType.FAILED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("failed", name);
        }
        public void Check_Event_Type_Name_Opened_Should_Return_String_opened()
        {
            var type = EventType.OPENED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("opened", name);
        }
        public void Check_Event_Type_Name_Delivered_Should_Return_String_delivered()
        {
            var type = EventType.DELIVERED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("delivered", name);
        }
        public void Check_Event_Type_Name_Complained_Should_Return_String_complained()
        {
            var type = EventType.COMPLAINED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("complained", name);
        }
        public void Check_Event_Type_Name_Clicked_Should_Return_String_clicked()
        {
            var type = EventType.CLICKED;

            var name = EnumLookup.GetEventTypeName(type);

            Assert.Equal("clicked", name);
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
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());
        }