public void MessageShouldBeAValidContract(string contract, string message) { var testService = new TesterService(); var result = testService.Execute(contract, message); result.IsMessageValid.ShouldBeTrue(); }
public void ContractShouldHaveAValidReferenceDefinition(string contract, string message) { var testService = new TesterService(); var result = testService.Execute(contract, message); result.IsMessageValid.ShouldBeFalse(); result.MessageErrors[0].ShouldBe("Unable to test; reference definition is invalid."); }
public void ContractShouldHaveValidOpenAPISchema(string contract, string message) { var testService = new TesterService(); var result = testService.Execute(contract, message); result.IsMessageValid.ShouldBeFalse(); result.MessageErrors[0].ShouldBe("Unable to test; contract is not a valid OpenAPI schema."); }
public void MessageShouldNotBeInvalidJSON(string contract, string message) { var testService = new TesterService(); var result = testService.Execute(contract, message); result.IsMessageValid.ShouldBeFalse(); result.MessageErrors[0].ShouldBe("Message contains invalid JSON."); }
public async Task <Result> Handle(Command request, CancellationToken cancellationToken) { var contract = await _db.Contract.SingleAsync(x => x.Id == request.ContractId, cancellationToken); string warningMessage = null; var isValid = true; var message = JsonConvert.SerializeObject(request.Message); var result = new Result { Contract = _mapper.Map <ContractDto>(contract), TestMessage = message }; if (contract.DeprecationDate.HasValue) { if (contract.DeprecationDate <= DateTime.Today) { isValid = false; result.MessageErrors.Add("This contract has been deprecated. Please check for a new version."); } else { warningMessage = $"This contract will be deprecated on {contract.DeprecationDate}, please check for a new version."; } } if (isValid) { var testResult = _testerService.Execute(contract.ContractString, message, request.AllowSubset); if (!testResult.IsMessageValid) { isValid = false; } result.MessageErrors = testResult.MessageErrors; result.Warnings = testResult.Warnings; } result.IsValid = isValid; result.WarningMessage = warningMessage; return(result); }
public async Task <ViewModel> Handle(Command request, CancellationToken cancellationToken) { var contract = await _db.Contract.SingleAsync( x => x.Id == request.ContractId && x.VersionNumber == request.VersionNumber, cancellationToken); string warningMessage = null; var isValid = true; var result = _mapper.Map <ViewModel>(contract); result.TestMessage = request.SampleMessage; if (contract.DeprecationDate.HasValue) { if (contract.DeprecationDate <= DateTime.Today) { isValid = false; result.MessageErrors.Add("This contract has been deprecated. Please check for a new version."); } else { warningMessage = $"This contract will be deprecated on {contract.DeprecationDate}, please check for a new version."; } } if (isValid) { var testResult = _testerService.Execute(contract.ContractString, request.SampleMessage); if (!testResult.IsMessageValid) { isValid = false; } result.MessageErrors = testResult.MessageErrors; } result.WarningMessage = warningMessage; result.IsValid = isValid; return(result); }