Example #1
0
        public void ShouldFailValidationForArrayTypeWithLessThanMinItems()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Array", new SchemaObject
                  {
                      Type  = "Array",
                      Items = new SchemaObject()
                      {
                          Type = "Integer"
                      },
                      MinItems = 2
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Array", "[\"1\"]" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("The Items array for Array does not have the minimum number (2) of items required.");
        }
Example #2
0
        public void ShouldFailValidationForNonArrayType()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "TestArray", new SchemaObject
                  {
                      Type  = "Array",
                      Items = new SchemaObject()
                      {
                          Type = "Integer"
                      },
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "TestArray", "123" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("\"123\" does not match the required data type for TestArray (array).");
        }
Example #3
0
        public void ShouldFailValidationForArrayTypeWithIncorrectItemType(string dataType, string format, string itemString)
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Array", new SchemaObject
                  {
                      Type  = "Array",
                      Items = new SchemaObject
                      {
                          Type   = dataType,
                          Format = format
                      }
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Array", $"[\"{itemString}\"]" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe($"An item in the Items array for Array does not match the required data type ({format ?? dataType}).");
        }
Example #4
0
        public void ShouldValidateArrayType()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Array", new SchemaObject
                  {
                      Type  = "Array",
                      Items = new SchemaObject()
                      {
                          Type = "Integer"
                      }
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Array", "[\"134435\"]" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #5
0
        public void AreAllElementsCorrectDataTypeShouldReturnInvalidContract()
        {
            var contractDictionary = SampleContractDictionary();

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Name", "123" },
                { "Age", "NotANumber" },
                { "BigNumber", "NotANumber" },
                { "Id", "" },
                { "Birthday", "" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors.ShouldBe(new[]
            {
                "\"NotANumber\" does not match the required data type for Age (Integer).",
                "\"NotANumber\" does not match the required data type for BigNumber (Integer).",
                "\"\" does not match the required format for Id (Guid)."
            });
        }
Example #6
0
        public void AreAllElementsCorrectDataTypeShouldReturnValidContract()
        {
            var contractDictionary = SampleContractDictionary();

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Name", "Robert" },
                { "Age", "31" },
                { "BigNumber", "1000000" },
                { "Id", "a21b2109-bd23-4205-ba53-b8df0fdd36bf" },
                { "Birthday", "2019-07-23" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #7
0
        public void ShouldFailValidationForNonNumberType()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Number", new SchemaObject
                  {
                      Type = "Number"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Number", "Not a number" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse("\"Not a number\" does not match the required data type for Number (Number).");
        }
Example #8
0
        public void PropertyNameShouldBeCaseInsensitive()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Id", new SchemaObject
                  {
                      Type = "String"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "ID", "testId" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #9
0
        public void ShouldNotFailValidationIfSchemaNotFound()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "FirstName", new SchemaObject
                  {
                      Type = "String"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "LastName", "Lastname" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #10
0
        public void ShouldValidateObjectType()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Object", new SchemaObject
                  {
                      Type = "Object"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Object", new object() }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #11
0
        public void ShouldValidateGuidFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Id", new SchemaObject
                  {
                      Reference = "#/Guid",
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Id", "01234567-abcd-0123-abcd-0123456789ab" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #12
0
        public void ShouldValidateDateTimeFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Timestamp", new SchemaObject
                  {
                      Type   = "String",
                      Format = "date-time"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Timestamp", "1/1/2019" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #13
0
        public void ShouldFailValidationIfSchemaNotFound()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "FirstName", new SchemaObject
                  {
                      Type = "String"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "LastName", "Lastname" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("The schema for \"LastName\" was not found in the contract definition.");
        }
Example #14
0
        public void ShouldFailValidationForArrayTypeWithoutItems()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Array", new SchemaObject
                  {
                      Type = "Array"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Array", "[\"1\",\"2\",\"3\"]" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("\"Array\" does not have the required property(Items) for type(Array).");
        }
Example #15
0
        public void ShouldFailValidationForNonObjectType()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Object", new SchemaObject
                  {
                      Type = "Object"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Object", "not an object" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("\"not an object\" does not match the required data type for Object (Object).");
        }
Example #16
0
        public void ShouldFailValidationForGuidFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Id", new SchemaObject
                  {
                      Reference = "Guid",
                      Type      = "String"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Id", "This isn't a guid" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse("\"This isn't a guid\" does not match the required format for Id (Guid).");
        }
Example #17
0
        public void ShouldValidateInt64Format()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Integer", new SchemaObject
                  {
                      Type   = "Integer",
                      Format = "int64"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Integer", "2150000000" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #18
0
        public void ShouldFailValidationForDateTimeFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Timestamp", new SchemaObject
                  {
                      Type   = "String",
                      Format = "date-time"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Timestamp", "Not a datetime" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse("\"Not a datetime\" does not match the required format for Timestamp (DateTime).");
        }
Example #19
0
        public void ShouldFailValidationForNonInt32Format()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Integer", new SchemaObject
                  {
                      Type   = "Integer",
                      Format = "int32"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Integer", "2150000000" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse("\"2150000000\" does not match the required format for Integer (Int32).");
        }
Example #20
0
        public void ShouldFailValidationForNonFloatFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Number", new SchemaObject
                  {
                      Type   = "Number",
                      Format = "float"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Number", double.MinValue }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse("\"123456789012.34567\" does not match the required format for Number (Float).");
        }
Example #21
0
        public void ShouldValidateDoubleFormat()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                { "Number", new SchemaObject
                  {
                      Type   = "Number",
                      Format = "double"
                  } }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "Number", "123456789012.34567" }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeTrue();
        }
Example #22
0
        public void ShouldFailValidationWhenMissingNestedProperty()
        {
            var contractDictionary = new CaseInsensitiveDictionary <SchemaObject>
            {
                {
                    "User", new SchemaObject()
                    {
                        Type       = "Object",
                        Properties = new CaseInsensitiveDictionary <SchemaObject>
                        {
                            { "FirstName", new SchemaObject {
                                  Type = "String"
                              } },
                            { "LastName", new SchemaObject {
                                  Type = "String"
                              } }
                        }
                    }
                }
            };

            var messageKeyDictionary = new CaseInsensitiveDictionary <object>
            {
                { "User", new CaseInsensitiveDictionary <object>
                  {
                      { "LastName", new SchemaObject {
                            Type = "String"
                        } }
                  } }
            };

            var testerService = new TesterService();

            var result = testerService.DoAllMessageValuesMatchDataTypes(messageKeyDictionary, contractDictionary);

            result.IsMessageValid.ShouldBeFalse();
            result.MessageErrors[0].ShouldBe("The value for field \"User-->FirstName\" was not found.");
        }