private ExpandoObject ExpectedShapedByRelatedDataLevel0(SchoolOutDto school) { var shapedSchool = new ExpandoObject(); var dictSchool = (IDictionary <string, object>)shapedSchool; dictSchool[nameof(SchoolOutDto.Id).Camelize()] = school.Id; dictSchool[nameof(SchoolOutDto.Name).Camelize()] = school.Name; dictSchool[nameof(SchoolOutDto.YearOfEstablishment).Camelize()] = school.YearOfEstablishment; return(shapedSchool); }
private ExpandoObject ExpectedShapedByRelatedDataLevel1(SchoolOutDto school) { var shapedSchool = new ExpandoObject(); var dictSchool = (IDictionary <string, object>)shapedSchool; dictSchool[nameof(SchoolOutDto.Id).Camelize()] = school.Id; dictSchool[nameof(SchoolOutDto.Name).Camelize()] = school.Name; dictSchool[nameof(SchoolOutDto.YearOfEstablishment).Camelize()] = school.YearOfEstablishment; dictSchool[nameof(SchoolOutDto.Lessons).Camelize()] = CreateDetail(school.Lessons, nameof(LessonOutDto.Id), nameof(LessonOutDto.Name), nameof(LessonOutDto.WeekHours), nameof(LessonOutDto.Notes)); dictSchool[nameof(SchoolOutDto.Students).Camelize()] = CreateDetail(school.Students, nameof(StudentOutDto.Id), nameof(StudentOutDto.FirstName), nameof(StudentOutDto.LastName), nameof(StudentOutDto.FullName), nameof(StudentOutDto.DateOfBirth), nameof(StudentOutDto.Notes)); return(shapedSchool); }
private ExpandoObject ExpectedShapedAll(SchoolOutDto school) { var obj = new ExpandoObject(); var dictSchool = (IDictionary <string, object>)obj; dictSchool[nameof(SchoolOutDto.Id).Camelize()] = school.Id; dictSchool[nameof(SchoolOutDto.Name).Camelize()] = school.Name; dictSchool[nameof(SchoolOutDto.YearOfEstablishment).Camelize()] = school.YearOfEstablishment; var shapedLessons = new List <ExpandoObject>(); foreach (var lesson in school.Lessons) { var shapedLesson = CreateObject(lesson, nameof(LessonOutDto.Id), nameof(LessonOutDto.Name), nameof(LessonOutDto.WeekHours), nameof(LessonOutDto.Notes)); var dictLesson = (IDictionary <string, object>)shapedLesson; dictLesson[nameof(LessonOutDto.Books).Camelize()] = CreateDetail(lesson.Books, nameof(BookOutDto.Id), nameof(BookOutDto.Name)); shapedLessons.Add(shapedLesson); } dictSchool[nameof(SchoolOutDto.Lessons).Camelize()] = shapedLessons; var shapedStudents = new List <ExpandoObject>(); foreach (var student in school.Students) { var shapedStudent = CreateObject(student, nameof(StudentOutDto.Id), nameof(StudentOutDto.FirstName), nameof(StudentOutDto.LastName), nameof(StudentOutDto.FullName), nameof(StudentOutDto.DateOfBirth), nameof(StudentOutDto.Notes)); var dictStudent = (IDictionary <string, object>)shapedStudent; var shapedContactInfo = CreateObject(student.ContactInfo, nameof(ContactInfoOutDto.Id), nameof(ContactInfoOutDto.Email), nameof(ContactInfoOutDto.Address)); if (student.ContactInfo != null) { var dictContactInfo = (IDictionary <string, object>)shapedContactInfo; foreach (var phone in student.ContactInfo.Phones) { dictContactInfo[nameof(ContactInfoOutDto.Phones).Camelize()] = CreateDetail(student.ContactInfo.Phones, nameof(PhoneOutDto.Id), nameof(PhoneOutDto.Number)); } } dictStudent[nameof(StudentOutDto.ContactInfo).Camelize()] = shapedContactInfo; shapedStudents.Add(shapedStudent); } dictSchool[nameof(SchoolOutDto.Students).Camelize()] = shapedStudents; return(obj); }
public ShaperTests() { var services = new ServiceCollection(); services.AddTransient <IShapePropertyWalker, ShapePropertyWalker>(); services.AddTransient <IShapePropertyWalkerVisitor, ShapePropertyWalkerVisitor>(); services.AddSingleton <IPropertyProvider, PropertyProvider>(); services.AddSingleton <IFieldNameResolver, FieldNameResolver>(); services.AddSingleton <IOptions <MvcJsonOptions>, MvcJsonOptionsTests>(); var walker = new ShapePropertyWalker(new PropertyProvider()); var visitor = new ShapePropertyWalkerVisitor(services.BuildServiceProvider(), new FieldNameResolver(new MvcJsonOptionsTests())); _shaper = new Shaper(walker, visitor); var mapper = new Mapper(new MapperConfiguration(config => config.AddProfile(new AppProfile()))); _school = mapper.DefaultContext.Mapper.Map <SchoolOutDto>(AppDbContextTests.GetContextWithData().Schools.FirstOrDefault()); }