public void Search_SevenRepos()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddSevenReposForOrg1(moqGitea);
            Moq.Mock <ISourceControl> moqSourceControl = SourceControlMockHelper.GetMock();

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = new Mock <IOptions <ServiceRepositorySettings> >();
            Moq.Mock <IRepository>          moqRepository          = new Mock <IRepository>();
            Moq.Mock <IHttpContextAccessor> moqHttpContextAccessor = new Mock <IHttpContextAccessor>();

            AltinnCore.Designer.Controllers.RepositoryController controller = new AltinnCore.Designer.Controllers.RepositoryController(moqGitea.Object, moqServiceRepositorySettings.Object, moqSourceControl.Object, moqRepository.Object, moqHttpContextAccessor.Object);
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            List <Repository> result = controller.Search(repositorySearch);

            // Assert
            Assert.Equal(7, result.Count);
        }
Exemplo n.º 2
0
        public void Current_LoggedInUser()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.GetCurrentUser_ReturnsOne(moqGitea);

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();

            AltinnCore.Designer.Controllers.UserController controller = new AltinnCore.Designer.Controllers.UserController(moqGitea.Object, moqServiceRepositorySettings.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556")
            };
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            User result = controller.Current();

            // Assert
            Assert.NotNull(result);
        }
Exemplo n.º 3
0
        public void Organization_GetOrg_Valid()
        {
            // Arrange
            Moq.Mock <IGitea> moqGitea = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddOneOrg(moqGitea);
            Moq.Mock <ISourceControl> moqSourceControl = SourceControlMockHelper.GetMock();

            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();
            Moq.Mock <IRepository>          moqRepository          = new Mock <IRepository>();
            Moq.Mock <IHttpContextAccessor> moqHttpContextAccessor = new Mock <IHttpContextAccessor>();

            AltinnCore.Designer.Controllers.RepositoryController controller = new AltinnCore.Designer.Controllers.RepositoryController(moqGitea.Object, moqServiceRepositorySettings.Object, moqSourceControl.Object, moqRepository.Object, moqHttpContextAccessor.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556", false)
            };
            RepositorySearch repositorySearch = new RepositorySearch();

            // Act
            ActionResult <Organization> result = controller.Organization("MockOrg");

            // Assert
            Assert.NotNull(result.Value);
        }
Exemplo n.º 4
0
        public void Login_LogOutUser()
        {
            // Arrange
            Moq.Mock <IRepository> moqRepository = new Mock <IRepository>();
            Moq.Mock <ILogger <HomeController> >             moqLogger = new Mock <ILogger <HomeController> >();
            Moq.Mock <IHttpContextAccessor>                  moqHttpContextAccessor       = new Mock <IHttpContextAccessor>();
            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();

            Moq.Mock <IGitea> moqGiteaWrapper = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddSevenReposForOrg1(moqGiteaWrapper);

            Moq.Mock <ISourceControl> moqSourceControl = GetMoqSourceControlForIndexTest();

            User user = new User();

            user.Login = "******";
            moqGiteaWrapper.Setup(g => g.GetCurrentUser()).ReturnsAsync(user);

            AltinnCore.Designer.Controllers.HomeController controller = new AltinnCore.Designer.Controllers.HomeController(
                moqRepository.Object,
                moqLogger.Object,
                moqServiceRepositorySettings.Object,
                moqGiteaWrapper.Object,
                moqHttpContextAccessor.Object,
                moqSourceControl.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556", true)
            };

            // Act
            Task <IActionResult> result = controller.Logout();

            // Assert
            LocalRedirectResult redirectResult = Assert.IsType <LocalRedirectResult>(result.Result);

            Assert.Equal("/user/logout", redirectResult.Url);
        }
Exemplo n.º 5
0
        public void Login_LogInUser()
        {
            // Arrange
            Moq.Mock <IRepository> moqRepository = new Mock <IRepository>();
            Moq.Mock <ILogger <HomeController> >             moqLogger = new Mock <ILogger <HomeController> >();
            Moq.Mock <IHttpContextAccessor>                  moqHttpContextAccessor       = new Mock <IHttpContextAccessor>();
            Moq.Mock <IOptions <ServiceRepositorySettings> > moqServiceRepositorySettings = SettingsHelper.GetMoqServiceRepositorySettings();

            Moq.Mock <IGitea> moqGiteaWrappeer = IGiteaMockHelper.GetMock();
            IGiteaMockHelper.AddSevenReposForOrg1(moqGiteaWrappeer);

            Moq.Mock <ISourceControl> moqSourceControl = GetMoqSourceControlForIndexTest();

            moqGiteaWrappeer.Setup(g => g.GetUserNameFromUI()).ReturnsAsync("Test");

            moqGiteaWrappeer.Setup(g => g.GetSessionAppKey(null)).ReturnsAsync(new System.Collections.Generic.KeyValuePair <string, string>("123", "Test"));

            AltinnCore.Designer.Controllers.HomeController controller = new AltinnCore.Designer.Controllers.HomeController(
                moqRepository.Object,
                moqLogger.Object,
                moqServiceRepositorySettings.Object,
                moqGiteaWrappeer.Object,
                moqHttpContextAccessor.Object,
                moqSourceControl.Object)
            {
                ControllerContext = ControllerContextHelper.GetControllerContextWithValidGiteaSession("234543556", true)
            };

            // Act
            Task <IActionResult> result = controller.Login();

            // Assert
            LocalRedirectResult redirectResult = Assert.IsType <LocalRedirectResult>(result.Result);

            Assert.Equal("/", redirectResult.Url);
        }