Пример #1
0
        public void Converter_Zero_Epoch()
        {
            var expected = new DateTime(1970, 1, 1);
            var actual   = DateTimeUnixConverter.FromUnixTimestamp(0);

            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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()
            }));
        }
Пример #4
0
        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);
        }