private static (GetLearningRepetitionQueryHandler handler, GetLearningRepetitionRequestModel request) CreateDependencies(ApplicationDbContext context, Guid userId, int courseId = 10)
        {
            var profile = new MappingProfile();
            var config  = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <MappingProfile>();
            });
            var mapper = config.CreateMapper();

            var repetitionManagerMock = new Mock <IRepetitionManager>();

            repetitionManagerMock
            .Setup(rm => rm.CreateRepetitionData(It.Is <WordStats>(ws => ws.Id == 30)))
            .Returns(("Question", null, null, null, RepetitionType.FromExampleToTranslatedOpen));

            var handler = new GetLearningRepetitionQueryHandler(new UnitOfWork(context),
                                                                mapper, repetitionManagerMock.Object, new Mock <IAudioService>().Object);

            var request = new GetLearningRepetitionRequestModel
            {
                CourseId = courseId,
                UserId   = userId.ToString()
            };

            return(handler, request);
        }
Пример #2
0
        protected virtual async Task<LoginResponseDto> Create(UserProfileDto input)
        {
            var rtv = new LoginResponseDto();
            input.userPassword = Cryptors.GetSHAHashData(input.userPassword);
            input.IsLockoutEnabled = 0;
            input.DateCreated = DateTime.Now;
            input.userEmail = input.userEmail;
            input.ShouldChangePasswordOnNextLogin = 1;
            input.AccessFailedCount = 0;
            input.businessName = input.businessName;
            input.Country = input.Country;
            UserProfile userDto = MappingProfile.MappingConfigurationSetups().Map<UserProfile>(input);
            
            _context.UserProfile.Add(userDto);
           int res = await _context.SaveChangesAsync();
            if (res > 0)
            {
                rtv.ResponseCode = 0;
                rtv.ResponseText = "Successfull";
                return rtv;
            }
            else 
            {
                rtv.ResponseCode = -2;
                rtv.ResponseText = "Failed";
                return rtv;

            }


        }
Пример #3
0
        public SubjectServiceTest()
        {
            var myProfile     = new MappingProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile));
            var mapper        = new Mapper(configuration);

            _SubjectList = new List <Subject>()
            {
                new Subject()
                {
                    SubjectId = new Random().Next(1, int.MaxValue), Description = "Subject Test 1"
                },
                new Subject()
                {
                    SubjectId = new Random().Next(1, int.MaxValue), Description = "Subject Test 2"
                },
                new Subject()
                {
                    SubjectId = new Random().Next(1, int.MaxValue), Description = "Subject Test 3"
                },
                new Subject()
                {
                    SubjectId = new Random().Next(1, int.MaxValue), Description = "Subject Test 4"
                },
                new Subject()
                {
                    SubjectId = new Random().Next(1, int.MaxValue), Description = "Subject Test 5"
                }
            };

            SubjectService = new SubjectService(repoWrapperMock.Object, loggerMock.Object, mapper);
        }
Пример #4
0
        public void Mapper_ConditionMappingIsConfigured_FinishOnFirstHit()
        {
            var profile = new MappingProfile();

            profile.CreateProfile <FakeSource, FakeReceiver>()
            .UseAsDefault()
            .For(x => x.StringValue, x =>
            {
                x.If(HasCode("D")).ThenDo(ExpressionResolve(c => "No hit: never"));
                x.If(HasCode("D1")).ThenDo(ExpressionResolve(c => "First hit: should"));
                x.If(HasCode("D1") | HasCode("D2")).ThenDo(ExpressionResolve(c => "Second hit: never"));
                x.Do(ExpressionResolve(c => "Default hit: never"));
            })
            .For(x => x.IntValue, x =>
            {
                x.If(HasCode("X")).ThenDo(ExpressionResolve(c => - 1));
                x.If(HasCode("XF")).ThenDo(ExpressionResolve(c => - 2));
                x.If(HasCode("D2")).ThenDo(ExpressionResolve(c => 10));
                x.If(HasCode("D1") | HasCode("D2")).ThenDo(ExpressionResolve(c => - 3));
                x.Do(ExpressionResolve(c => - 4));
            });

            _mapperConfiguration.LoadProfile(profile);
            var source = CreateSource(codes: new[] { "D1", "D2" });

            var receiver = _subject.Map <FakeSource, FakeReceiver>(source);

            Assert.AreEqual("First hit: should", receiver.StringValue);
            Assert.AreEqual(10, receiver.IntValue);
        }
Пример #5
0
        public List <RatingDto> GetAllRating(RatingDto input)
        {
            var query = (from rating in _context.Rating.ToList()
                         join topic in _context.Topic.ToList()
                         on rating.TopicId equals topic.Id
                         select new RatingDto
            {
                RatingCount = rating.RatingCount,
                TopicId = topic.Id,
                TopicName = topic.Name,
                Id = rating.Id,
                DateCreated = rating.DateCreated,
                Status = rating.Status,
                UserId = rating.UserId
            }).ToList().Skip((input.PagedResultDto.Page - 1) * input.PagedResultDto.SkipCount).Take(input.PagedResultDto.MaxResultCount);

            // Map Records
            List <RatingDto> ratingDto = MappingProfile.MappingConfigurationSetups().Map <List <RatingDto> >(query);

            //Apply Sort
            ratingDto = Sort(input.PagedResultDto.Sort, input.PagedResultDto.SortOrder, ratingDto);

            // Apply search
            if (!string.IsNullOrEmpty(input.PagedResultDto.Search))
            {
                ratingDto = ratingDto.Where(p => p.Status != null && p.Status.ToLower().ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.TopicName != null && p.TopicName.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.DateCreated != null && p.DateCreated.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                            p.RatingCount != null && p.RatingCount.ToString().ToLower().ToString().Contains(input.PagedResultDto.Search.ToLower())
                                            ).ToList();
            }
            return(ratingDto);
        }
Пример #6
0
        public async void Should_Get_Item_ByIdAsync()
        {
            var itemGet = new Item {
                Id = 1, Description = "MyItem1Async"
            };

            var repositoryMock = new Mock <IRepository <Item> >();

            repositoryMock.Setup(u => u.GetAsync(1)).Returns(Task <Item>
                                                             .Factory
                                                             .StartNew(() => itemGet));

            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(u => u.Items).Returns(() => repositoryMock.Object);

            var mappingProfile = new MappingProfile();
            var config         = new MapperConfiguration(mappingProfile);
            var mapper         = new Mapper(config);

            var service = new ItemService(unitOfWorkMock.Object, new Parser(), mapper);

            var actualGet = await service.GetByIdAsync(1);

            Assert.NotNull(actualGet);
            Assert.Equal(itemGet.Description, itemGet.Description);

            repositoryMock.Verify(m => m.GetAsync(1));
        }
Пример #7
0
        protected virtual async Task Create(QuestionCategoryDto input)
        {
            QuestionCategory questionCategoryDto = MappingProfile.MappingConfigurationSetups().Map <QuestionCategory>(input);

            _context.QuestionCategory.Add(questionCategoryDto);
            await _context.SaveChangesAsync();
        }
Пример #8
0
        public OrderManagerTests()
        {
            var mappingProfile = new MappingProfile();
            var configuration  = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfile));

            _mapper = new Mapper(configuration);
        }
Пример #9
0
            public IMapper Mapper()
            {
                var myProfile     = new MappingProfile();
                var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile));

                return(new Mapper(configuration));
            }
Пример #10
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            var formatters = GlobalConfiguration.Configuration.Formatters;

            formatters.Remove(formatters.XmlFormatter);
            formatters.JsonFormatter.Indent = true;
            var mapper = MappingProfile.InitializeAutoMapper().CreateMapper();

            FluentValidationModelValidatorProvider.Configure(config);
            var container = new UnityContainer();

            container.RegisterType <IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());
            container.RegisterInstance <IMapper>(mapper);
            config.DependencyResolver = new UnityResolver(container);

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Пример #11
0
        public IEnumerable <POCO.MstItem> BulkRead(MstItemFilter filter = null, FilterMethods filterMethods = null)
        {
            IEnumerable <POCO.MstItem> result;

            var dynamicFilter = Filterer <MstItemFilter> .GetFilter(filter, filterMethods);

            var mappingProfile = new MappingProfile <Data.MstItem, POCO.MstItem>();

            using (var ctx = new posDataContext())
            {
                IEnumerable <Data.MstItem> data;

                if (filter != null)
                {
                    var enumerable       = dynamicFilter as Filter[] ?? dynamicFilter.ToArray();
                    var filterExpression = ExpressionBuilder
                                           .GetExpression <Data.MstItem>(enumerable.ToList()).Compile();

                    data = ctx.MstItems.Where(filterExpression);
                }
                else
                {
                    data = ctx.MstItems;
                }

                result = mappingProfile.mapper.Map <IEnumerable <Data.MstItem>, IEnumerable <POCO.MstItem> >(data);
            }

            return(result);
        }
Пример #12
0
        protected virtual async Task Create(CommentDto input)
        {
            Comment comment = MappingProfile.MappingConfigurationSetups().Map <Comment>(input);

            _context.Comment.Add(comment);
            await _context.SaveChangesAsync();
        }
Пример #13
0
        public AuthorServiceTest()
        {
            var myProfile     = new MappingProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile));
            var mapper        = new Mapper(configuration);

            _authorList = new List <Author>()
            {
                new Author()
                {
                    AuthorId = new Random().Next(1, int.MaxValue), Name = "Author Test 1"
                },
                new Author()
                {
                    AuthorId = new Random().Next(1, int.MaxValue), Name = "Author Test 2"
                },
                new Author()
                {
                    AuthorId = new Random().Next(1, int.MaxValue), Name = "Author Test 3"
                },
                new Author()
                {
                    AuthorId = new Random().Next(1, int.MaxValue), Name = "Author Test 4"
                },
                new Author()
                {
                    AuthorId = new Random().Next(1, int.MaxValue), Name = "Author Test 5"
                }
            };

            authorService = new AuthorService(repoWrapperMock.Object, loggerMock.Object, mapper);
        }
Пример #14
0
        static async Task Main(string[] args)
        {
            var coachesList = new HashSet <List <CoacheDto> >();
            var tasks       = new List <Task <IRestResponse> >();

            var restResponse = await Task.WhenAny(TeamEndpoint.GetAllByYear()).Result;

            var teamsList = new JsonDeserializer().Deserialize <List <TeamDto> >(restResponse);

            foreach (var team in teamsList)
            {
                tasks.Add(CoachEndpoint.GetCoacheByTeam($"{team.School}"));
            }

            var coachResponse = await Task.WhenAll(tasks);

            foreach (var response in coachResponse)
            {
                var coache = new JsonDeserializer().Deserialize <List <CoacheDto> >(response);
                coachesList.Add(coache);
            }

            var mapping = new MappingProfile();
            var result  = mapping.Map(coachesList, teamsList);

            var repo = new Repository();
            await repo.AddAsync(result);
        }
Пример #15
0
        public List <QuestionCategoryDto> GetAllQuestionCategory(QuestionCategoryDto input)
        {
            var query = (from questionCategory in _context.QuestionCategory.ToList()
                         select new QuestionCategoryDto
            {
                Name = questionCategory.Name,
                Id = questionCategory.Id,
                DateCreated = questionCategory.DateCreated,
                Status = questionCategory.Status,
                UserId = questionCategory.UserId
            }).ToList().Skip((input.PagedResultDto.Page - 1) * input.PagedResultDto.SkipCount).Take(input.PagedResultDto.MaxResultCount);

            // Map Records
            List <QuestionCategoryDto> roleDto = MappingProfile.MappingConfigurationSetups().Map <List <QuestionCategoryDto> >(query);

            //Apply Sort
            roleDto = Sort(input.PagedResultDto.Sort, input.PagedResultDto.SortOrder, roleDto);

            // Apply search
            if (!string.IsNullOrEmpty(input.PagedResultDto.Search))
            {
                roleDto = roleDto.Where(p => p.Status != null && p.Status.ToLower().ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                        p.Name != null && p.Name.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) ||
                                        p.DateCreated != null && p.DateCreated.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower())
                                        ).ToList();
            }
            return(roleDto);
        }
        private IMapper MockMapper()
        {
            var profile       = new MappingProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile));

            return(new Mapper(configuration));
        }
Пример #17
0
        protected virtual async Task Create(QuestionDto input)
        {
            Question comment = MappingProfile.MappingConfigurationSetups().Map <Question>(input);

            _context.Question.Add(comment);
            await _context.SaveChangesAsync();
        }
Пример #18
0
        protected virtual async Task Create(RatingDto input)
        {
            Rating ratingDto = MappingProfile.MappingConfigurationSetups().Map <Rating>(input);

            _context.Rating.Add(ratingDto);
            await _context.SaveChangesAsync();
        }
Пример #19
0
        protected virtual async Task Create(VideoCategoryDto input)
        {
            VideoCategory videoDto = MappingProfile.MappingConfigurationSetups().Map <VideoCategory>(input);

            _context.VideoCategory.Add(videoDto);
            await _context.SaveChangesAsync();
        }
Пример #20
0
        public static void ShowBuildMappingForm(SPDocumentLibrary docLib, MappingProfile mp)
        {
            if (docLib == null)
                return;
            frmBuildMapping f = new frmBuildMapping();

            //--populate cboTargetContentType
            List<string> inelligableContentTypes = new List<string>();
            //inelligableContentTypes.Add("Document");
            inelligableContentTypes.Add("Folder");
            foreach (SPContentType ct in docLib.ContentTypes)
            {
                if (!inelligableContentTypes.Contains(ct.Name)) 
                    f.cboTargetContentType.Items.Add(ct.Name);
            }

            //--
            f.lblTargetDocLib.Text = "Target Document Library: " + docLib.Title;
            f.m_targetDocLib = docLib;
            if (mp == null) //--create a new Mapping Profile
            {
                f.m_mpWorking = new MappingProfile("new profile","");
                f.m_mpWorking.MappingItems = new List<MappingItem>();
                f.txtProfileName.Text = "(New Mapping Profile)";
                f.Text = "New Mapping Profile";
                f.lnkDeleteProfile.Enabled = false;
                if (f.cboTargetContentType.Items.Count == 1)
                    f.cboTargetContentType.SelectedIndex = 0;
            }
            else //--edit existing Mapping Profile
            {
                f.m_editingMPindex = ActionMetaDataUtil.MappingProfiles.IndexOf(mp);
                MappingProfile ret = (MappingProfile)Util.DeepCopy(mp);
                if (ret == null)
                    return;
                f.m_mpWorking = ret;
                f.txtProfileName.Text = mp.ProfileName;
                f.cboTargetContentType.SelectedIndex = f.cboTargetContentType.FindStringExact(mp.TargetContentTypeName);
                f.Text = "Edit Mapping Profile";
                if (f.m_mpWorking.MappingItems == null)
                    f.m_mpWorking.MappingItems = new List<MappingItem>();
            }

            f.displayMappingProfileInRtb(null, null);
            f.Location = new Point(MainForm.DefInstance.Left +10 , MainForm.DefInstance.Top + 10);

            //--
            f.ShowDialog();
        }
Пример #21
0
        private bool findColoumRefFromInternalName(MappingProfile mp, SPList list)
        {
            int countFound = 0;
            foreach (MappingItem mi in mp.MappingItems)
            {
                mi.sourceID = new Guid();
                mi.destID = new Guid();
                foreach (SPField field in list.Fields)
                {
                    if (field.InternalName == mi.SourceColumn)
                    {
                        mi.sourceID = field.Id;
                        mi.sourceTypeAsString = field.TypeAsString;
                        break;
                    }
                }
                foreach (SPField field in list.Fields)
                {
                    if (field.InternalName == mi.DestColumn)
                    {
                        mi.destID = field.Id;
                        mi.destTypeAsString = field.TypeAsString;
                        break;
                    }
                }

                if (mi.sourceID == new Guid())
                    AddToRtbLocal("source column " + mi.SourceColumn + " not found\r\n", StyleType.bodyRed);
                else
                {
                    AddToRtbLocal("source column " + mi.SourceColumn + " found\r\n", StyleType.bodySeaGreen);
                    countFound++;
                }
                if (mi.destID == new Guid())
                    AddToRtbLocal("  ->destination column " + mi.DestColumn + " not found\r\n", StyleType.bodyRed);
                else
                {
                    AddToRtbLocal("  ->destination column " + mi.DestColumn + " found\r\n", StyleType.bodySeaGreen);
                    countFound++;
                }
            }
            if (countFound != mp.MappingItems.Count * 2)
                return false;

            return true;
        }