public static void ShouldOutputFullDemographicsAnalysis()
        {
            String input =
                "Name: Suzanne Martinez, Age: 39, Highest Level of Education: High School, Income: $45,000" + Environment.NewLine +
                "Name: Melissa Brownell, Age: 27, Highest Level of Education: College, Income: $70,000" + Environment.NewLine +
                "Name: Nathan Southern, Age: 73, Highest Level of Education: Grade School, Income: $33,000" + Environment.NewLine +
                "Name: Celeste Willis, Age: 46, Highest Level of Education: High School, Income: $60,000" + Environment.NewLine +
                "Name: Ashley Green, Age: 27, Highest Level of Education: College, Income: $100,000" + Environment.NewLine +
                "Name: Jennifer Coleman, Age: 35, Highest Level of Education: High School, Income: $75,000" + Environment.NewLine;


            var demographicsAnalysisInputStream  = new MemoryStream(Encoding.UTF8.GetBytes(input));
            var demographicsAnalysisOutputStream = new MemoryStream();

            DemographicsAnalyzer.PrintFullDemographicsAnalysis(demographicsAnalysisInputStream, demographicsAnalysisOutputStream);
            String demographicsAnalysisOutput = new StreamReader(demographicsAnalysisOutputStream).ReadFromBeginning();

            String expectedOutput =
                "Total Respondents: 6" + Environment.NewLine +
                "Average Age: 41.2" + Environment.NewLine +
                "Most Common Highest Level of Education: High School" + Environment.NewLine +
                "Median Income: $65,000.00" + Environment.NewLine +
                "Names of All Respondents: Melissa Brownell, Jennifer Coleman, Ashley Green, Suzanne Martinez, Nathan Southern, Celeste Willis" + Environment.NewLine;

            Assert.AreEqual(expectedOutput, demographicsAnalysisOutput);
        }
        public async Task <string> Run(
            [ServiceBusTrigger("crowd-analysis", "crowd-analyzer", Connection = "serviceBusConnection")] string request,
            ILogger log)
        {
            DateTime startTime = DateTime.UtcNow;

            log.LogInformation($"FUNC (CrowdAnalyzer): crowd-analysis topic triggered processing message: {request.Substring(0, 20)}");

            CamFrameAnalysis analysis = null;

            try
            {
                analysis = JsonConvert.DeserializeObject <CamFrameAnalysis>(request);

                // Only process if there are detected faces
                if (analysis.SimilarFaces == null && analysis.IdentifiedPersons == null)
                {
                    log.LogWarning($"FUNC (CrowdAnalyzer): starting crowd-analysis: found no faces in the analysis request");
                    return(null);
                }

                DemographicsAnalyzer demographics = new DemographicsAnalyzer(
                    analysis,
                    visitorRepo,
                    crowdDemographicsRepo,
                    identifiedVisitorRepo,
                    log);
                var isDemographicsUpdated = await demographics.UpdateDemographics();

                log.LogInformation($"FUNC (CrowdAnalyzer): finished processing with result: {JsonConvert.SerializeObject(demographics.Demographics)}");

                // If changes where made, publish changes to demographics-analysis topic
                if (isDemographicsUpdated)
                {
                    return(JsonConvert.SerializeObject(demographics.Demographics));
                }
            }
            catch (Exception e)
            {
                log.LogError($"FUNC (CrowdAnalyzer): Failed with error: {JsonConvert.SerializeObject(e.Message)}");
            }


            return(null);
        }
        public static void ShouldComputeMedianIncome()
        {
            Money medianIncome = DemographicsAnalyzer.ComputeMedianIncome(Persons);

            Assert.AreEqual(new Money(65000, "USD"), medianIncome);
        }
        public static void ShouldFindMostCommonHighestLevelOfEducation()
        {
            EducationLevel mostCommonHighestLevelOfEducation = DemographicsAnalyzer.FindMostCommonHighestLevelOfEducation(Persons);

            Assert.AreEqual(EducationLevel.HighSchool, mostCommonHighestLevelOfEducation);
        }
        public static void ShouldComputeAverageAgeOfAllPersons()
        {
            decimal averageAge = DemographicsAnalyzer.ComputeAverageAge(Persons);

            Assert.AreEqual(41.2, averageAge);
        }