/// <summary>
        /// Creates a proxy Fluent Method Group.
        /// </summary>
        /// <param name="subjectFluentMethodGroup">the first group that become either subject or gets generalized depending on the generalizeSubject parameter</param>
        /// <param name="secondaryFluentMethodGroup">the second group which is always gets generalized</param>
        /// <param name="generalizeSubject">decides whether the subject fluent method group also needs to be generalized</param>
        /// <returns>proxy fluent method group</returns>
        public static ProxyFluentMethodGroup Create(IFluentMethodGroup subjectFluentMethodGroup, IFluentMethodGroup secondaryFluentMethodGroup, bool generalizeSubject)
        {
            ProxyFluentMethodGroup proxy = Init(subjectFluentMethodGroup);

            //
            if (generalizeSubject)
            {
                proxy.subjectFluentMethodGroup = null;  // No subject, means use nullObjects
                // -- Generalize the subject Fluent Method Group --
                GeneralizedOutput subjectGeneralized = GeneralizedOutput.Generalize(subjectFluentMethodGroup);
                //
                if (!subjectGeneralized.IsEmpty)
                {
                    proxy.generalizedOutputs.Add(subjectGeneralized);
                }
                foreach (var output in subjectGeneralized.GeneralizedOutputs.Where(gop => !gop.IsEmpty))
                {
                    proxy.generalizedOutputs.Add(output);
                }
                //
                proxy.innerMethods.AddRange(subjectFluentMethodGroup.InnerMethods);
                proxy.childFluentMethodGroups.AddRange(subjectFluentMethodGroup.ChildFluentMethodGroups);
            }
            else
            {
                proxy.subjectFluentMethodGroup = subjectFluentMethodGroup;
                //
                foreach (var output in subjectFluentMethodGroup.GeneralizedOutputs.Where(gop => !gop.IsEmpty))
                {
                    proxy.generalizedOutputs.Add(output);
                }
                proxy.innerMethods.AddRange(subjectFluentMethodGroup.InnerMethods);
                proxy.childFluentMethodGroups.AddRange(subjectFluentMethodGroup.ChildFluentMethodGroups);
            }
            //
            // -- Generalize the secondary  Fluent Method Group  --
            GeneralizedOutput secondaryGeneralized = GeneralizedOutput.Generalize(secondaryFluentMethodGroup);

            //
            if (!secondaryGeneralized.IsEmpty)
            {
                proxy.generalizedOutputs.Add(secondaryGeneralized);
            }
            foreach (var output in secondaryGeneralized.GeneralizedOutputs.Where(gop => !gop.IsEmpty))
            {
                proxy.generalizedOutputs.Add(output);
            }
            //
            proxy.innerMethods.AddRange(secondaryFluentMethodGroup.InnerMethods);
            //
            proxy.childFluentMethodGroups.AddRange(secondaryFluentMethodGroup.ChildFluentMethodGroups);
            //
            return(proxy);
        }
Пример #2
0
        /// <summary>
        /// Creates a proxy fluent method group for the given fluent method group.
        /// </summary>
        /// <param name="subjectFluentMethodGroup">the subject for which proxy needs to be created</param>
        /// <returns>proxy fluent method group</returns>
        public static ProxyFluentMethodGroup Create(IFluentMethodGroup subjectFluentMethodGroup)
        {
            ProxyFluentMethodGroup proxy = Init(subjectFluentMethodGroup);

            //
            proxy.subjectFluentMethodGroup = subjectFluentMethodGroup;
            //
            foreach (var output in subjectFluentMethodGroup.GeneralizedOutputs.Where(gop => !gop.IsEmpty))
            {
                proxy.generalizedOutputs.Add(output);
            }
            return(proxy);
        }
Пример #3
0
        /// <summary>
        /// Prune the "Segment Fluent Method Group" in this list to produce a "Fluent Method Group".
        /// </summary>
        /// <returns>Fluent Method Group</returns>
        public IFluentMethodGroup Prune()
        {
            var localGroups = this;

            if (localGroups.Count == 0)
            {
                return(null);
            }
            else
            {
                IFluentMethodGroup prunedGroup = ProxyFluentMethodGroup.Create(localGroups.First());
                foreach (ISegmentFluentMethodGroup currentGroup in localGroups.Skip(1))
                {
                    if (prunedGroup.StandardFluentModel == null)
                    {
                        if (currentGroup.StandardFluentModel == null)
                        {
                            // If both doesn't have standard model then create a proxy by generalizing both
                            //
                            prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true);
                        }
                        else
                        {
                            if (prunedGroup.GeneralizedOutputs.Select(go => go.DefineFunc).Any(d => d.IsDefineSupported))
                            {
                                prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true);
                            }
                            else
                            {
                                // If the current one have a standard model then make it the subject and generalize the pruned one
                                //
                                prunedGroup = ProxyFluentMethodGroup.Create(currentGroup, prunedGroup, false);
                            }
                        }
                    }
                    else
                    {
                        if (prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase) &&
                            currentGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase))
                        {
                            // If both has standard model and both local names matches with the inner method group name then
                            // create a proxy by generalizing both.
                            //
                            prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true);
                        }
                        else if (!prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase) &&
                                 !currentGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase))
                        {
                            // If both has standard model and both local names doesn't matches with the inner method group name then
                            // create a proxy by generalizing both.
                            //
                            prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, true);
                        }
                        else if (prunedGroup.LocalNameInPascalCase.Equals(this.InnerMethodGroupName, StringComparison.OrdinalIgnoreCase))
                        {
                            // If both has standard models but only the local name of pruned matches with the inner method
                            // group name then create a proxy with pruned as subject and current one generalized.
                            //
                            prunedGroup = ProxyFluentMethodGroup.Create(prunedGroup, currentGroup, false);
                        }
                        else
                        {
                            // If both has standard models but only the local name of current matches with the inner method
                            // group name then create a proxy with current as subject and pruned one generalized.
                            //
                            prunedGroup = ProxyFluentMethodGroup.Create(currentGroup, prunedGroup, false);
                        }
                    }
                }
                this.PrunedMethodGroup = prunedGroup;
                return(prunedGroup);
            }
        }