Esempio n. 1
0
 public PoliceApiClient(IOptions <PoliceApiSettings> options, ILogger <PoliceApiClient> logger,
                        IPoliceHttpClient policeHttpClient)
 {
     _settings         = options.Value;
     _logger           = logger;
     _policeHttpClient = policeHttpClient;
 }
        public async Task ShouldFetchEventsAndReturnConvertedData()
        {
            //
            // Arrange
            //
            var restClientMock = new Mock <IPoliceHttpClient>();

            restClientMock.Setup(a => a.GetAsync("myurl")).ReturnsAsync(() => new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(Data)
            });

            var settings = new PoliceApiSettings
            {
                PoliceApiUrl = "myurl"
            };
            var logger  = new NullLogger <PoliceApiClient>();
            var options = Options.Create(settings);
            var client  = new PoliceApiClient(options, logger, restClientMock.Object);

            //
            // Act
            //
            var events = (await client.GetLatestEvents()).ToList();

            //
            // Assert
            //
            restClientMock.Verify(m => m.GetAsync("myurl"), Times.Once);
            Assert.Equal(2, events.Count);

            Assert.Equal(new DateTime(2021, 2, 6, 18, 24, 0), events[0].UtcDateTime);
            Assert.Equal("Stockholm", events[0].Location.Name);
            Assert.Equal(59.329324, events[0].Location.Lat);
            Assert.Equal(18.068581, events[0].Location.Lng);
            Assert.Equal("Bus, grov", events[0].Type);

            Assert.Equal(new DateTime(2021, 2, 6, 16, 24, 0), events[1].UtcDateTime);
            Assert.Equal("Örebro", events[1].Location.Name);
            Assert.Equal(59.329334, events[1].Location.Lat);
            Assert.Equal(18.068591, events[1].Location.Lng);
            Assert.Equal("Stöld", events[1].Type);
        }
Esempio n. 3
0
 public Worker(IOptions <PoliceApiSettings> options,
               IMediator mediator)
 {
     _settings = options.Value;
     _mediator = mediator;
 }