Пример #1
0
        public static XmlResource GetUpdatedResourcePhaseField(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int index, HrbcOptionSearch phaseSearcher, HrbcPhaseEntryReader phaseEntryReader,
                                                               List <KeyValuePair <int, PhaseFlowContent> > resourcePhaseFlow, Dictionary <Enums.ResourceType, Dictionary <string, OptionSearchContent> > phaseDictionary, HrbcRecordCreator records)
        {
            string phaseAlias     = $"{resourceType.ToResourceName()}.{PhaseField}";
            string phaseDateAlias = $"{resourceType.ToResourceName()}.{PhaseDateField}";
            Option phaseValue     = GetPhaseOption(resourceType, phaseOptionType, index, phaseSearcher, phaseEntryReader, resourcePhaseFlow, phaseDictionary);
            string phaseDateValue = GetPhaseDate(resourceType, phaseDateType, index, phaseEntryReader);
            string recordId       = records.Data[$"{resourceType.ToPrivateEnum()}{index}"].Id.ToString();
            var    resource       = ResourceHelper.CreateUpdatedResource(resourceType, recordId, phaseDateAlias, phaseDateValue);

            if (phaseDateValue == string.Empty)
            {
                resource.DictionaryValues.Remove(phaseDateAlias);
            }
            if (phaseValue != null)
            {
                resource.DictionaryValues[phaseAlias] = phaseValue;
            }
            return(resource);
        }
Пример #2
0
        private static Option GetPhaseOption(Enums.ResourceType resourceType, PhaseOptionInput phaseOptionType, int index, HrbcOptionSearch PhaseSearcher, HrbcPhaseEntryReader phaseEntryReader,
                                             List <KeyValuePair <int, PhaseFlowContent> > resourcePhaseFlow, Dictionary <Enums.ResourceType, Dictionary <string, OptionSearchContent> > phaseDictionary)
        {
            var resourceRootPhase = PhaseSearcher.Data.Options.Where(op => op.Alias == $"Option.P_{resourceType.ToResourceName()}Phase").SingleOrDefault();
            var listOption        = resourceRootPhase.Children.Where(c => c.Children != null && c.Children.Count >= 2).OrderBy(c => c.Sort).ToList();

            Assume.That(listOption.Count, Is.GreaterThan(2), "Less Than 3 options");
            var recentExpectedPhase = listOption.ElementAt(1).Children.ElementAt(1);
            var phaseIdContent      = phaseDictionary[resourceType];
            var recentPhaseName     = phaseEntryReader.Data[$"{resourceType.ToPrivateEnum()}{index}"].Where(phase => phase.Flag == "1").SingleOrDefault().Phase;
            var recentPhaseId       = resourcePhaseFlow.Where(r => r.Value.Name == recentPhaseName).SingleOrDefault().Key;
            var recentPhase         = phaseIdContent[recentPhaseId.ToString()];
            var recentParentPhase   = phaseIdContent[recentPhase.ParentId.ToString()];

            Assume.That(recentPhaseId, Is.EqualTo((int)recentExpectedPhase.Id), "Recent Phase does not match the expected one.");
            int nextPhaseOptionId = 0;

            switch (phaseOptionType)
            {
            case PhaseOptionInput.GreaterThanCurrentPhase:
                nextPhaseOptionId = resourcePhaseFlow.Last().Key;
                break;

            case PhaseOptionInput.SameSortButGreaterParent:
                nextPhaseOptionId = (int)listOption.ElementAt(2).Children.ElementAt(1).Id;
                break;

            case PhaseOptionInput.SmallerThanCurrentPhase:
                nextPhaseOptionId = resourcePhaseFlow.First().Key;
                break;

            case PhaseOptionInput.SameSortButSmallerParent:
                nextPhaseOptionId = (int)listOption.ElementAt(0).Children.ElementAt(1).Id;
                break;

            case PhaseOptionInput.SmallerSortSmallerParent:
                nextPhaseOptionId = (int)listOption.ElementAt(0).Children.ElementAt(0).Id;
                break;

            case PhaseOptionInput.EqualToCurrentPhase:
                nextPhaseOptionId = recentPhaseId;
                break;

            case PhaseOptionInput.NoPhase:
                break;

            default:
                break;
            }
            if (nextPhaseOptionId == 0)
            {
                return(null);
            }
            else
            {
                return(new Option()
                {
                    ActualXMLTag = phaseIdContent[nextPhaseOptionId.ToString()].Alias
                });
            }
            throw new NotImplementedException();
        }
        public void TestUpdateSingleItem(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int expectedCode, int index)
        {
            phaseDictionary = PhaseFieldHelper.InitPhaseList(phaseSearcher);
            var resource = PhaseFieldHelper.GetUpdatedResourcePhaseField(resourceType, phaseDateType, phaseOptionType, index,
                                                                         phaseSearcher, phaseEntryReader, GetPhaseOrderBySort(resourceType), phaseDictionary, records);
            string result = ResourceHelper.WriteResource(resource, null);

            Assert.That(result, MustBe.EqualTo(records.Data[$"{resourceType.ToPrivateEnum()}{index}"].Id.ToString()), string.Format("Cannot update phase for {0}", resourceType));
        }
        public void TestUpdateListItem(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int expectedCode, int index)
        {
            phaseDictionary = PhaseFieldHelper.InitPhaseList(phaseSearcher);
            var resourceList = new int[] { (index * 2), (index * 2 + 1) }.Select(keyDep =>
            {
                return(PhaseFieldHelper.GetUpdatedResourcePhaseField(resourceType, phaseDateType, phaseOptionType, keyDep,
                                                                     phaseSearcher, phaseEntryReader, GetPhaseOrderBySort(resourceType), phaseDictionary, records));
            }).ToList();

            List <WriteResultItem> result = ResourceHelper.WriteResources(resourceType, resourceList, null);

            Assert.That(result, MustBe.SuccessfullyWritten(2), string.Format("Cannot update phase for {0}", resourceType));
        }
        public void TestUpdateSingleItem(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int expectedCode)
        {
            phaseDictionary = PhaseFieldHelper.InitPhaseList(phaseSearcher);
            var resource = PhaseFieldHelper.GetUpdatedResourcePhaseField(resourceType, phaseDateType, phaseOptionType, 0,
                                                                         phaseSearcher, phaseEntryReader, GetPhaseOrderBySort(resourceType), phaseDictionary, records);
            ErrorCode result = ResourceHelper.WriteResourceFail(resource, null);

            Assert.That(result, MustBe.MatchingErrorCode(expectedCode), string.Format("Cannot create phase for {0}", resourceType));
        }
        public void TestUpdateListItem(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int expectedCode)
        {
            phaseDictionary = PhaseFieldHelper.InitPhaseList(phaseSearcher);
            var resourceList = new int[] { 0, 1 }.Select(keyDep =>
            {
                return(PhaseFieldHelper.GetUpdatedResourcePhaseField(resourceType, phaseDateType, phaseOptionType, keyDep,
                                                                     phaseSearcher, phaseEntryReader, GetPhaseOrderBySort(resourceType), phaseDictionary, records));
            }).ToList();

            ErrorCode result = ResourceHelper.WriteResourcesFail(resourceList, null);

            Assert.That(result, MustBe.MatchingErrorCode(expectedCode), string.Format("Cannot create phase for {0}", resourceType));
        }