Exemplo n.º 1
0
        public void Ensure_Action_Returns_OnError_If_UserRepository_Is_Null()
        {
            var logger     = A.Fake <ILogger>();
            var gitService = A.Fake <IGitService>();

            var user = new GitUserDto()
            {
                AvatarUrl = "Url",
                Location  = "location",
                Name      = "Test user"
            };

            A.CallTo(() => gitService.GetGitUser(null)).WithAnyArguments().Returns(new GetGitUserResult()
            {
                User = user
            });

            A.CallTo(() => gitService.GetGitUserRepositories(null)).WithAnyArguments().Returns(null);

            var result = new GetUserRepositoriesAction <dynamic>(gitService, logger)
            {
                OnSuccess = (m) => new { success = true, model = m },
                OnFailed  = (m) => new { success = false },
                OnError   = (errors) => new { error = true, notifications = errors }
            }.Execute("username");

            Assert.IsTrue(result.error);
        }
Exemplo n.º 2
0
        public void Ensure_Action_Returns_User_If_Repository_Is_Empty()
        {
            var logger     = A.Fake <ILogger>();
            var gitService = A.Fake <IGitService>();

            var user = new GitUserDto()
            {
                AvatarUrl = "Url",
                Location  = "location",
                Name      = "Test user"
            };

            A.CallTo(() => gitService.GetGitUser(null)).WithAnyArguments().Returns(new GetGitUserResult()
            {
                User = user
            });

            var repos = new List <GitRepositoryDto>()
            {
            };

            A.CallTo(() => gitService.GetGitUserRepositories(null)).WithAnyArguments().Returns(new GetGitRepositoriesResult()
            {
                Repositories = repos
            });

            var result = new GetUserRepositoriesAction <dynamic>(gitService, logger)
            {
                OnSuccess = (m) => new { success = true, model = m },
                OnFailed  = (m) => new { success = false },
                OnError   = (errors) => new { inerror = false }
            }.Execute("username");

            Assert.IsTrue(result.success);
            Assert.IsNotNull(result.model);
            Assert.AreEqual(result.model.User.Name, user.Name);
            Assert.AreEqual(result.model.User.AvatarUrl, user.AvatarUrl);
            Assert.AreEqual(result.model.User.Location, user.Location);

            Assert.IsTrue(result.model.Repositories.Count == 0);
        }
        private GitUserDto GetGitUser(string username)
        {
            var user       = new GitUserDto();
            var userResult = GitService.GetGitUser(new GetGitUserRequest(username));

            if (userResult.IsNull() || userResult.User.IsNull())
            {
                Logger.Error("The user returned by the git service was null. Username - {0}".FormatInvariantCulture(username));
                Notifications.AddError(Errors.GetGitUserError.FormatInvariantCulture(username));
            }

            if (!Notifications.HasErrors())
            {
                user = userResult.User;
            }

            if (!Notifications.HasErrors() && !userResult.IsValid())
            {
                Notifications.AddMessage(new Notification(Messages.NoUserFound.FormatInvariantCulture(username)));
            }

            return(user);
        }
Exemplo n.º 4
0
        public void Ensure_Action_Returns_Returns_A_Sorted_Repository_By_StargazersCount_Desc()
        {
            var logger     = A.Fake <ILogger>();
            var gitService = A.Fake <IGitService>();

            var user = new GitUserDto()
            {
                AvatarUrl = "Url",
                Location  = "location",
                Name      = "Test user"
            };

            A.CallTo(() => gitService.GetGitUser(null)).WithAnyArguments().Returns(new GetGitUserResult()
            {
                User = user
            });

            var repos = new List <GitRepositoryDto>()
            {
                new GitRepositoryDto()
                {
                    Name = "Test repo", StargazersCount = 12
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 1", StargazersCount = 15
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 2", StargazersCount = 125
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 3", StargazersCount = 142
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 4", StargazersCount = 132
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 5", StargazersCount = 1
                },
                new GitRepositoryDto()
                {
                    Name = "Test repo 6", StargazersCount = 122
                }
            };

            A.CallTo(() => gitService.GetGitUserRepositories(null)).WithAnyArguments().Returns(new GetGitRepositoriesResult()
            {
                Repositories = repos
            });

            var result = new GetUserRepositoriesAction <dynamic>(gitService, logger)
            {
                OnSuccess = (m) => new { success = true, model = m },
                OnFailed  = (m) => new { failed = false },
                OnError   = (errors) => new { inError = false }
            }.Execute("username");

            var sortedRepo = (from r in repos
                              orderby r.StargazersCount descending
                              select r)
                             .ToList();


            Assert.IsTrue(result.success);
            Assert.IsNotNull(result.model);

            for (var i = 0; i < result.model.Repositories.Count; i++)
            {
                Assert.AreEqual(sortedRepo[i].Name, result.model.Repositories[i].Name);
                Assert.AreEqual(sortedRepo[i].StargazersCount, result.model.Repositories[i].StargazersCount);
            }
        }
 public GetGitUserResult()
 {
     this.User = new GitUserDto();
 }