public void Handler_returns_list_of_engagements()
        {
            var request = new GetEngagementsRequest {
                SinceEventId = 0, PageSize = 1000, PageNumber = 1
            };
            var engagements = _handler.Handle(request, new CancellationToken()).Result;

            engagements.Should().BeNullOrEmpty();
        }
コード例 #2
0
        public void Number_Of_Active_Returned_Records_As_Expected()
        {
            var request = new GetEngagementsRequest {
                SinceEventId = 0, PageSize = 1000, PageNumber = 1
            };

            _actualEngagements = _repository.GetEngagements(request).Result.ToList();
            Assert.AreEqual(3, _actualEngagements.Where(x => x.Event == MapEventDescriptionToStatus(OrganisationStatus.Active)).ToList().Count);
        }
コード例 #3
0
        public void Total_Number_Of_Returned_Records_As_Expected()
        {
            var request = new GetEngagementsRequest {
                SinceEventId = 0, PageSize = 1000, PageNumber = 1
            };

            _actualEngagements = _repository.GetEngagements(request).Result.ToList();
            Assert.AreEqual(6, _actualEngagements.Count);
        }
コード例 #4
0
        public async Task <IActionResult> GetEngagements(long sinceEventId = 0, int pageSize = 1000, int pageNumber = 1)
        {
            _logger.LogInformation($"Processing Organisation-GetEngagements, sinceEventId={sinceEventId}, pageSize={pageSize}, pageNumber={pageNumber}");

            var request = new GetEngagementsRequest {
                SinceEventId = sinceEventId, PageSize = pageSize, PageNumber = pageNumber
            };

            return(Ok(await _mediator.Send(request)));
        }
 public async Task <IEnumerable <Engagement> > Handle(GetEngagementsRequest request, CancellationToken cancellationToken)
 {
     try
     {
         return(await _repository.GetEngagements(request));
     }
     catch (Exception ex)
     {
         _logger.LogError("Unable to retrieve list of engagements", ex);
         throw new ApplicationException(ex.Message);
     }
 }
        public void Handler_returns_exception_from_repository()
        {
            var request = new GetEngagementsRequest {
                SinceEventId = 0, PageSize = 1000, PageNumber = 1
            };

            _repository.Setup(x => x.GetEngagements(request))
            .Throws(new Exception("Unit test exception"));

            Func <Task> result = async() => await
                                 _handler.Handle(request, new CancellationToken());

            result.Should().Throw <ApplicationException>();
        }
コード例 #7
0
        public async Task <IEnumerable <Engagement> > GetEngagements(GetEngagementsRequest request)
        {
            using (var connection = _dbConnectionHelper.GetDatabaseConnection())
            {
                var sqlIfPaginated = request.SinceEventId.Equals(0) ? string.Empty : $@" where ose.Id >= @SinceEventId
                                            order by ose.Id
                                            OFFSET ((@PageNumber - 1) * @PageSize) rows
                                            fetch next @PageSize rows ONLY";

                var sql = $@"select ose.ID, ose.providerId, ose.CreatedOn, isnull(os.EventDescription, 'UNKNOWN') as Event
	                                        from OrganisationStatusEvent ose left join organisationStatus os
	                                        on os.Id = ose.OrganisationStatusId"     + sqlIfPaginated;
                return(await connection.QueryAsync <Engagement>(sql, new { request.SinceEventId, request.PageSize, request.PageNumber }));
            }
        }
        public void Handler_paged_returns_list_of_engagements(long sinceEventId = 0, int pageSize = 1000, int pageNumber = 1)
        {
            _logger     = new Mock <ILogger <GetEngagementsHandler> >();
            _repository = new Mock <IOrganisationRepository>();

            var engagementsDummy = new List <Engagement>
            {
                new Engagement {
                    ProviderId = 11111111, Event = "INITIATED", CreatedOn = DateTime.Today
                },
                new Engagement {
                    ProviderId = 11111112, Event = "INITIATED", CreatedOn = DateTime.Today.AddDays(-1)
                },
                new Engagement {
                    ProviderId = 11111113, Event = "INITIATED", CreatedOn = DateTime.Today.AddDays(-2)
                },
                new Engagement {
                    ProviderId = 11111114, Event = "REMOVED", CreatedOn = DateTime.Today.AddDays(-3)
                },
                new Engagement {
                    ProviderId = 11111115, Event = "ACTIVE", CreatedOn = DateTime.Today.AddDays(-4)
                },
                new Engagement {
                    ProviderId = 11111116, Event = "ACTIVENOSTARTS", CreatedOn = DateTime.Today.AddDays(-5)
                }
            };

            var request = new GetEngagementsRequest {
                SinceEventId = sinceEventId, PageSize = pageSize, PageNumber = pageNumber
            };

            _repository.Setup(x => x.GetEngagements(request)).ReturnsAsync(engagementsDummy);
            _handler = new GetEngagementsHandler(_repository.Object, _logger.Object);

            var engagementsActual = _handler.Handle(request, new CancellationToken()).Result;

            engagementsActual.Should().NotBeNullOrEmpty();
        }
        public void Before_each_test()
        {
            _logger     = new Mock <ILogger <GetEngagementsHandler> >();
            _repository = new Mock <IOrganisationRepository>();
            var engagements = new List <Engagement>
            {
                new Engagement {
                    ProviderId = 11111111, Event = "INITIATED", CreatedOn = DateTime.Today
                },
                new Engagement {
                    ProviderId = 11111112, Event = "INITIATED", CreatedOn = DateTime.Today.AddDays(-1)
                },
                new Engagement {
                    ProviderId = 11111113, Event = "INITIATED", CreatedOn = DateTime.Today.AddDays(-2)
                }
            };
            var request = new GetEngagementsRequest {
                SinceEventId = 0, PageSize = 1000, PageNumber = 1
            };

            _repository.Setup(x => x.GetEngagements(request)).ReturnsAsync(engagements);
            _handler = new GetEngagementsHandler(_repository.Object, _logger.Object);
        }