public void Converter_Zero_Epoch() { var expected = new DateTime(1970, 1, 1); var actual = DateTimeUnixConverter.FromUnixTimestamp(0); Assert.AreEqual(expected, actual); }
public void Converter_Current_CurrentDate() { var expected = DateTime.Parse("2015-07-07T14:19:56+00:00"); var actual = DateTimeUnixConverter.FromUnixTimestamp(1436282396); Assert.AreEqual(expected, actual); }
private RestRequest createRequest(string resourcePath) { var request = new RestRequest(resourcePath) { Method = Method.GET }; //post not work. why? var jss = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; if (!String.IsNullOrEmpty(where)) { request.AddParameter("where", where); } if ((objectIds != null) && (objectIds.Count > 0)) { request.AddParameter("objectIds", String.Join(", ", objectIds)); } if (geometry != null) { request.AddParameter("geometry", JsonConvert.SerializeObject(geometry, jss)); } if (!String.IsNullOrEmpty(geometryType)) { request.AddParameter("geometryType", geometryType); } if (inSR != null) { request.AddParameter("inSR", JsonConvert.SerializeObject(inSR, jss)); } if (!String.IsNullOrEmpty(spatialRel)) { request.AddParameter("spatialRel", spatialRel); } if (!String.IsNullOrEmpty(relationParam)) { request.AddParameter("relationParam", relationParam); } if (timeInstant.HasValue) { request.AddParameter("time", JsonConvert.SerializeObject(timeInstant, new DateTimeUnixConverter())); } else { if (startTime.HasValue && endTime.HasValue) { var converter = new DateTimeUnixConverter(); string timeExtent = String.Format("{0}, {1}", JsonConvert.SerializeObject(startTime, converter), JsonConvert.SerializeObject(endTime, converter)); request.AddParameter("time", timeExtent); } } if (!String.IsNullOrEmpty(outFields)) { request.AddParameter("outFields", outFields); } if (returnGeometry.HasValue) { request.AddParameter("returnGeometry", returnGeometry.Value ? "true" : "false"); } if (maxAllowableOffset.HasValue) { request.AddParameter("maxAllowableOffset", maxAllowableOffset); } if (geometryPrecision.HasValue) { request.AddParameter("geometryPrecision", geometryPrecision); } if (outSR != null) { request.AddParameter("outSR", JsonConvert.SerializeObject(outSR, jss)); } if (!String.IsNullOrEmpty(gdbVersion)) { request.AddParameter("gdbVersion", gdbVersion); } if (returnDistinctValues.HasValue) { request.AddParameter("returnDistinctValues", returnDistinctValues.Value ? "true" : "false"); } if (returnIdsOnly.HasValue) { request.AddParameter("returnIdsOnly", returnIdsOnly.Value ? "true" : "false"); } if (returnCountOnly.HasValue) { request.AddParameter("returnCountOnly", returnCountOnly.Value ? "true" : "false"); } if (!String.IsNullOrWhiteSpace(orderByFields)) { request.AddParameter("orderByFields", orderByFields); } if (!String.IsNullOrWhiteSpace(groupByFieldsForStatistics)) { request.AddParameter("groupByFieldsForStatistics", groupByFieldsForStatistics); } if (outStatistics != null) { request.AddParameter("outStatistics", JsonConvert.SerializeObject(outStatistics, jss)); } if (returnZ.HasValue) { request.AddParameter("returnZ", returnZ.Value ? "true" : "false"); } if (returnM.HasValue) { request.AddParameter("returnM", returnM.Value ? "true" : "false"); } request.AddParameter("f", "json"); return(request); }
public async Task <IEnumerable <UserPostsModel> > GetSubreddit(string domain) { var url = _reddit.RetrieveUrlWithDomain(domain); var posts = await _reddit.GetPathAsync(url); var callId = Guid.NewGuid().ToString(); var postsWithCallId = posts.Select(x => { x.CallId = callId; return(x); }); await _repository.SavePostsAsync(postsWithCallId); var retrievedPosts = _repository.GetPosts(callId); return(retrievedPosts.GroupBy(x => x.Author) .Select(x => new UserPostsModel { Author = x.Key, Posts = x.Select(y => new PostDto { Id = y.Id, PermaLink = y.Permalink, Title = y.Title, CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(y.Created) }).ToList() })); }
public async Task Controller_UsingADomain_AllDBSavesHaveDomain() { var controller = new RedditController(new MixedDomainRedditAccess(), new MockRepository()); var posts = await controller.GetSubreddit("bbc.com"); var expected = new List <UserPostsModel> { new UserPostsModel { Author = "Account1", Posts = new List <PostDto> { new PostDto { Id = "1", Title = "1", CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0), PermaLink = "link" }, new PostDto { Id = "2", Title = "2", CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0), PermaLink = "link" } } }, new UserPostsModel { Author = "Account2", Posts = new List <PostDto> { new PostDto { Id = "3", Title = "3", CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0), PermaLink = "link" }, new PostDto { Id = "4", Title = "4", CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0), PermaLink = "link" } } }, new UserPostsModel { Author = "Account3", Posts = new List <PostDto> { new PostDto { Id = "5", Title = "5", CreatedDate = DateTimeUnixConverter.FromUnixTimestamp(1436282396.0), PermaLink = "link" } } } }; var actualList = posts.ToList(); Assert.AreEqual(expected, actualList); }