public async Task CreateAsyncShouldCreateCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ProfessionsCreateDb").Options; var dbContext = new ApplicationDbContext(options); var repository = new EfDeletableEntityRepository <Profession>(dbContext); var service = new ProfessionService(repository); await service.CreateAsync(new ProfessionServiceInputModel { Name = "Profession", }); var expectedProfession = new Profession { Id = 1, Name = "Profession" }; var actualProfession = dbContext.Professions.FirstOrDefault(x => x.Name == "Profession"); Assert.NotNull(actualProfession); Assert.Equal(expectedProfession.Id, actualProfession.Id); Assert.Equal(expectedProfession.Name, actualProfession.Name); }
public async Task GetByIdReturnEntityWhenExistElementWIthGivenId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ProfessionGetByIdDb").Options; var dbContext = new ApplicationDbContext(options); await dbContext.Professions .AddAsync(new Profession { Id = 1, }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Profession>(dbContext); var service = new ProfessionService(repository); this.InitializeMapper(); var result = service.GetById <ProfessionViewModel>(1); Assert.Equal(1, result.Id); Assert.IsType <ProfessionViewModel>(result); }
public async Task GetProfession_ReturnsNotFound_ForInvalidId() { // Arrange string professionId = "ANIMAL_TRAINER"; Mock <IDataRepo> mockRepo = new Mock <IDataRepo>(); // Return null. mockRepo.Setup(repo => repo.GetProfessionAsync(professionId)).ReturnsAsync(() => null); ProfessionService mockService = new ProfessionService(mockRepo.Object); ProfessionController controller = new ProfessionController(mockService); // Act GetProfessionRequest request = new GetProfessionRequest() { ProfessionId = professionId }; var response = await controller.GetProfession(request); var result = response.Result; // Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); var error = Assert.IsType <ErrorResponse>(notFoundObjectResult.Value); Assert.Equal(404, notFoundObjectResult.StatusCode); Assert.Null(error.Description); Assert.Equal(ErrorCode.ProfessionNotFound.ToString(), error.ErrorCode); }
public virtual MainCoursesVM GetMainCourses() { var allRootSections = SectionVMService.GetSectionWithEntityTree(); var professions = ProfessionService.GetAll() .OrderByName().IsActive().ToDictionary(x => x.Profession_ID, x => x); var professionSections = SiteObjectRelationService.GetRelation(typeof(Profession), Enumerable.Empty <object>(), typeof(Section)).ToList(); var sectionIds = new HashSet <int>(professionSections.Select(x => x.RelationObject_ID).Cast <int>()); var sectionForProfession = allRootSections.Select(x => x.Entity.As <Section>()).Where(x => sectionIds.Contains(x.Section_ID)); return (new MainCoursesVM { Products = ProductService.GetAll() .OrderByName().IsActive().ToList(), SiteTerms = SiteTermService.GetAll() .OrderByName().IsActive().ToList(), Professions = sectionForProfession.Select(x => EntityWithList.New(x, professionSections.Where(sor => sor.RelationObject_ID.Equals(x.Section_ID)) .Select(y => professions.GetValueOrDefault((int)y.Object_ID)) .Cast <IEntityCommonInfo>().Where(p => p != null))).ToList(), RootSections = allRootSections, Vendors = VendorService.GetAll() .OrderByName().IsActive().ToList(), }); }
/// <summary> /// 学生的课程 /// </summary> /// <param name="StuNo">学生编号</param> /// <returns></returns> public List <Course> GetStudentCourse(string StuNo) { List <Course> courseList = new List <Course>(); try { //得到该学生的信息 Z_Student student = StudentService.GetEntity(u => u.F_StuNo == StuNo).FirstOrDefault(); //得到该学生所在的班级 Z_Class cClass = ClassService.GetEntity(c => c.F_Id == student.Z_C_F_Id).FirstOrDefault(); //查询到该学生所在的年级 Z_Grade grade = GradeService.GetEntity(g => g.F_ID == cClass.Z_G_F_ID).FirstOrDefault(); //得到该学生所在的专业 Z_Profession profession = ProfessionService.GetEntity(u => u.F_ID == cClass.Z_P_F_ID).FirstOrDefault(); //得到当前是第几周 SchollTime schollTime = GetSchollTime(); //查询到该专业的所有课程 IQueryable <Z_Course> courses = GetEntity(u => u.F_Major == profession.F_ProName).Where(u => u.F_Grade == grade.F_GradeName).Where(u => u.F_Class.Contains(cClass.F_ClassName)).Where(u => u.F_SchoolYear.Contains(schollTime.SearchYear)).Where(u => u.F_Term == schollTime.Term.ToString()); var cl = courses.OrderBy(u => u.F_Week).ThenBy(u => u.F_CourseTimeType).ToList(); cl.ForEach(u => u.F_CourseTimeType = u.F_CourseTimeType.Substring(0, u.F_CourseTimeType.Length - 1)); courseList = AutoMapperConfig.MapList(cl, courseList); ComputedTimeLength(courseList); } catch (Exception e) { throw e; } return(courseList); }
public async Task EditAsyncShouldEditCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ProfessionsEditDb").Options; var dbContext = new ApplicationDbContext(options); await dbContext.Professions.AddAsync( new Profession { Id = 1, Name = "Name", }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Profession>(dbContext); var service = new ProfessionService(repository); var editModel = new ProfessionServiceInputModel { Name = "NewName", }; await service.EditAsync(1, editModel); var result = dbContext.Professions.FirstOrDefault(x => x.Id == 1); Assert.NotNull(result); Assert.Equal("NewName", result.Name); }
private static object InstanceProfessionService() { IRepository repository = RepositoryFactory.GetRepositoryInstance <ProfessionRepository>(); IProfessionService service = new ProfessionService(repository); return(service); }
public virtual ActionResult List() { var result = new List <object>(); result.AddRange(SiteTermService.GetAll().IsActive().Cast <object>()); result.AddRange(ProductService.GetAll().IsActive().Cast <object>()); result.AddRange(ProfessionService.GetAll().IsActive().Cast <object>()); result.AddRange(VendorService.GetAll().IsActive().Cast <object>()); return(View(result.OrderBy(o => o.GetValue("Name")))); }
/// <summary> /// 根据课程获取该课程下的所有学生 /// </summary> /// <returns></returns> public List <Z_Student> GetStudentsByCourseId(Course course) { // 获取学年 var grade = GradeService.GetEntity(gra => gra.F_GradeName == course.Grade).FirstOrDefault(); // 获取该课程所属专业 var profession = ProfessionService.GetEntity(u => u.F_ProName == course.Major).FirstOrDefault(); // 获取该课程下的班级 var classes = ClassService.GetEntity(u => u.Z_Grade.F_ID == grade.F_ID && u.Z_Profession.F_ID == profession.F_ID && course.Classes.Contains(u.F_ClassName)); // 获取班级下的所有学生 var stus = StudentService.GetEntity(stu => classes.Any(c => c.F_Id == stu.Z_Class.F_Id)).AsQueryable().ToList(); return(stus); }
public async Task GetProfession_ReturnsOk_ForValidId() { // Arrange string professionId = "ANIMAL_TRAINER"; Profession profession = new Profession() { Id = professionId, Label = "Label", Description = "Description", Role = "Role", Notes = "Notes", Source = "Source", IsAdvanced = false, MainProfile = null, SecondaryProfile = null, AdvanceFrom = new List <string>() { "ABBOT" }, AdvanceTo = new List <string>() { "ADMIRAL" }, Skills = null, Trappings = null, Talents = null, NumberOfAdvances = 2, NumberOfSkills = 0, NumberOfTalents = 0 }; Mock <IDataRepo> mockRepo = new Mock <IDataRepo>(); mockRepo.Setup(repo => repo.GetProfessionAsync(professionId)).ReturnsAsync(profession); ProfessionService mockService = new ProfessionService(mockRepo.Object); ProfessionController controller = new ProfessionController(mockService); // Act GetProfessionRequest request = new GetProfessionRequest() { ProfessionId = professionId }; var response = await controller.GetProfession(request); var result = response.Result; // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, okObjectResult.StatusCode); Assert.Equal(profession, okObjectResult.Value); }
public async Task DeleteShouldDeleteCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ProfessionsDeleteDb").Options; var dbContext = new ApplicationDbContext(options); await dbContext.Professions.AddAsync(new Profession { Id = 1 }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Profession>(dbContext); var service = new ProfessionService(repository); await service.DeleteAsync(1); var profession = dbContext.Professions.FirstOrDefault(x => x.Id == 1); Assert.Null(profession); }
public virtual MainPageVM Get() { var sections = SectionService.GetAll().IsActive().Where(s => s.ForMainPage) .ByWebOrder().ToList(); var professions = ProfessionService.GetAll().IsActive() .Where(p => p.ForMainPage).ToList() .OrderBy(x => StringUtils.IsBasicLetter(x.Name.First())).ThenBy(x => x.Name).ToList(); var vendors = VendorService.GetAll().IsActive() .Where(p => p.ForMainPage).ByWebOrder().ToList(); var products = ProductService.GetAll().IsActive() .Where(p => p.ForMainPage).ToList().OrderBy(x => x.Name).ToList(); var siteterms = SiteTermService.GetAll().IsActive() .Where(p => p.ForMainPage).ToList().OrderBy(x => x.Name).ToList(); VideoService.LoadWith(x => x.VideoCategory); var videos = VideoService.GetAll(x => x.CategoryId == VideoCategories.CoursePresentation) .OrderByDescending(x => x.UpdateDate).Take(3).ToList(); return (new MainPageVM { Professions = professions, Vendors = vendors, Sections = sections, Products = products, Banners = BannerService.GetBanner(CommonConst.SiteRoot + "/") .ShufflePriority(x => x.Priority), News = NewsService.GetAllForMain().ToList(), SiteTerms = siteterms, Videos = videos, Documents = CertTypeService .GetAll(c => CertTypes.ForMain.Contains(c.UrlName)).ToList(), About = SimplePageService.GetAll().BySysName(SimplePages.MainPage) }); }
public async Task GetAllReturnAllEntities() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "ProfessionsGetAllDb").Options; var dbContext = new ApplicationDbContext(options); dbContext.Professions.AddRange( new Profession(), new Profession(), new Profession()); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Profession>(dbContext); var service = new ProfessionService(repository); this.InitializeMapper(); var result = service.GetAll <ProfessionViewModel>(); Assert.Equal(3, result.Count()); }
public async Task GetProfessions_ShouldReturnProfessions() { // Arrange List <string> expectedResult = new List <string>() { "ABBOT", "GAMBLER", "PIT_FIGHTER", "SERGEANT" }; Mock <IDataRepo> mockRepo = new Mock <IDataRepo>(); mockRepo.Setup(repo => repo.GetProfessionsAsync()).ReturnsAsync(expectedResult); ProfessionService mockService = new ProfessionService(mockRepo.Object); ProfessionController controller = new ProfessionController(mockService); // Act var response = await controller.GetProfessions(); var result = response.Result; // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, okObjectResult.StatusCode); Assert.Equal(expectedResult, okObjectResult.Value); }
public ProfessionController() : base() { ProfessionService = new ProfessionService(); }
public virtual ActionResult Details(string urlName) { var model = ProfessionService.GetAll().ByUrlName(urlName); return(MView(ViewNames.CommonEntityPage, model)); }
public static void Add(Profession p) { ProfessionService.Add(p); }
public static void Delete(int id) { ProfessionService.Delete(id); }
public static void Edit(Profession p) { ProfessionService.Edit(p); }
public static List <Profession> GetAll() { return(ProfessionService.GetAll()); }