Exemplo n.º 1
0
        internal virtual IDictionary <string, string> GetFilterDictionary()
        {
            var dict = new Dictionary <string, string>();

            if (Limit.HasValue)
            {
                dict["limit"] = Limit.Value.ToString();
            }

            if (IncludeTotalCount)
            {
                dict["include[]"] = "total_count";
            }

            if (CreatedAfter.HasValue || CreatedBefore.HasValue)
            {
                var obj = new
                {
                    gt = CreatedAfter?.ToString("o"),
                    lt = CreatedBefore?.ToString("o")
                };
                dict["date_created"] = JsonConvert.SerializeObject(obj, Formatting.None, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
            }

            return(dict);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Used to convert a <code>Search Query</code> object to an easy to serialze dictionary
        /// </summary>
        /// <returns>returns String, Object dictionary</returns>
        public Dictionary <string, object> ToDictionary()
        {
            var dict = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(Id))
            {
                dict.Add(IdField, Id);
            }
            if (!string.IsNullOrEmpty(Source))
            {
                dict.Add(SourceField, Source);
            }
            if (!string.IsNullOrEmpty(Status))
            {
                dict.Add(StatusField, Status);
            }
            if (Page.HasValue)
            {
                dict.Add(PageField, Page.Value);
            }
            if (CreatedAfter.HasValue)
            {
                dict.Add(CreatedAfterField, CreatedAfter?.ToString("O"));
            }
            if (CreatedBefore.HasValue)
            {
                dict.Add(CreatedBeforeField, CreatedBefore?.ToString("O"));
            }

            return(dict.Count > 0 ? dict : null);
        }
Exemplo n.º 3
0
        public void IsSatisfiedBy_WhenCreatedAfterIsAfterValue_ReturnsTrue()
        {
            var createdAfter = DateTime.UtcNow;
            var item         = new TestEntity
            {
                CreatedOn = createdAfter
            };
            var specification = new CreatedAfter <TestEntity>(createdAfter.AddDays(-1));
            var satisified    = specification.IsSatisfiedBy(item);

            Assert.IsTrue(satisified);
        }