public async Task ViewAction_ReturnedCorrectedDetails_ForScrumMasterMentor()
        {
            int    expectedDetailsCount   = 2;
            string expectedMentorViewName = "_MentorDetails";
            string expectedScrumViewName  = "_ScrumMasterDetails";

            var user     = GetUserWithSpecifiedRoles(RoleType.ScrumMaster, RoleType.Mentor);
            var fakeUser = new FakeUser(user.Id);

            fakeUser.AddRole(RoleType.ScrumMaster);
            fakeUser.AddRole(RoleType.Mentor);

            var userDetails = await GetTestedUserDetails(user, fakeUser, expectedDetailsCount);

            var mentorDetails = userDetails[0] as DetailedMentorInfo;
            var smDetails     = userDetails[1] as DetailedScrumMasterInfo;

            var mentor = await _context.Mentors.FindAsync(user.Id);

            var sm = await _context.ScrumMasters.FindAsync(user.Id);

            Assert.IsNotNull(mentorDetails, "It is not a DetailedMentorInfo");

            Assert.AreEqual(expectedMentorViewName,
                            mentorDetails.PartialViewName,
                            "View names are different");

            Assert.AreEqual(mentor.Specialization.Name,
                            mentorDetails.SpecializationName,
                            "Specializations are different");

            Assert.IsNotNull(smDetails, "It is not a DetailedScrumMasterInfo");

            Assert.AreEqual(expectedScrumViewName,
                            smDetails.PartialViewName,
                            "View names are different");

            string expectedProjectName = sm.CurrentGroup?.Project.Name;

            Assert.AreEqual(expectedProjectName,
                            smDetails.ProjectName,
                            "Projects are different");
        }
        public void GetHeaderNavigationAction_Returned_TwoPartialViews_WhenUserIsScrumMentor()
        {
            var    fakeUser = new FakeUser(1);
            string exceptedFirstViewName  = "ScrumMaster/_HeaderNavigation";
            string exceptedSecondViewName = "Mentor/_HeaderNavigation";

            fakeUser.AddRole(RoleType.Mentor);
            fakeUser.AddRole(RoleType.ScrumMaster);
            _controller = CreateController(fakeUser);

            var result = _controller.GetHeaderNavigation() as MultiplePartialViewResult;

            Assert.IsNotNull(result, "It is not a MultiplePartialViewResult");
            Assert.AreEqual(2, result.PartialViews.Count, "There is not two views");

            var firstView  = result.PartialViews[0];
            var secondView = result.PartialViews[1];

            Assert.AreEqual(exceptedFirstViewName, firstView.ViewName, "There is no SM navigation menu");
            Assert.AreEqual(exceptedSecondViewName, secondView.ViewName, "There is no mentor navigation menu");
        }
        public void GetHeaderNavigationAction_Returned_CorrectPartialView_WhenUserIs_OnManagerPages()
        {
            string exceptedViewName = "Manager/_CustomManagerNavigation";
            var    fakeUser         = new FakeUser(1);

            fakeUser.AddRole(RoleType.Manager);
            _controller = CreateController(fakeUser, "ManageRoles", "Manager");

            var result = _controller.GetHeaderNavigation() as PartialViewResult;

            Assert.IsNotNull(result, "It is not a PartialViewResult");
            Assert.AreEqual(exceptedViewName, result.ViewName, "Name does not match");
        }
        public void Project_View_IsCurrentUserOwner_IsTrue_WhenUser_IsOwner()
        {
            var project  = GetTestProject();
            int scrumId  = project.Groups.First(g => g.ScrumMasterId.HasValue).ScrumMasterId.Value;
            var fakeUser = new FakeUser(scrumId);

            fakeUser.AddRole(RoleType.ScrumMaster);
            _controller = CreateProjectController(fakeUser);

            var result    = _controller.View(project.Id) as ViewResult;
            var viewModel = result.Model as ProjectDescriptionViewModel;

            Assert.IsTrue(viewModel.IsCurrentUserOwner, "This user is not project owner");
        }
        public void Project_View_IsCurrentUserOwner_IsFalse_WhenUser_IsNotOwner()
        {
            var project  = GetTestProject();
            var trainee  = _context.Trainees.First();
            var fakeUser = new FakeUser(trainee.Id);

            fakeUser.AddRole(RoleType.Trainee);
            _controller = CreateProjectController(fakeUser);

            var result    = _controller.View(project.Id) as ViewResult;
            var viewModel = result.Model as ProjectDescriptionViewModel;

            Assert.IsFalse(viewModel.IsCurrentUserOwner, "This user is project owner");
        }
        private void TestHeaderForRole(RoleType role, string exceptedViewName)
        {
            var fakeUser = new FakeUser(1);

            fakeUser.AddRole(role);
            _controller = CreateController(fakeUser);

            var result = _controller.GetHeaderNavigation() as MultiplePartialViewResult;

            Assert.IsNotNull(result, "It is not a MultiplePartialViewResult");
            Assert.AreEqual(1, result.PartialViews.Count, "There is not one view");

            var view = result.PartialViews.Single();

            Assert.AreEqual(exceptedViewName, view.ViewName, "Name does not match");
        }
        public void GetHeader_ViewBag_IsUserTrainee_ContainsTrue_WhenUser_IsTrainee()
        {
            var fakeUser = new FakeUser(1);

            fakeUser.AddRole(RoleType.Trainee);
            _controller = CreateController(fakeUser);

            var result = _controller.GetHeader() as PartialViewResult;

            Assert.IsNotNull(result, "It is not a partial view");

            var viewBagIsUserTrainee = result.ViewBag.IsUserTrainee;

            Assert.IsNotNull(viewBagIsUserTrainee, "View bag does not contain IsUserTrainee property");
            Assert.IsTrue(viewBagIsUserTrainee, "ViewBag.IsUserTrainee contains incorrect data");
        }
        public async Task ViewAction_ReturnedCorrectedDetails_ForManager()
        {
            int    expectedDetailsCount = 1;
            string expectedViewName     = "_ManagerDetails";
            var    user     = GetUserWithSpecifiedRoles(RoleType.Manager);
            var    fakeUser = new FakeUser(user.Id);

            fakeUser.AddRole(RoleType.Manager);

            var userDetails = await GetTestedUserDetails(user, fakeUser, expectedDetailsCount);

            var managerDetails = userDetails.Single() as DetailedManagerInfo;

            Assert.IsNotNull(managerDetails, "It is not a DetailedManagerInfo");
            Assert.AreEqual(expectedViewName, managerDetails.PartialViewName, "View names are different");
        }
        public void GetTraineeProfileNavigationMenuAction_Returned_OwnerNavigationMenu_WhenUserIsTrainee_AndProfileOwner()
        {
            int    userId           = 1;
            string exceptedViewName = "Trainee/_ProfileOwnerNavigation";
            var    fakeUser         = new FakeUser(userId);

            fakeUser.AddRole(RoleType.Trainee);
            _controller = CreateController(fakeUser);

            var viewModel = new ProfileMainInfoViewModel
            {
                TraineeId = userId
            };

            var result = _controller.GetTraineeProfileNavigationMenu(viewModel) as PartialViewResult;

            Assert.IsNotNull(result, "It is not a partial view");
            Assert.AreEqual(exceptedViewName, result.ViewName, $"It is not a {exceptedViewName} view");

            var resultViewModel = result.Model as ProfileMainInfoViewModel;

            Assert.IsNotNull(resultViewModel, "View does not contain a model of ProfileMainInfoViewModel type");
        }
        public async Task ViewAction_ReturnedCorrectedDetails_ForHR()
        {
            int    expectedDetailsCount = 1;
            string expectedViewName     = "_HRDetailsView";
            var    user     = GetUserWithSpecifiedRoles(RoleType.HR);
            var    fakeUser = new FakeUser(user.Id);

            fakeUser.AddRole(RoleType.HR);

            var userDetails = await GetTestedUserDetails(user, fakeUser, expectedDetailsCount);

            var hrDetails = userDetails.Single() as DetailedHRInfo;
            var hr        = _context.Users.Find(user.Id);

            Assert.IsNotNull(hrDetails, "It is not a DetailedHRInfo");
            Assert.AreEqual(expectedViewName, hrDetails.PartialViewName, "View names are different");

            string expectedCompany = hr.Contacts?.Company;

            Assert.AreEqual(expectedCompany,
                            hrDetails.Company,
                            "Companies are different");
        }