public void BuildShouldApplyPercentageMarginForNumberOfPupils()
        {
            dynamic model = new ExpandoObject();

            model.NumberOfPupils = 100;

            var financeDoc = new Microsoft.Azure.Documents.Document();

            financeDoc.SetPropertyValue("No Pupils", 100d);
            financeDoc.SetPropertyValue("Overall Phase", "Secondary");
            financeDoc.SetPropertyValue("UrbanRuralInner", "Urban and city");
            financeDoc.SetPropertyValue("% of pupils eligible for FSM", 100);
            financeDoc.SetPropertyValue("% of pupils with SEN Statement", 100);
            financeDoc.SetPropertyValue("% of pupils with EAL", 100);
            financeDoc.SetPropertyValue("LA", 831);

            var benchmarkSchool = new SchoolViewModel(model);

            benchmarkSchool.HistoricalSchoolFinancialDataModels = new List <SchoolFinancialDataModel>();
            benchmarkSchool.HistoricalSchoolFinancialDataModels.Add(new SchoolFinancialDataModel("123", "2014-2015", financeDoc, SchoolFinancialType.Maintained));

            var builder = new BenchmarkCriteriaBuilderService();

            var criteria = builder.BuildFromSimpleComparisonCriteria(benchmarkSchool.HistoricalSchoolFinancialDataModels.Last(), true, true, true, true, 5);

            Assert.AreEqual(financeDoc.GetPropertyValue <double>("No Pupils") * 0.85, criteria.MinNoPupil);
            Assert.AreEqual(financeDoc.GetPropertyValue <double>("No Pupils") * 1.15, criteria.MaxNoPupil);
        }
        public async Task <CourseAudit> Audit(ILogger log, Document auditee)
        {
            Throw.IfNull(auditee, nameof(auditee));
            Throw.IfNull(auditee.GetPropertyValue <Guid>("id"), "Document id");
            CourseAudit persisted;

            Guid id = auditee.GetPropertyValue <Guid>("id");

            try
            {
                log.LogInformation($"Writing audit for course { id }");
                using (var client = _cosmosDbHelper.GetClient())
                {
                    await _cosmosDbHelper.CreateDocumentCollectionIfNotExistsAsync(client, _settings.AuditCollectionId);

                    Document doc = await _cosmosDbHelper.CreateDocumentAsync(client, _settings.AuditCollectionId,
                                                                             new CourseAudit()
                    {
                        id          = Guid.NewGuid(),
                        Collection  = _settings.CoursesCollectionId,
                        DocumentId  = id.ToString(),
                        UpdatedBy   = auditee.GetPropertyValue <string>("UpdatedBy") ?? auditee.GetPropertyValue <string>("CreatedBy"),
                        UpdatedDate = auditee.GetPropertyValue <DateTime?>("UpdatedDate") ?? DateTime.Now,
                        Document    = auditee
                    });

                    persisted = _cosmosDbHelper.DocumentTo <CourseAudit>(doc);
                }
                return(persisted);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }