예제 #1
0
        public async Task SearchItemTemplateAsync_ShouldTryToFindItemsInDatabaseWithMoreAccurateSearchFirstThenWithFuzzyFilter()
        {
            const string filter      = "some-filter";
            const string cleanFilter = "SOME-CLEAN-FILTER";
            const string cleanFilterWithoutSeparator = "SOME-CLEAN-FILTER-WITH-NO-SEPARATOR";
            var          itemTemplateId1             = Guid.NewGuid();
            var          itemTemplateId2             = Guid.NewGuid();
            var          itemTemplateId3             = Guid.NewGuid();

            var item1 = new ItemTemplate {
                Id = itemTemplateId1
            };
            var item2 = new ItemTemplate {
                Id = itemTemplateId2
            };
            var item3 = new ItemTemplate {
                Id = itemTemplateId3
            };

            _stringCleanupUtil.RemoveAccents(filter)
            .Returns(cleanFilter);
            _stringCleanupUtil.RemoveSeparators(cleanFilter)
            .Returns(cleanFilterWithoutSeparator);
            _unitOfWorkFactory.GetUnitOfWork().ItemTemplates.GetItemByCleanNameWithAllDataAsync(cleanFilter, Arg.Any <int>(), Arg.Any <int?>(), Arg.Any <bool>())
            .Returns(new List <ItemTemplate> {
                item1
            });
            _unitOfWorkFactory.GetUnitOfWork().ItemTemplates.GetItemByPartialCleanNameWithAllDataAsync(cleanFilter, Arg.Any <int>(), Arg.Any <IEnumerable <Guid> >(), Arg.Any <int?>(), Arg.Any <bool>())
            .Returns(new List <ItemTemplate> {
                item2
            });
            _unitOfWorkFactory.GetUnitOfWork().ItemTemplates.GetItemByPartialCleanNameWithoutSeparatorWithAllDataAsync(cleanFilterWithoutSeparator, Arg.Any <int>(), Arg.Any <IEnumerable <Guid> >(), Arg.Any <int?>(), Arg.Any <bool>())
            .Returns(new List <ItemTemplate> {
                item3
            });

            var actualItemTemplates = await _service.SearchItemTemplateAsync(filter, 40, null);

            actualItemTemplates.Should().BeEquivalentTo(item1, item2, item3);
        }
예제 #2
0
        public void ApplyChangesFromRequest_UpdateCleanName()
        {
            var itemTemplate = new ItemTemplate {
                Name = "some-name"
            };
            var request = new ItemTemplateRequest {
                Name = "some-new-name"
            };

            _stringCleanupUtil.RemoveAccents("some-new-name")
            .Returns("some-new-clean-name");

            _util.ApplyChangesFromRequest(itemTemplate, request);

            itemTemplate.CleanName.Should().BeEquivalentTo("some-new-clean-name");
        }
        public void ApplyChangesFromRequest(ItemTemplate itemTemplate, ItemTemplateRequest request)
        {
            itemTemplate.Name          = request.Name;
            itemTemplate.TechName      = request.TechName;
            itemTemplate.Source        = request.Source;
            itemTemplate.SubCategoryId = request.SubCategoryId;
            itemTemplate.Data          = JsonConvert.SerializeObject(request.Data, Formatting.None);

            itemTemplate.CleanName = _stringCleanupUtil.RemoveAccents(request.Name);

            itemTemplate.Slots = request.Slots?.Select(x => new ItemTemplateSlot {
                SlotId = x.Id
            }).ToList() ?? new List <ItemTemplateSlot>();

            itemTemplate.Requirements = request.Requirements?.Select(x => new ItemTemplateRequirement
            {
                StatName = x.Stat,
                MaxValue = x.Max,
                MinValue = x.Min
            }).ToList() ?? new List <ItemTemplateRequirement>();

            itemTemplate.Modifiers = request.Modifiers?.Select(x => new ItemTemplateModifier
            {
                StatName         = x.Stat,
                RequiredJobId    = x.JobId,
                RequiredOriginId = x.OriginId,
                Value            = x.Value,
                Type             = x.Type,
                Special          = x.Special == null ? "" : string.Join(',', x.Special)
            }).ToList() ?? new List <ItemTemplateModifier>();

            itemTemplate.Skills = request.SkillIds?.Select(skillId => new ItemTemplateSkill
            {
                SkillId = skillId
            }).ToList() ?? new List <ItemTemplateSkill>();

            itemTemplate.UnSkills = request.UnSkillIds?.Select(skillId => new ItemTemplateUnSkill
            {
                SkillId = skillId
            }).ToList() ?? new List <ItemTemplateUnSkill>();

            itemTemplate.SkillModifiers = request.SkillModifiers?.Select(x => new ItemTemplateSkillModifier
            {
                SkillId = x.SkillId,
                Value   = x.Value
            }).ToList() ?? new List <ItemTemplateSkillModifier>();
        }
예제 #4
0
        public async Task <List <ItemTemplate> > SearchItemTemplateAsync(string filter, int maxResultCount, int?currentUserId)
        {
            var matchingItemTemplates = new List <ItemTemplate>();

            using (var uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var cleanFilter = _stringCleanupUtil.RemoveAccents(filter).ToUpperInvariant();

                var exactMatchingItems = await uow.ItemTemplates.GetItemByCleanNameWithAllDataAsync(cleanFilter, maxResultCount, currentUserId, true);

                matchingItemTemplates.AddRange(exactMatchingItems);

                var partialMatchingItems = await uow.ItemTemplates.GetItemByPartialCleanNameWithAllDataAsync(cleanFilter, maxResultCount - matchingItemTemplates.Count, matchingItemTemplates.Select(i => i.Id), currentUserId, true);

                matchingItemTemplates.AddRange(partialMatchingItems);

                var noSeparatorFilter = _stringCleanupUtil.RemoveSeparators(cleanFilter);
                var partialMatchingIgnoreSpacesItems = await uow.ItemTemplates.GetItemByPartialCleanNameWithoutSeparatorWithAllDataAsync(noSeparatorFilter, maxResultCount - matchingItemTemplates.Count, matchingItemTemplates.Select(i => i.Id), currentUserId, true);

                matchingItemTemplates.AddRange(partialMatchingIgnoreSpacesItems);
            }

            return(matchingItemTemplates);
        }