public HttpResponseMessage Post(HttpRequestMessage request, ApiKeyDto dto) { try { var newApiKey = ApiKeyService.Create(dto); return(request.CreateResponse(HttpStatusCode.Created, newApiKey)); } catch (Exception) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }
public async void Create() { var mock = new ServiceMockFacade <IApiKeyRepository>(); var model = new ApiApiKeyRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ApiKey>())).Returns(Task.FromResult(new ApiKey())); var service = new ApiKeyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLApiKeyMapperMock, mock.DALMapperMockFactory.DALApiKeyMapperMock); CreateResponse <ApiApiKeyResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiApiKeyRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ApiKey>())); }