Пример #1
0
        public async Task Handle_WhenExceptionIsThrown_ShouldLogError()
        {
            var mockContext = new Mock <VoteMonitorContext>(_dbContextOptions);

            mockContext.Setup(m => m.PollingStations).Throws(new Exception());
            var sut = new GetPollingStationsHandler(mockContext.Object, new Mapper(_mapperConfiguration), _mockLogger.Object);

            await Record.ExceptionAsync(async() => await sut.Handle(new GetPollingStations(), new CancellationToken()));

            _mockLogger.Verify(x => x.Log(
                                   LogLevel.Error,
                                   It.IsAny <EventId>(),
                                   It.Is <It.IsAnyType>((v, t) => true),
                                   It.IsAny <Exception>(),
                                   It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once);
        }
Пример #2
0
        public async Task Handle_WithDefaultPage_ReturnsFirstPageResults()
        {
            SetupContextWithPollingStations(new List <Entities.PollingStation>
            {
                new PollingStationBuilder().WithId(1).Build()
            });

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new GetPollingStationsHandler(context, new Mapper(_mapperConfiguration), _mockLogger.Object);

                var getPollingStations = new GetPollingStations
                {
                    PageSize = 10
                };
                var result = await sut.Handle(getPollingStations, new CancellationToken());

                result.Count().Should().Be(1);
                result.First().Id.Should().Be(1);
            }
        }