public void Index_GetSevenReposFromOrgWhereFourIsClonedLocallyOnlyLocallyClonedListed() { // 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 = new Mock <IOptions <ServiceRepositorySettings> >(); Moq.Mock <IGitea> moqGiteaWrappeer = IGiteaMockHelper.GetMock(); IGiteaMockHelper.AddSevenReposForOrg1(moqGiteaWrappeer); Moq.Mock <ISourceControl> moqSourceControl = this.GetMoqSourceControlForIndexTest(); RepositorySearch repositorySearch = new RepositorySearch(); repositorySearch.OnlyLocalRepositories = true; AltinnCore.Designer.Controllers.HomeController controller = new AltinnCore.Designer.Controllers.HomeController( moqRepository.Object, moqLogger.Object, moqServiceRepositorySettings.Object, moqGiteaWrappeer.Object, moqHttpContextAccessor.Object, moqSourceControl.Object); // Act ActionResult result = controller.Index(repositorySearch); // Assert ViewResult viewResult = Assert.IsType <ViewResult>(result); AltinnStudioViewModel model = Assert.IsAssignableFrom <AltinnStudioViewModel>(viewResult.Model); Assert.Equal(4, model.Repositories.Count); }
public void StartPage_NotLoggedInUser() { // 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(); 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") }; // Act ActionResult result = controller.StartPage(); // Assert ViewResult viewResult = Assert.IsType <ViewResult>(result); Assert.Equal("StartPage", viewResult.ViewName); }
public void StartPage_LoggedInUser() { // 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"); 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") }; // Act ActionResult result = controller.StartPage(); // Assert RedirectToActionResult redirectResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectResult.ActionName); Assert.Equal("Home", redirectResult.ControllerName); }
public void Login_LogInUser() { // Arrange 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( 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); }
public void Login_LogOutUser() { // Arrange 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( 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("/repos/user/logout", redirectResult.Url); }
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); }
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); }
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); }