Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseAppService"/> class.
 /// </summary>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public BaseAppService(IObjectMapperAdapter objectMapper, ICacheAdapter cacheService, IExceptionManagerAdapter exceptionManager, ILoggingServiceAdapter loggingService)
 {
     this.ObjectMapper     = objectMapper;
     this.CacheService     = cacheService;
     this.ExceptionManager = exceptionManager;
     this.LoggingService   = loggingService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CourseModuleAppService"/> class.
 /// </summary>
 /// <param name="courseManager">The course manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public CourseModuleAppService(
     ICourseDomainService courseManager,
     IModuleDomainService moduleManager,
     IModuleQuizDomainService moduleQuizManager,
     IDepartmentDomainService departmentManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService,
     ICourseRegistrationDomainService courseRegistrationManager,
     IQuizDomainService quizManager,
     IAssignmentDomainService assignmentManager,
     ISubmissionDomainService submissionManager,
     IStudentDomainService studentManager)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.CourseManager             = courseManager;
     this.ModuleManager             = moduleManager;
     this.DepartmentManager         = departmentManager;
     this.CourseRegistrationManager = courseRegistrationManager;
     this.QuizManager       = quizManager;
     this.AssignmentManager = assignmentManager;
     this.SubmissionManager = submissionManager;
     this.StudentManager    = studentManager;
 }
        private static void AssertListMappingWorksBasedOnTestName(IObjectMapperAdapter mapper, [CallerMemberName] string name = null)
        {
            var parts      = name.Split("To");
            var sourceType = GetCollectionType(parts[0]);
            var targetType = GetCollectionType(parts[1]);

            GenericHelper.RewriteAndInvoke(() => AssertListMappingWorksFor <IX1, IX2>(mapper), sourceType, targetType);
        }
        public void PropertyToSetMethod(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap<ClassWithValue, ClassWithSetValue>();
            var source = new ClassWithValue { Value = "ABC" };
            var result = adapter.Map<ClassWithSetValue>(source);

            Assert.Equal(source.Value, result.GetValue());
        }
        public void NameBasedUnflattening(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap<ClassWithNestedValue, ClassWithNested<ClassWithValue>>();
            var source = new ClassWithNestedValue { NestedValue = "ABC" };
            var result = adapter.Map<ClassWithNested<ClassWithValue>>(source);

            Assert.Equal(source.NestedValue, result.Nested.Value);
        }
        public void MethodToProperty(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap<ClassWithValueAsMethod, ClassWithValue>();
            var source = new ClassWithValueAsMethod("ABC");
            var result = adapter.Map<ClassWithValue>(source);

            Assert.Equal(source.Value(), result.Value);
        }
Exemple #7
0
        public void GetMethodToProperty(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap <ClassWithGetValueMethod, ClassWithValue>();
            var source = new ClassWithGetValueMethod("ABC");
            var result = adapter.Map <ClassWithValue>(source);

            Assert.Equal(source.GetValue(), result.Value);
        }
Exemple #8
0
 public void HashSetToISet(IObjectMapperAdapter mapper)
 {
     AssertListMappingWorksFor(mapper, new HashSet <int> {
         5
     }, ((ISet <int>) new HashSet <int> {
         5
     }));
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecurityAppService"/> class.
 /// </summary>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public SecurityAppService(
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
 }
        public void Simple(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap<Wrapper<string>, ImmutableWrapper<string>>();

            var source = new Wrapper<string> { Value = "X" };
            var result = mapper.Map<ImmutableWrapper<string>>(source);

            Assert.Equal("X", result.Value);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CourseModuleAppService"/> class.
 /// </summary>
 /// <param name="courseManager">The course manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public BaseQuestionTopicAppService(
     IBaseQuestionTopicDomainService baseQuestionTopicManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.BaseQuestionTopicManager = baseQuestionTopicManager;
 }
        public void DictionaryEntryToProperty(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap<Dictionary<string, object>, Wrapper<string>>();

            var source = new Dictionary<string, object> { { "Value", "ABC" } };
            var result = mapper.Map<Wrapper<string>>(source);

            Assert.NotNull(result);
            Assert.Equal("ABC", result.Value);
        }
Exemple #13
0
        public void PropertyToSetMethod(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap <ClassWithValue, ClassWithSetValue>();
            var source = new ClassWithValue {
                Value = "ABC"
            };
            var result = adapter.Map <ClassWithSetValue>(source);

            Assert.Equal(source.Value, result.GetValue());
        }
        public void PropertyToDictionaryEntry(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap<Wrapper<string>, Dictionary<string, object>>();

            var source = new Wrapper<string> { Value = "ABC" };
            var result = mapper.Map<Dictionary<string, object>>(source);

            Assert.NotNull(result);
            Assert.Contains(new KeyValuePair<string, object>("Value", "ABC"), result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduleModuleAppService"/> class.
 /// </summary>
 /// <param name="ScheduleManager">The Schedule manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public ScheduleAppService(
     IScheduleDomainService ScheduleManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.ScheduleManager = ScheduleManager;
 }
        public void NameBasedUnflattening(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap <ClassWithNestedName, ClassWithNested <ClassWithName> >();
            var source = new ClassWithNestedName {
                NestedName = "ABC"
            };
            var result = adapter.Map <ClassWithNested <ClassWithName> >(source);

            Assert.Equal(source.NestedName, result.Nested.Name);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StaffAppService"/> class.
 /// </summary>
 /// <param name="staffManager">The staff manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 public StaffAppService(
     IStaffDomainService staffManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.StaffManager = staffManager;
 }
Exemple #18
0
        public void NameBasedFlattening(IObjectMapperAdapter adapter)
        {
            adapter.CreateMap <ClassWithNested <ClassWithValue>, ClassWithNestedValue>();
            var source = new ClassWithNested <ClassWithValue> {
                Nested = { Value = "ABC" }
            };
            var result = adapter.Map <ClassWithNestedValue>(source);

            Assert.Equal(source.Nested.Value, result.NestedValue);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserAppService"/> class.
 /// </summary>
 /// <param name="userManager">The user manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public UserAppService(
     IUserDomainService userManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.UserManager = userManager;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitModuleAppService"/> class.
        /// </summary>
        /// <param name="unitManager">The unit manager.</param>
        /// <param name="objectMapper">The object mapper.</param>
        /// <param name="cacheService">The cache service.</param>
        /// <param name="exceptionManager">The exception manager.</param>
        /// <param name="loggingService">The logging service.</param>
        public VideoAppService(

            IObjectMapperAdapter objectMapper,
            ICacheAdapter cacheService,
            IExceptionManagerAdapter exceptionManager,
            ILoggingServiceAdapter loggingService,
            IVideoDomainService iVideoDomainService)
            : base(objectMapper, cacheService, exceptionManager, loggingService)
        {
            _iVideoDomainService = iVideoDomainService;
        }
        private static void AssertEnumMappingWorksFor <TSource, TTarget>(IObjectMapperAdapter mapper, TSource sourceValue, TTarget expectedValue)
        {
            mapper.CreateMap <Wrapper <TSource>, Wrapper <TTarget> >();

            var source = new Wrapper <TSource> {
                Value = sourceValue
            };
            var result = mapper.Map <Wrapper <TTarget> >(source);

            Assert.Equal(expectedValue, result.Value);
        }
        /// <summary>
        /// Creates new object of type U from mapper adapter object.
        /// </summary>
        /// <typeparam name="T">Type of target object</typeparam>
        /// <typeparam name="U">Type of source object</typeparam>
        /// <param name="adapter">The adapter.</param>
        /// <param name="source">The source.</param>
        /// <returns>New object with properties mapped from mapper adapter.</returns>
        public static T CreateMappedObject <T, U>(this IObjectMapperAdapter <T, U> adapter, U source) where T : new()
        {
            if (adapter == null)
            {
                return(default(T));
            }

            T newObject = new T();

            adapter.MapObject(source, newObject);
            return(newObject);
        }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileAppService"/> class.
 /// </summary>
 /// <param name="fileManager">The file manager.</param>
 /// <param name="baseFileManager">The base file manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public FileAppService(
     IFileDomainService fileManager,
     IBaseFileDomainService baseFileManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.FileManager     = fileManager;
     this.BaseFileManager = baseFileManager;
 }
        public void ExpandoObjectToClass(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap<dynamic, Wrapper<string>>();

            dynamic source = new ExpandoObject();
            source.Value = "ABC";

            var result = mapper.Map<Wrapper<string>>((object)source);

            Assert.NotNull(result);
            Assert.Equal("ABC", result.Value);
        }
        /// <summary>
        /// Creates new object of type T from mapper adapter object.
        /// </summary>
        /// <typeparam name="T">Type of source object</typeparam>
        /// <typeparam name="U">Type of target object</typeparam>
        /// <param name="adapter">The adapter.</param>
        /// <param name="source">The source.</param>
        /// <returns>New object with properties mapped from mapper adapter.</returns>
        public static U CreateMappedObject <T, U>(this IObjectMapperAdapter <T, U> adapter, T source) where U : new()
        {
            if (adapter == null)
            {
                return(default(U));
            }

            U newObject = new U();

            adapter.MapObject(source, newObject);
            return(newObject);
        }
Exemple #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageAppService"/> class.
 /// </summary>
 /// <param name="MessageManager">The message manager.</param>
 /// <param name="studentViewedMessageManager">The student viewed message manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="exceptionManager">The exception manager.</param>
 /// <param name="loggingService">The logging service.</param>
 public MessageAppService(
     IMessageDomainService messageManager,
     IStudentViewedMessageDomainService studentViewedMessageManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.MessageManager = messageManager;
     this.StudentViewedMessageManager = studentViewedMessageManager;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DiscussionAppService"/> class.
 /// </summary>
 /// <param name="objectMapperAdapter">The object mapper adapter.</param>
 /// <param name="cacheAdapter">The cache adapter.</param>
 /// <param name="exceptionManagerAdapter">The exception manager adapter.</param>
 /// <param name="loggingServiceAdapter">The logging service adapter.</param>
 /// <param name="discussionDomainService">The discussion domain service.</param>
 /// <param name="topicDomainService">The topic domain service.</param>
 /// <param name="topicPostDomainService">The topic post domain service.</param>
 public DiscussionAppService(IObjectMapperAdapter objectMapperAdapter, ICacheAdapter cacheAdapter,
                             IExceptionManagerAdapter exceptionManagerAdapter, ILoggingServiceAdapter loggingServiceAdapter,
                             IDiscussionDomainService discussionDomainService, ITopicDomainService topicDomainService,
                             ITopicPostDomainService topicPostDomainService,
                             ICourseDomainService courseDomainService)
     : base(objectMapperAdapter, cacheAdapter, exceptionManagerAdapter, loggingServiceAdapter)
 {
     DiscussionManager = discussionDomainService;
     TopicManager      = topicDomainService;
     PostManager       = topicPostDomainService;
     CourseManager     = courseDomainService;
 }
        public void DictionaryEntryToProperty(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap <Dictionary <string, object>, Wrapper <string> >();

            var source = new Dictionary <string, object> {
                { "Value", "ABC" }
            };
            var result = mapper.Map <Wrapper <string> >(source);

            Assert.NotNull(result);
            Assert.Equal("ABC", result.Value);
        }
        public void PropertyToDictionaryEntry(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap <Wrapper <string>, Dictionary <string, object> >();

            var source = new Wrapper <string> {
                Value = "ABC"
            };
            var result = mapper.Map <Dictionary <string, object> >(source);

            Assert.NotNull(result);
            Assert.Contains(new KeyValuePair <string, object>("Value", "ABC"), result);
        }
        public void ExpandoObjectToClass(IObjectMapperAdapter mapper)
        {
            mapper.CreateMap <dynamic, Wrapper <string> >();

            dynamic source = new ExpandoObject();

            source.Value = "ABC";

            var result = mapper.Map <Wrapper <string> >((object)source);

            Assert.NotNull(result);
            Assert.Equal("ABC", result.Value);
        }
Exemple #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QuizAppService"/> class.
 /// </summary>
 /// <param name="staffManager">The staff manager.</param>
 /// <param name="objectMapper">The object mapper.</param>
 public AnswerAppService(
     IAnswerDomainService answerManager,
     IAnswerQuestionChoiceDomainService answerQuestionChoiceManager,
     IQuestionChoiceDomainService questionchoiceManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.AnswerManager = answerManager;
     this.AnswerQuestionChoiceManager = answerQuestionChoiceManager;
     this.QuestionChoiceManager       = questionchoiceManager;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QuestionAppService"/> class.
 /// </summary>
 /// <param name="questionManager">The staff manager.</param>
 ///  <param name="moduleManager">The module manager.</param>
 /// <param name="questionChoicesManager">The questionchoices mapper.</param>
 ///  <param name="objectMapper">The object mapper.</param>
 ///   <param name="cacheService">The cache servide.</param>
 ///   <param name="exceptionManager">The exception manager.</param>
 ///   <param name="loggingService">The loggin manager.</param>
 public QuestionAppService(
     IQuestionDomainService questionManager,
     IModuleDomainService moduleManager,
     IQuestionChoiceDomainService questionChoicesManager,
     IObjectMapperAdapter objectMapper,
     ICacheAdapter cacheService,
     IExceptionManagerAdapter exceptionManager,
     ILoggingServiceAdapter loggingService)
     : base(objectMapper, cacheService, exceptionManager, loggingService)
 {
     this.QuestionManager        = questionManager;
     this.ModuleManager          = moduleManager;
     this.QuestionChoicesManager = questionChoicesManager;
 }
        private static void AssertNullableMappingWorksFor <TSource, TTarget>(IObjectMapperAdapter mapper, TSource sourceValue, TTarget expectedValue, TTarget targetValue = default(TTarget))
        {
            mapper.CreateMap <Wrapper <TSource>, Wrapper <TTarget> >();

            var source = new Wrapper <TSource> {
                Value = sourceValue
            };

            WrapperStatic <TTarget> .NextValueAfterConstructor = targetValue;

            var result = mapper.Map <Wrapper <TTarget> >(source);

            Assert.Equal(expectedValue, result.Value);
        }
Exemple #34
0
 /// <summary>
 /// Creates from view model model.
 /// </summary>
 /// <param name="asset">The user.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <returns></returns>
 public static User CreateFromViewModelModel(UserViewModel user, IObjectMapperAdapter objectMapper)
 {
     if (user is StudentViewModel)
     {
         return(objectMapper.Map <StudentViewModel, Student>((StudentViewModel)user));
     }
     else if (user is StaffViewModel)
     {
         return(objectMapper.Map <StaffViewModel, Staff>((StaffViewModel)user));
     }
     else
     {
         return(objectMapper.Map <UserViewModel, User>(user));
     }
 }
 /// <summary>
 /// Creates the user entity.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <returns></returns>
 public static Model.Entities.User CreateFromDataModel(User user, IObjectMapperAdapter objectMapper)
 {
     if (user is Student)
     {
         return(objectMapper.Map <Student, Model.Entities.Student>((Student)user));
     }
     else if (user is Staff)
     {
         return(objectMapper.Map <Staff, Model.Entities.Staff>((Staff)user));
     }
     else
     {
         return(objectMapper.Map <User, Model.Entities.User>(user));
     }
 }
Exemple #36
0
        /// <summary>
        /// Creates the staff courses.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="objectMapper">The object mapper.</param>
        /// <returns></returns>
        private static List <CourseViewModel> CreateStaffCourses(Staff user, IObjectMapperAdapter objectMapper)
        {
            List <CourseViewModel> courses = new List <CourseViewModel>();

            if (user != null && user.StaffCourses != null)
            {
                foreach (var staffCourses in user.StaffCourses)
                {
                    if (staffCourses.Course != null)
                    {
                        courses.Add(objectMapper.Map <Course, CourseViewModel>(staffCourses.Course));
                    }
                }
            }
            return(courses);
        }
 public void NonStaticApi(IObjectMapperAdapter adapter)
 {
     Assert.True(adapter.MapperType.GetConstructors(BindingFlags.Instance | BindingFlags.Public).Any());
 }