public void TransformValueTypeValidTest()
        {
            var analyzer = new AnalyticalObject <ValueTypeTest>();

            analyzer.Property(p => p.x).HasTransformation(o => o + 1);
            var popRs2 = new PopulationResult(new Dictionary <string, object>()
            {
                ["valuetypetest_x"] = 2
            }, analyzer.TypeMap);

            Assert.AreEqual((int)popRs2["valuetypetest_x"], 3);
        }
        public void TransformationCastTest()
        {
            var analyzer = new AnalyticalObject <ValueTypeTest>();

            analyzer.Property(p => p.x).HasTransformation <string>(o => $"|{o}|");

            var popRs = new PopulationResult(new Dictionary <string, object>()
            {
                ["valuetypetest_x"] = 1
            }, analyzer.TypeMap);

            Assert.AreEqual(popRs["valuetypetest_x"], "|1|");
        }
        public async Task TransformConcatenationTest()
        {
            var analyzer = new AnalyticalObject <ValueTypeTest>();

            analyzer.Property(u => u.y).HasTransformation(o => o + "5");

            PopulationResult rs = new PopulationResult(new Dictionary <string, object>()
            {
                ["valuetypetest_y"] = "4"
            }, analyzer.TypeMap);

            Assert.AreEqual(rs["valuetypetest_y"], "45");
        }
        public void TransformationFromMasterListTest()
        {
            FluentOlapConfiguration.TransformationsMasterList.AddTransformation <int, string>("Surround", o => $"|{o}|");

            var analyzer = new AnalyticalObject <ValueTypeTest>();

            analyzer.Property(p => p.x).HasTransformation("Surround");
            var popRs = new PopulationResult(new Dictionary <string, object>()
            {
                ["valuetypetest_x"] = 1
            }, analyzer.TypeMap);

            Assert.AreEqual(popRs["valuetypetest_x"], "|1|");
        }
        public void TransformationShadowPropertyTest()
        {
            var analyzer      = new AnalyticalObject <ValueTypeTest>();
            var innerAnalyzer = new AnalyticalObject <ValueTypeTestInner>();

            innerAnalyzer.Property(x => x.z).HasTransformation(o => o + 2);
            analyzer.Property("shadow", innerAnalyzer);

            var popRs = new PopulationResult(new Dictionary <string, object>()
            {
                ["valuetypetestinner_z"] = 1
            }, analyzer.TypeMap);

            Assert.AreEqual(popRs["valuetypetestinner_z"], 3);
        }
        public void TransformationValueTypeNullTest()
        {
            var analyzer = new AnalyticalObject <ValueTypeTest>();

            analyzer.Property(p => p.x).HasTransformation(o => o + 1);
            try
            {
                var popRs = new PopulationResult(new Dictionary <string, object>()
                {
                    ["valuetypetest_x"] = null
                }, analyzer.TypeMap);
            }
            catch (InvalidOperationException e)
            {
            }
        }
Example #7
0
        public static async Task <PopulationResultCollection> CollectData <T>(AnalyticalObject <T> focusedObject,
                                                                              IServiceInput serviceInput)
        {
            if (focusedObject.ServiceName == null)
            {
                throw new Exception("Root analyzer object must have a service defined.");
            }

            if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(focusedObject.ServiceName))
            {
                throw new Exception($"Service {focusedObject.ServiceName} not defined.");
            }

            IService <IServiceInput, IServiceOutput> focusedService = FluentOlapConfiguration.ServiceDefinitions[focusedObject.ServiceName];
            PopulationResultCollection results = new PopulationResultCollection();

            PopulationResult rootResult = await CallService(focusedService, serviceInput);

            results.Add(rootResult);

            foreach (var expandable in focusedObject.ExpandableChildren)
            {
                if (expandable.Value.ServiceName == null)
                {
                    throw new Exception("Child analyzer object must have a service defined.");
                }

                if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(expandable.Value.ServiceName))
                {
                    throw new Exception($"Service {expandable.Value.ServiceName} not defined.");
                }

                IService <IServiceInput, IServiceOutput> expandableService = FluentOlapConfiguration.ServiceDefinitions[expandable.Value.ServiceName];

                IServiceInput input = null;

                switch (expandableService.Type)
                {
                case ServiceType.HttpCall:
                    HttpService expandableHttpService       = expandableService as HttpService;
                    IDictionary <string, string> parameters = new Dictionary <string, string>();
                    foreach (string innerParam in expandableHttpService.GetRequiredParameters())
                    {
                        JToken parsedRoot = JToken.Parse(rootResult.Raw);
                        parameters.Add(innerParam, parsedRoot[innerParam].Value <string>());
                    }

                    input = new HttpServiceOptions
                    {
                        PrefixKey  = expandable.Value.NodeName,
                        Parameters = parameters
                    };

                    await expandableHttpService.InvokeAsync((HttpServiceOptions)input);

                    break;
                }

                results.Add(await CallService(expandableService, input));
            }

            return(results);
        }