public async Task SaveCommitmentStatistics(CommitmentsExternalModel statisticsModel, CommitmentsRdsModel rdsModel)
        {
            await WithConnection(async c =>
            {
                using (var transaction = c.BeginTransaction())
                {
                    try
                    {
                        await SaveStatistic(c, transaction, nameof(statisticsModel.ActiveApprenticeships),
                                            statisticsModel.ActiveApprenticeships,
                                            rdsModel.ActiveApprenticeships);

                        await SaveStatistic(c, transaction, nameof(statisticsModel.TotalApprenticeships),
                                            statisticsModel.TotalApprenticeships,
                                            rdsModel.TotalApprenticeships);

                        await SaveStatistic(c, transaction, nameof(statisticsModel.TotalCohorts),
                                            statisticsModel.TotalCohorts,
                                            rdsModel.TotalCohorts);

                        transaction.Commit();
                    }
                    catch (SqlException)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }

                return(0);
            });
        }
Exemple #2
0
        private CommitmentsExternalModel Map(ConsistencyStatistics model)
        {
            var externalModel = new CommitmentsExternalModel()
            {
                TotalApprenticeships  = model.TotalApprenticeships,
                TotalCohorts          = model.TotalCohorts,
                ActiveApprenticeships = model.ActiveApprenticeships
            };

            return(externalModel);
        }
Exemple #3
0
        private async Task <CommitmentsExternalModel> RetrieveCommitmentsStatisticsFromTheApi()
        {
            _log.Debug("Gathering statistics for the Commitments area of the system");
            CommitmentsExternalModel statistics = null;

            try
            {
                statistics = await _commitmentsStatisticsHandler.Handle();
            }
            catch (HttpRequestException httpRequestException)
            {
                _log.Error(httpRequestException, "Failed to retrieve commitment stats from the API");
            }

            return(statistics);
        }
        public async Task ThenSaveCommitmentsStatistics()
        {
            await SetupDatabase();

            var commitmentsExternalModel = new CommitmentsExternalModel()
            {
                TotalCohorts = 1, TotalApprenticeships = 1, ActiveApprenticeships = 1
            };

            CommitmentsStatisticsHandlerMock.Setup(x => x.Handle()).Returns(Task.FromResult(commitmentsExternalModel));

            await DAS.Data.Functions.Statistics.GetCommitmentStatisticsFunction.Run(null, Log, StatisticsService);

            var databaseAsExpected = TestHelper.ConditionMet(IsDatabaseInExpectedState, TimeSpan.FromSeconds(60));

            Assert.IsTrue(databaseAsExpected);
        }