Пример #1
0
        public void ItShouldNotFilterComplexAndFiltersWhenFirstNotFilter()
        {
            var filter1 = new Filter <int, bool>("{0} > {1}")
            {
                Sequence = 1
            };

            filter1.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 20)
            });
            var filter2 = new Filter <int, bool>("{2} = {3}")
            {
                Sequence = 2
            };

            filter2.SetConnector("AND");
            filter2.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("2", 10), SetDictionary("3", 10)
            });
            var concept = new Concept <int>();

            concept.AddFilter(filter1);
            concept.AddFilter(filter2);
            Assert.IsFalse(concept.Filter(Month.January));
        }
Пример #2
0
        public void ItShouldCreateOperationFromConcept()
        {
            var concept = new Concept <int>("({0} * {1}) + ({2} * {3})");
            var filter  = new Filter <int, bool>("{0} > {1}");

            filter.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 1)
            });
            concept.AddFilter(filter);
            var january = SetDictionary("0", 2);

            january.Value[Month.January] = 3;
            concept.SetParameters(new List <IMonthlyParameter <int> >
            {
                january, SetDictionary("1", 3), SetDictionary("2", 2), SetDictionary("3", 5)
            });
            var output = SetDictionary("output", 25);

            concept.AddOutputParameter1(output);

            concept.Run();
            Assert.AreEqual(16, concept.Output1.Value[Month.May]);
            Assert.AreEqual(16, output.Value[Month.August]);
            Assert.AreEqual(19, concept.Output1.Value[Month.January]);
            Assert.AreEqual(19, output.Value[Month.January]);
        }
Пример #3
0
        public void ItShouldNameOutputWithConceptTitleWhenNoName()
        {
            var concept = new Concept <int>("({0} * {1}) + ({2} * {3})")
            {
                Title = "Concept"
            };
            var filter = new Filter <int, bool>("{0} > {1}");

            filter.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 1)
            });
            concept.AddFilter(filter);
            var january = SetDictionary("0", 2);

            january.Value[Month.January] = 3;
            concept.SetParameters(new List <IMonthlyParameter <int> > {
                january, SetDictionary("1", 3), SetDictionary("2", 2), SetDictionary("3", 5)
            });


            concept.Run();
            Assert.AreEqual(16, concept.Output1.Value[Month.May]);
            Assert.AreEqual(19, concept.Output1.Value[Month.January]);
            Assert.AreEqual("Concept", concept.Output1.Name);
        }
Пример #4
0
        public void ItShouldReplaceOutputValue()
        {
            var filter = new Filter <int, bool>("{0} > {1}");

            filter.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 1)
            });
            var concept = new Concept <int>();

            concept.AddFilter(filter);
            const string text      = "({0} * {1}) + ({2} * {3})";
            var          operation = new RuleTree <int, int>(text);

            operation.SetParameters(
                new List <IMonthlyParameter <int> > {
                SetDictionary("0", 2), SetDictionary("1", 3), SetDictionary("2", 2), SetDictionary("3", 5)
            });
            concept.AddOperation(operation);
            var output = SetDictionary("output", 25);

            concept.AddOutputParameter1(output);

            concept.Run();
            Assert.AreEqual(16, concept.Output1.Value[Month.May]);
            Assert.AreEqual(16, output.Value[Month.August]);
        }
Пример #5
0
        public void ItShouldFilterWhenFilterSuccess()
        {
            var filter = new Filter <int, bool>("{0} > {1}")
            {
                Parameter1 = SetDictionary("0", 10),
                Parameter2 = SetDictionary("1", 1)
            };
            var concept = new Concept <int>();

            concept.AddFilter(filter);
            Assert.IsTrue(concept.Filter(Month.January));
        }
Пример #6
0
        public void ItShouldRunWhenFilterAndOperations()
        {
            var filter = new Filter <int, bool>("{0} > {1}")
            {
                Parameter1 = SetDictionary("0", 10),
                Parameter2 = SetDictionary("1", 1)
            };
            var concept = new Concept <int>();

            concept.AddFilter(filter);
            var operation = new Mock <IRule <int, int> >();

            operation.Setup(x => x.GetResult()).Returns(SetDictionary("0", 1));
            concept.AddOperation(operation.Object);
            Assert.DoesNotThrow(concept.Run);
        }
Пример #7
0
        public void ItShouldGet16OnComplexOperation()
        {
            var filter = new Filter <int, bool>("{0} > {1}");

            filter.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 1)
            });
            var concept = new Concept <int>("({0} * {1}) + ({2} * {3})");

            concept.AddFilter(filter);
            concept.SetParameters(
                new List <IMonthlyParameter <int> > {
                SetDictionary("0", 2), SetDictionary("1", 3), SetDictionary("2", 2), SetDictionary("3", 5)
            });
            concept.Run();
            Assert.AreEqual(16, concept.Output1.Value[Month.May]);
        }
Пример #8
0
        public void ItShouldGet15OnOutput()
        {
            var filter = new Filter <int, bool>("{0} > {1}")
            {
                Parameter1 = SetDictionary("0", 10),
                Parameter2 = SetDictionary("1", 1)
            };
            var concept = new Concept <int>();

            concept.AddFilter(filter);
            var operation = new Mock <IRule <int, int> >();

            operation.Setup(x => x.GetResult()).Returns(SetDictionary("0", 15));
            concept.AddOperation(operation.Object);
            concept.Run();
            Assert.AreEqual(15, concept.Output1.Value[Month.March]);
        }
Пример #9
0
        public void ItShouldAddValueToOutputParameter()
        {
            var filter = new Filter <int, bool>("{0} > {1}");

            filter.SetParameters(new List <IMonthlyParameter <int> > {
                SetDictionary("0", 10), SetDictionary("1", 1)
            });
            var concept = new Concept <int>("({0} * {1}) + ({2} * {3})");

            concept.AddFilter(filter);
            concept.SetParameters(
                new List <IMonthlyParameter <int> > {
                SetDictionary("0", 2), SetDictionary("1", 3), SetDictionary("2", 2), SetDictionary("3", 5)
            });
            var output = SetDictionary("output", 10);

            output.IsAccumulator = true;
            concept.AddOutputParameter1(output);

            concept.Run();
            Assert.AreEqual(26, concept.Output1.Value[Month.June]);
            Assert.AreEqual(26, output.Value[Month.February]);
        }
Пример #10
0
        public static Concept <decimal> ToModel(this Concept conceptDb)
        {
            var concept = new Concept <decimal>(conceptDb.Operation)
            {
                Id          = conceptDb.ConceptId,
                Description = conceptDb.Description,
                GLAccountId = conceptDb.GLAccountID,
                Title       = conceptDb.Title,
                Sequence    = conceptDb.Sequence
            };

            //var parameters = new List<IMonthlyParameter<decimal>>();

            if (conceptDb.Output1 != null)
            {
                concept.Output1 = new Global <decimal>()
                {
                    Id            = conceptDb.Output1.ParameterId,
                    Name          = conceptDb.Output1.Name,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Output1.ParameterTypeId
                };

                //parameters.Add(concept.Output1);
            }

            if (conceptDb.Output2 != null)
            {
                concept.Output2 = new Global <decimal>()
                {
                    Id            = conceptDb.Output2.ParameterId,
                    Name          = conceptDb.Output2.Name,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Output2.ParameterTypeId
                };
                //parameters.Add(concept.Output2);
            }

            if (conceptDb.Parameter1 != null)
            {
                concept.Parameter1 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter1.ParameterId,
                    Name          = conceptDb.Parameter1.Name,
                    Description   = conceptDb.Parameter1.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter1.ParameterTypeId
                };
                //parameters.Add(concept.Parameter1);
            }

            if (conceptDb.Parameter2 != null)
            {
                concept.Parameter2 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter2.ParameterId,
                    Name          = conceptDb.Parameter2.Name,
                    Description   = conceptDb.Parameter2.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter2.ParameterTypeId
                };
                //parameters.Add(concept.Parameter2);
            }

            if (conceptDb.Parameter3 != null)
            {
                concept.Parameter3 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter3.ParameterId,
                    Name          = conceptDb.Parameter3.Name,
                    Description   = conceptDb.Parameter3.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter3.ParameterTypeId
                };
                //parameters.Add(concept.Parameter3);
            }

            if (conceptDb.Parameter4 != null)
            {
                concept.Parameter4 = new Global <decimal>()
                {
                    Id            = conceptDb.Parameter4.ParameterId,
                    Name          = conceptDb.Parameter4.Name,
                    Description   = conceptDb.Parameter4.Description,
                    ParameterType = (FromDisney.ParameterType)conceptDb.Parameter4.ParameterTypeId
                };
                //parameters.Add(concept.Parameter4);
            }

            if (conceptDb.GLAccount != null)
            {
                concept.GLAccount = new Core.GLAccount
                {
                    Title   = conceptDb.GLAccount.Title,
                    SAPCode = conceptDb.GLAccount.SAPCode,
                };
            }

            if (conceptDb.ExpenseType != null)
            {
                concept.ExpenseType = new Engine.Core.ExpenseType
                {
                    Id          = conceptDb.ExpenseType.ExpenseTypeId,
                    Code        = conceptDb.ExpenseType.Code,
                    Description = conceptDb.ExpenseType.Description,
                    IsActive    = conceptDb.ExpenseType.IsActive
                };

                if (conceptDb.ExpenseType.ExpenseGroup != null)
                {
                    concept.ExpenseType.ExpenseGroup = new Engine.Core.ExpenseGroup
                    {
                        Id          = conceptDb.ExpenseType.ExpenseGroup.ExpenseGroupId,
                        Code        = conceptDb.ExpenseType.ExpenseGroup.Code,
                        Description = conceptDb.ExpenseType.ExpenseGroup.Description,
                        IsActive    = conceptDb.ExpenseType.ExpenseGroup.IsActive
                    };
                }
            }

            var cvm = conceptDb.ConceptsValidMonths.OrderBy(m => m.MonthId).ToList();

            concept.ValidMonths = new Dictionary <Month, bool>
            {
                { Month.January, cvm.Any(m => m.MonthId == (int)Month.January) },
                { Month.February, cvm.Any(m => m.MonthId == (int)Month.February) },
                { Month.March, cvm.Any(m => m.MonthId == (int)Month.March) },
                { Month.April, cvm.Any(m => m.MonthId == (int)Month.April) },
                { Month.May, cvm.Any(m => m.MonthId == (int)Month.May) },
                { Month.June, cvm.Any(m => m.MonthId == (int)Month.June) },
                { Month.July, cvm.Any(m => m.MonthId == (int)Month.July) },
                { Month.August, cvm.Any(m => m.MonthId == (int)Month.August) },
                { Month.September, cvm.Any(m => m.MonthId == (int)Month.September) },
                { Month.October, cvm.Any(m => m.MonthId == (int)Month.October) },
                { Month.November, cvm.Any(m => m.MonthId == (int)Month.November) },
                { Month.December, cvm.Any(m => m.MonthId == (int)Month.December) }
            };


            if (conceptDb.ConceptFilters != null)
            {
                foreach (ConceptFilter cf in conceptDb.ConceptFilters)
                {
                    MonthlyParameter <decimal> parameter1 = null, parameter2 = null;

                    if (cf.Filter.Parameter != null)
                    {
                        parameter1 = new MonthlyParameter <decimal>();

                        parameter1.Id            = cf.Filter.Parameter.ParameterId;
                        parameter1.Name          = cf.Filter.Parameter.Name;
                        parameter1.Description   = cf.Filter.Description;
                        parameter1.FixedValue    = cf.Filter.Parameter.FixedValue;
                        parameter1.ParameterType = (FromDisney.ParameterType)cf.Filter.Parameter.ParameterTypeId;
                    }

                    if (cf.Filter.Parameter1 != null)
                    {
                        parameter2 = new MonthlyParameter <decimal>()
                        {
                            Id            = cf.Filter.Parameter1.ParameterId,
                            Name          = cf.Filter.Parameter1.Name,
                            FixedValue    = cf.Filter.Parameter1.FixedValue,
                            ParameterType = (FromDisney.ParameterType)cf.Filter.Parameter1.ParameterTypeId
                        }
                    }
                    ;

                    if (parameter1 != null && parameter2 != null)
                    {
                        IFIlter <bool> filter = new Filter <decimal, bool>
                        {
                            Operation   = new Operation(cf.Filter.Operation),
                            Description = cf.Filter.Description,
                            Sequence    = cf.Sequence,
                            Connector   = new Operation(cf.Connector),
                            Name        = cf.Filter.Title,
                            Id          = cf.FilterId,
                            Parameter1  = parameter1,
                            Parameter2  = parameter2,
                            FilterType  = cf.Filter.FilterType.FilterTypeId
                        };

                        concept.AddFilter(filter);
                    }
                }
            }

            return(concept);
        }