public async Task UpdateAdviceService() { var options = TestHelper.GetDbContext("UpdateAdviceService"); //Given var lkp1 = new AdviceServiceEntity { Id = Guid.NewGuid(), Name = "1", DisplayOrder = 1 }; using (var context = new DataContext(options)) { context.AdviceService.Add(lkp1); context.SaveChanges(); } var model = new AdviceService() { Id = lkp1.Id, Name = "1 Updated", DisplayOrder = 2 }; using (var context = new DataContext(options)) { var service = new DirectoryLookupService(context); //When var result = await service.UpdateAdviceService(model); //Then Assert.True(result.Success); var actual = await context.AdviceService.FindAsync(model.Id); Assert.Equal(model.Name, actual.Name); Assert.Equal(model.DisplayOrder, actual.DisplayOrder); } }
public async Task All() { var company = new Company() { Id = Guid.NewGuid(), Name = "Name2" }; var userType = new UserType() { Id = Guid.NewGuid(), Name = "Name2" }; var adviceScope = new AdviceScope() { Id = Guid.NewGuid(), Name = "Name2" }; var adviceService = new AdviceService() { Id = Guid.NewGuid(), Name = "Name2" }; var licenseCategory = new LicenseCategory() { Id = Guid.NewGuid(), Name = "Name2" }; var companies = new List <Company>() { company }; var userTypes = new List <UserType>() { userType }; var licenseCategories = new List <LicenseCategory>() { licenseCategory }; var adviceServices = new List <AdviceService>() { adviceService }; var adviceScopes = new List <AdviceScope>() { adviceScope }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetCompanies()).ReturnsAsync(companies); service.Setup(c => c.GetUserTypes()).ReturnsAsync(userTypes); service.Setup(c => c.GetLicenseCategories()).ReturnsAsync(licenseCategories); service.Setup(c => c.GetAdviceServices()).ReturnsAsync(adviceServices); service.Setup(c => c.GetAdviceScopes()).ReturnsAsync(adviceScopes); var controller = new LookupsController(service.Object); var result = await controller.All(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <api.Controllers.Directory.Lookups.Dto.Lookups>(okResult.Value); var all = new api.Controllers.Directory.Lookups.Dto.Lookups() { Companies = companies, UserTypes = userTypes, LicenseCategories = licenseCategories, AdviceScopes = adviceScopes, AdviceServices = adviceServices, }; Assert.NotStrictEqual(all, returnValue); }
public ActionResult AboutTrainer(string employeeTC, string urlName, int?pageIndex) { if (employeeTC.IsEmpty()) { return(NotFound()); } if (!pageIndex.HasValue && urlName.In( SimplePages.Urls.TrainerOrgResponses, SimplePages.Urls.TrainerResponses, SimplePages.Urls.TrainerTests, SimplePages.Urls.TrainerAdvices, SimplePages.Urls.TrainerWorks, SimplePages.Urls.TrainerVideos)) { return(RedirectToAction(() => AboutTrainer(employeeTC, urlName, 1))); } var index = pageIndex.GetValueOrDefault() - 1; var model = new AboutTrainerVM(); model.UrlName = urlName; model.Page = GetAboutTrainer(); employeeTC = employeeTC.ToUpper(); model.Employee = EmployeeVMService.GetEmployee(employeeTC); if (model.Employee == null || !model.Employee.Employee.IsTrainer) { return(Redirect(SimplePages.FullUrls.Trainers)); } var orgResponses = OrgResponseService.GetAll().IsActive() .Where(r => ("," + r.Employee_TC + ",").Contains("," + employeeTC + ",")) .OrderByDescending(o => o.UpdateDate); var responses = ResponseService.GetAllForEmployee(employeeTC) .OrderByDescending(x => x.Course.IsActive) .ThenByDescending(o => o.Rating).ThenByDescending(x => x.UpdateDate); var advices = AdviceService.GetAll().IsActive() .Where(r => r.Employee_TC == employeeTC) .OrderByDescending(o => o.UpdateDate); var tests = TestService.GetAll().Where(x => x.Status == TestStatus.Active) .Where(r => r.Author_TC == employeeTC) .OrderByDescending(o => o.Id); var videos = VideoService.GetAll().IsActive() .Where(r => r.Employee_TC == employeeTC) .OrderByDescending(o => o.VideoID); var userWorks = UserWorkService.GetAll().IsActive() .Where(r => r.Trainer_TC == employeeTC) .OrderByDescending(o => o.UserWorkID); model.HasOrgResponses = orgResponses.Any(); model.HasResponses = responses.Any(); model.HasAdvices = advices.Any(); model.HasTests = tests.Any(); model.HasVideos = videos.Any(); model.HasPortfolio = Images.GetGallaryFiles(model.Employee.Employee, "Portfolio").Any(); model.HasWorks = userWorks.Any(); if (model.IsTrainerResponses) { model.Responses = responses.ToPagedList(index, 20); } if (model.IsTrainerOrgResponses) { model.OrgResponses = orgResponses.ToPagedList(index, 10);; } if (model.IsAdvices) { model.Advices = advices.ToPagedList(index, 10); } if (model.IsTests) { model.Tests = tests.ToPagedList(index, 10); } if (model.IsVideos) { model.Videos = videos.ToList(); } if (model.IsWorks) { model.UserWorks = userWorks.ToPagedList(index, 10); } if (model.IsAboutTrainer) { model.Certifications = EmployeeCertificationService.GetAll( x => x.EmployeeFK_TC == employeeTC && x.Certification.IsActive) .OrderBy(x => x.SortOrder) .Select(x => x.Certification).ToList(); } return(View(model)); }