public async Task RequestServicesCommandHandler_Handle_RecordsProcessed() { var availabilityService = new Mock <IAvailabilityService>(); availabilityService.Setup(e => e.Request(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new AvailabilityResponseModel(HttpStatusCode.OK, 22, "{}")); var availabilityProcessor = new AvailabilityProcessor(_availabilityRecordRepository, availabilityService.Object); var requestServicesCommandHandler = new RequestServicesCommandHandler(_availabilityContext, availabilityProcessor); var availabilityRecord = new AvailabilityRecord(Guid.NewGuid(), "test name", "http://google.com", 200, null, 2); await _availabilityRecordRepository.AddAsync(availabilityRecord, CancellationToken.None); await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(CancellationToken.None); await requestServicesCommandHandler.Handle(new RequestServicesCommand(), CancellationToken.None); availabilityRecord = await _availabilityRecordRepository .GetById(availabilityRecord.Id, CancellationToken.None) .ConfigureAwait(false); Assert.Single(availabilityRecord.AvailabilityLogs); Assert.Equal(200, availabilityRecord.AvailabilityLogs.First().StatusCode); Assert.Equal(22, availabilityRecord.AvailabilityLogs.First().ResponseTime); Assert.Equal("{}", availabilityRecord.AvailabilityLogs.First().Body); }
public async Task AvailabilityProcessor_ProcessAvailabilityRecord_RecordProcessed() { var availabilityRecord = new AvailabilityRecord(Guid.NewGuid(), "test name", "http://google.com/", 200, null, 2); await _availabilityRecordRepository.AddAsync(availabilityRecord, CancellationToken.None); await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(CancellationToken.None); var availabilityService = new Mock <IAvailabilityService>(); availabilityService.Setup(e => e.Request(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new AvailabilityResponseModel(HttpStatusCode.OK, 65, "{}")); var availabilityProcessor = new AvailabilityProcessor(_availabilityRecordRepository, availabilityService.Object); await availabilityProcessor.ProcessAvailabilityRecord(availabilityRecord.Id, CancellationToken.None); availabilityRecord = await _availabilityRecordRepository.GetById(availabilityRecord.Id, CancellationToken.None); Assert.Single(availabilityRecord.AvailabilityLogs); Assert.Equal(200, availabilityRecord.AvailabilityLogs.First().StatusCode); Assert.Equal("{}", availabilityRecord.AvailabilityLogs.First().Body); Assert.Equal(65, availabilityRecord.AvailabilityLogs.First().ResponseTime); }