Пример #1
0
        public void MessageShouldBeAValidContract(string contract, string message)
        {
            var testService = new TesterService();

            var result = testService.Execute(contract, message);

            result.IsMessageValid.ShouldBeTrue();
        }
Пример #2
0
        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.");
        }
Пример #3
0
        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.");
        }
Пример #4
0
        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.");
        }
Пример #5
0
            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);
            }
Пример #6
0
            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);
            }