public void CircularReference() { Models models = new Models(); Model model1 = new Model() { Id = "theModel1" }; Model model2 = new Model() { Id = "theModel2" }; models.Data[model1.Id] = model1; models.Data[model2.Id] = model2; model1.SubTypes = new string[] { "theModel2" }; model2.SubTypes = new string[] { "theModel1" }; models.Validate(Violations); Assert.AreEqual(2, Violations.Count); Assert.AreEqual("SubTypes", Violations[0].Code); Assert.AreEqual(@"[""theModel1""].SubTypes[""theModel2""]", Violations[0].Context); Assert.AreEqual(Common.Swagger.Common.ViolationLevel.Error, Violations[0].ViolationLevel); Assert.AreEqual("SubTypes", Violations[1].Code); Assert.AreEqual(@"[""theModel2""].SubTypes[""theModel1""]", Violations[1].Context); Assert.AreEqual(Common.Swagger.Common.ViolationLevel.Error, Violations[1].ViolationLevel); }
public void ModelPropertiesIsNull() { Models models = new Models(); Model model = new Model() { Id = "theModel" }; model.Properties = null; models.Data["theModel"] = model; models.Validate(Violations); Assert.AreEqual(1, Violations.Count); AssertInvalidProperty("Properties", @"[""theModel""].Properties", Common.Swagger.Common.ViolationLevel.Error); }
public void SubtypesMegaDepth() { Models models = new Models(); // 1 -> 5 Model model1 = new Model() { Id = "theModel1" }; Model model5 = new Model() { Id = "theModel5" }; models.Data[model1.Id] = model1; models.Data[model5.Id] = model5; // 2 -> 4 -> 7 Model model2 = new Model() { Id = "theModel2" }; Model model4 = new Model() { Id = "theModel4" }; Model model7 = new Model() { Id = "theModel7" }; models.Data[model2.Id] = model2; models.Data[model4.Id] = model4; models.Data[model7.Id] = model7; model2.SubTypes = new string[] { "theModel4" }; model4.SubTypes = new string[] { "theModel7" }; // 3 -> 6 -> 8 -> 9 -> 6 Model model3 = new Model() { Id = "theModel3" }; Model model6 = new Model() { Id = "theModel6" }; Model model8 = new Model() { Id = "theModel8" }; Model model9 = new Model() { Id = "theModel9" }; models.Data[model3.Id] = model3; models.Data[model6.Id] = model6; models.Data[model8.Id] = model8; models.Data[model9.Id] = model9; model3.SubTypes = new string[] { "theModel6" }; model6.SubTypes = new string[] { "theModel8" }; model8.SubTypes = new string[] { "theModel9" }; model9.SubTypes = new string[] { "theModel6" }; models.Validate(Violations); Assert.AreEqual(4, Violations.Count); Assert.IsTrue(Violations.All((f) => f.ViolationLevel == Common.Swagger.Common.ViolationLevel.Error)); Assert.IsTrue(Violations.All((f) => f.Code == "SubTypes")); Assert.AreEqual(@"[""theModel3""].SubTypes[""theModel6""]", Violations[0].Context); Assert.AreEqual(@"[""theModel6""].SubTypes[""theModel8""]", Violations[1].Context); Assert.AreEqual(@"[""theModel8""].SubTypes[""theModel9""]", Violations[2].Context); Assert.AreEqual(@"[""theModel9""].SubTypes[""theModel6""]", Violations[3].Context); }
public void SubTypeReferenceIsValid() { Models models = new Models(); Model model1 = new Model() { Id = "theModel1" }; Model model2 = new Model() { Id = "theModel2" }; models.Data[model1.Id] = model1; models.Data[model2.Id] = model2; model1.SubTypes = new string[] { "theModel2" }; models.Validate(Violations); Assert.AreEqual(0, Violations.Count); }
public void SubTypeIsSameCaseSensitive2() { Models models = new Models(); Model model1 = new Model() { Id = "theModel1" }; models.Data[model1.Id] = model1; model1.SubTypes = new string[] { "theMODEL1" }; models.Validate(Violations); AssertInvalidProperty("SubTypes", @"[""theModel1""].SubTypes[""theMODEL1""]", Common.Swagger.Common.ViolationLevel.Error); }
public void ModelPropertyRefValid() { Models models = new Models(); Model model1 = new Model() { Id = "theModel1" }; Model model2 = new Model() { Id = "theModel2" }; Property property = new Property() { Reference = "theModel2", Type = null, Format = null }; model1.Properties.Data["theProperty"] = property; models.Data["theModel1"] = model1; models.Data["theModel2"] = model2; models.Validate(Violations); Assert.AreEqual(0, Violations.Count); }
public void ModelPropertyRefInvalid() { Models models = new Models(); Model model1 = new Model() { Id = "theModel1" }; Model model2 = new Model() { Id = "theModel2" }; Property property = new Property() { Reference = "nonExistentModel", Type = null, Format = null }; model1.Properties.Data["theProperty"] = property; models.Data["theModel1"] = model1; models.Data["theModel2"] = model2; models.Validate(Violations); AssertInvalidProperty("Reference", @"[""theModel1""].Properties[""theProperty""].Reference", Common.Swagger.Common.ViolationLevel.Error); }
public void ModelPropertyItemsIsInvalid() { Models models = new Models(); Model model = new Model() { Id = "theModel" }; Property property = new Property(); Items items = new Items() { Type = "invalidType", Format = "invalidFormat" }; property.Items = items; model.Properties.Data["theProperty"] = property; models.Data["theModel"] = model; models.Validate(Violations); Assert.AreEqual(1, Violations.Count); AssertInvalidProperty("Type", @"[""theModel""].Properties[""theProperty""].Items.Type", Common.Swagger.Common.ViolationLevel.Error); }