Beispiel #1
0
        public void UserReposTest_ThrowsNullArgumentException()
        {
            var controller = new GitHubUserController(GitHubServiceMock.Object);
            var ex         = controller.UserRepos(null).Exception;

            Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException));
        }
Beispiel #2
0
        public void UserReposTest_1Result()
        {
            string repoUrl = "msx888";

            GitHubServiceMock.Setup(x => x.GetUserRepos(It.Is <string>(i => i == repoUrl))).Returns(Task.FromResult(new List <GitHubUserRepository>
            {
                new GitHubUserRepository
                {
                    Name            = "R1",
                    Description     = "Text",
                    StargazersCount = 0,
                    Updated         = DateTime.Now
                }
            }.AsEnumerable()));

            var controller = new GitHubUserController(GitHubServiceMock.Object);

            var result = controller.UserRepos(repoUrl).Result as PartialViewResult;
            var model  = (GitHubUserReposModel)result.Model;

            Assert.AreEqual(1, model.Repositories.Count());
        }
Beispiel #3
0
        public void UserReposTest_Return5FromSeveral()
        {
            string repoUrl = "msx888";

            GitHubServiceMock.Setup(x => x.GetUserRepos(It.Is <string>(i => i == repoUrl))).Returns(Task.FromResult(new List <GitHubUserRepository>
            {
                new GitHubUserRepository
                {
                    Name            = "R1",
                    Description     = "Text",
                    StargazersCount = 3,
                    Updated         = DateTime.Now
                },
                new GitHubUserRepository
                {
                    Name            = "R2",
                    Description     = "Text",
                    StargazersCount = 2,
                    Updated         = DateTime.Now
                },
                new GitHubUserRepository
                {
                    Name            = "R3",
                    Description     = "Text",
                    StargazersCount = 7,
                    Updated         = DateTime.Now
                },
                new GitHubUserRepository
                {
                    Name            = "R4",
                    Description     = "Text",
                    StargazersCount = 4,
                    Updated         = DateTime.Now
                },
                new GitHubUserRepository
                {
                    Name            = "R5",
                    Description     = "Text",
                    StargazersCount = 1,
                    Updated         = DateTime.Now
                },
                new GitHubUserRepository
                {
                    Name            = "R6",
                    Description     = "Text",
                    StargazersCount = 2,
                    Updated         = DateTime.Now
                }
            }.AsEnumerable()));

            var controller = new GitHubUserController(GitHubServiceMock.Object);

            var result = controller.UserRepos(repoUrl).Result as PartialViewResult;
            var model  = (GitHubUserReposModel)result.Model;

            Assert.AreEqual(5, model.Repositories.Count());
            Assert.AreEqual(7, model.Repositories.ToList()[0].StargazersCount);
            Assert.AreEqual(4, model.Repositories.ToList()[1].StargazersCount);
            Assert.AreEqual(3, model.Repositories.ToList()[2].StargazersCount);
            Assert.AreEqual(2, model.Repositories.ToList()[3].StargazersCount);
            Assert.AreEqual(2, model.Repositories.ToList()[4].StargazersCount);
        }