Ejemplo n.º 1
0
        public void BecauseEnumOutOfRange()
        {
            // ARRANGE
            ContractorType unsupportedEnumValue = 0;

            // ACT
            var exception = Fail.BecauseEnumOutOfRange(unsupportedEnumValue);

            // ASSERT
            Assert.That(exception.Message, Is.EqualTo("Unsupported enum value: 0 (ContractorType)"));
        }
        public string GetName()
        {
            switch (this.Type)
            {
            case ContractorType.Company:
                return(this.CompanyName);

            case ContractorType.Person:
                return(this.FirstName + " " + this.LastName);

            default:
                throw Fail.BecauseEnumOutOfRange(this.Type);
            }
        }
        public override Result Assert(HttpOperation operation)
        {
            // TODO: Add non-nullable annotations to OrFail() - and other contract methods
            var current = operation.Response.Content.ReadJson().OrFail("response") !;

            if (_savedPattern == null)
            {
                SaveNewPattern(current);
                return(Ok);
            }

            JsonComparer patterns = new JsonComparer(_savedPattern, current, _ignore);

            if (patterns.AreEquivalent)
            {
                return(Ok);
            }

            switch (_mode)
            {
            case Mode.ContractCheck:
                // Always save new response (contract) when running in contract-check-mode
                SaveNewPattern(current);
                break;

            case Mode.Default:
                if (operation.TestServer.Repair)
                {
                    SaveNewPattern(current);
                    return(Ok);
                }

                break;

            default:
                throw Fail.BecauseEnumOutOfRange(_mode);
            }

            return(Failure($"Response is different than expected. \nVerify the differences: \n\n{patterns.GetDifferences()}"));
        }