コード例 #1
0
        public async Task DeleteAvailabilityRecordCommandHandler_Handle_AvailabilityRecordDeleted()
        {
            var accountId          = Guid.NewGuid();
            var availabilityRecord = new AvailabilityRecord(accountId,
                                                            "test",
                                                            "http://google.com/",
                                                            200,
                                                            "{}",
                                                            2);

            await _availabilityRecordRepository.AddAsync(availabilityRecord, CancellationToken.None);

            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(CancellationToken.None);

            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, accountId.ToString()));
            var claimsPrincipal = new ClaimsPrincipal();

            claimsPrincipal.AddIdentity(claimsIdentity);

            var deleteAvailabilityRecordCommandHandler = new DeleteAvailabilityRecordCommandHandler(_availabilityRecordRepository,
                                                                                                    _claimConverter);

            await deleteAvailabilityRecordCommandHandler.Handle(new DeleteAvailabilityRecordCommand(availabilityRecord.Id, claimsPrincipal),
                                                                CancellationToken.None).ConfigureAwait(false);

            Assert.Empty(await _availabilityContext.AvailabilityRecords.ToListAsync(CancellationToken.None));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public async Task UpdateAvailabilityRecordCommandHandler_Handle_AvailabilityRecordUpdated()
        {
            var accountId = Guid.NewGuid();

            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, accountId.ToString()));
            var claimsPrincipal = new ClaimsPrincipal();

            claimsPrincipal.AddIdentity(claimsIdentity);

            var createAvailabilityRecordCommandHandler = new UpdateAvailabilityRecordCommandHandler(_availabilityRecordRepository,
                                                                                                    _claimConverter);

            var record = new AvailabilityRecord(accountId,
                                                "name",
                                                "url",
                                                200,
                                                "{}",
                                                1);

            await _availabilityRecordRepository.AddAsync(record,
                                                         CancellationToken.None);

            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(CancellationToken.None);

            await createAvailabilityRecordCommandHandler.Handle(new UpdateAvailabilityRecordCommand(claimsPrincipal,
                                                                                                    record.Id,
                                                                                                    "test name",
                                                                                                    "http://google.com/",
                                                                                                    200,
                                                                                                    "{}",
                                                                                                    12), CancellationToken.None).ConfigureAwait(false);

            Assert.Equal(accountId, record.AccountId);
            Assert.Equal("test name", record.Name);
            Assert.Equal("http://google.com/", record.Url);
            Assert.Equal(200, record.ExpectedStatusCode);
            Assert.Equal("{}", record.ExpectedResponse);
            Assert.Equal(12, record.LogLifetimeThresholdInHours);
        }
コード例 #5
0
        public async Task Handle(CreateAvailabilityRecordCommand notification, CancellationToken cancellationToken)
        {
            var accountId = _claimConverter.GetAccountId(notification.ClaimsPrincipal);

            var availabilityRecord = new AvailabilityRecord(accountId,
                                                            notification.Name,
                                                            notification.Url,
                                                            notification.ExpectedStatusCode,
                                                            notification.ExpectedResponse,
                                                            notification.LogLifetimeThresholdInHours);

            await _availabilityRecordRepository.AddAsync(availabilityRecord, cancellationToken)
            .ConfigureAwait(false);

            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
        }
コード例 #6
0
        public async Task GetAvailabilityRecordsCommandHandler_Handle_AvailabilityRecordsReturned()
        {
            var accountId = Guid.NewGuid();

            var availabilityRecord = new AvailabilityRecord(accountId,
                                                            "test name",
                                                            "http://google.com/",
                                                            200,
                                                            "{}",
                                                            2);

            availabilityRecord.AppendLog(200, "{}", 66);

            await _availabilityRecordRepository.AddAsync(availabilityRecord, CancellationToken.None)
            .ConfigureAwait(false);

            await _availabilityRecordRepository.UnitOfWork.SaveEntitiesAsync(CancellationToken.None);

            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, accountId.ToString()));
            var claimsPrincipal = new ClaimsPrincipal();

            claimsPrincipal.AddIdentity(claimsIdentity);

            var configuration = new MapperConfiguration(cfg => {
                cfg.AddProfile <DefaultDomainMapping>();
            });

            var mapper = configuration.CreateMapper();

            var getAvailabilityRecordsCommandHandler = new GetAvailabilityListItemsCommandHandler(_availabilityRecordRepository,
                                                                                                  _claimConverter,
                                                                                                  mapper);

            var availabilityListItemDtos = await getAvailabilityRecordsCommandHandler
                                           .Handle(new GetAvailabilityListItemsCommand(claimsPrincipal), CancellationToken.None)
                                           .ConfigureAwait(false);

            Assert.Equal(availabilityRecord.Id, availabilityListItemDtos.First().Id);
            Assert.Equal("http://google.com/", availabilityListItemDtos.First().Url);
            Assert.Equal("test name", availabilityListItemDtos.First().Name);
            Assert.Equal("ST_OK", availabilityListItemDtos.First().Status);
        }