public async void GetApiKeyQueryHandler_should_return_apikey_by_key() { // Arrange var apiKey = Builder <ApiKey> .CreateNew() .With(s => s.Key = "68869c32-d971-40f0-8b12-7392a153cd94") .With(s => s.Owner = "Administration") .With(s => s.Id = "12345") .With(s => s.Created = new DateTime(2021, 2, 3)) .Build(); A.CallTo(() => _mongoDBService.GetApiKeyAsync("68869c32-d971-40f0-8b12-7392a153cd94")).Returns(apiKey); var command = new GetApiKeyQuery("68869c32-d971-40f0-8b12-7392a153cd94"); // Act var result = await _getApiKeyQueryHandler.Handle(command, default); // Assert A.CallTo(() => _mongoDBService.GetApiKeyAsync("68869c32-d971-40f0-8b12-7392a153cd94")).MustHaveHappenedOnceExactly(); Assert.Equal("68869c32-d971-40f0-8b12-7392a153cd94", result.Key); }
public async Task <ApiKeyDto> Handle(GetApiKeyQuery request, CancellationToken cancellationToken) { var result = await _mongoDBService.GetApiKeyAsync(request.Key); return(_mapper.Map <ApiKeyDto>(result)); }