public void Simple_TermDefinitions_WithEntityType_InSameNamespace_Should_Be_Generated_Together() { var model = new StubEdmModel() { new StubEdmEntityType("NS1", "Person") { new StubEdmStructuralProperty("Name") { Type = EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: null, isUnicode: true, isNullable: false) }, }, new StubTerm("NS1", "fooValueTerm") { Type = EdmCoreModel.Instance.GetInt32(true) }, new StubTerm("NS1", "barValueTerm") { Type = EdmCoreModel.Instance.GetString(false) }, }; XElement result = this.generator.GenerateDefinitionCsdl(EdmVersion.V40, model).Single(); string expected = @" <Schema Namespace='NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <EntityType Name='Person'> <Property Name='Name' Type='Edm.String' Nullable='false' /> </EntityType> <Term Name='fooValueTerm' Type='Edm.Int32' /> <Term Name='barValueTerm' Type='Edm.String' Nullable='false' /> </Schema>"; AssertHelper.AssertXElementEquals(expected, result); }
public void TermDefinitions_InMultipleNamespaces_Should_Be_Generated() { var model = new StubEdmModel() { new StubTerm("NS1", "fooValueTerm") { Type = EdmCoreModel.Instance.GetInt32(true) }, new StubTerm("NS2", "barValueTerm") { Type = EdmCoreModel.Instance.GetString(false) }, }; var fileContents = this.generator.GenerateDefinitionCsdl(EdmVersion.V40, model); Assert.AreEqual(2, fileContents.Count()); var result1 = fileContents.ElementAt(0); string expected1 = @" <Schema Namespace='NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Term Name='fooValueTerm' Type='Edm.Int32' /> </Schema>"; AssertHelper.AssertXElementEquals(expected1, result1); var result2 = fileContents.ElementAt(1); string expected2 = @" <Schema Namespace='NS2' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Term Name='barValueTerm' Type='Edm.String' Nullable='false' /> </Schema>"; AssertHelper.AssertXElementEquals(expected2, result2); }
public void ValidateKindsOfNone() { StubEdmModel model = new StubEdmModel(); EdmEntityContainer container = new EdmEntityContainer("namespace", "container"); model.Add(container); model.Add(new NoneKinds1("namespace", "badThing", container)); var type = new EdmEntityType("namespace", "type"); type.AddProperty(new NoneKinds2("namespace", "otherBadThing", EdmCoreModel.Instance.GetInt32(false), type)); model.Add(type); var expectedErrors = new EdmLibTestErrors() { { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.TypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.EntityContainerElementMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.SchemaElementMustNotHaveKindOfNone }, { "(namespace.type)", EdmErrorCode.KeyMissingOnEntityType }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.PrimitiveTypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.SchemaElementMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.TypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.PropertyMustNotHaveKindOfNone }, }; this.VerifySemanticValidation(model, expectedErrors); }
public void Initialize() { this.definitionModel = this.CreateDefinitionModel(); this.expectedModel = this.CreateApplicationModel(); this.actualModel = this.CreateApplicationModel(); this.comparer = new VocabularyModelComparer(); }
public void Annotations_On_NonEntityType_Should_Be_Generated() { var model = new StubEdmModel(); var entity = new StubEdmEntityType("NS1", "Person"); var vt = new StubTerm("NS1", "MyValueTerm") { Type = EdmCoreModel.Instance.GetString(true) }; var va1 = new StubVocabularyAnnotation() { Term = vt, Value = new StubStringConstantExpression("Great!!!") }; entity.AddVocabularyAnnotation(va1); model.Add(entity); var entitySet = new StubEdmEntitySet("personSet", null); var va2 = new StubVocabularyAnnotation() { Term = vt, Value = new StubStringConstantExpression("Aha!!!") }; entitySet.AddVocabularyAnnotation(va2); var container = new StubEdmEntityContainer("NS1", "myContainer") { entitySet }; var va3 = new StubVocabularyAnnotation() { Term = vt, Value = new StubStringConstantExpression("Huh??") }; container.AddVocabularyAnnotation(va3); model.Add(container); XElement result = this.generator.GenerateApplicationCsdl(EdmVersion.V40, model); string expected = @" <Schema Namespace='Application.NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Annotations Target='NS1.Person'> <Annotation Term='NS1.MyValueTerm' String='Great!!!' /> </Annotations> <Annotations Target='NS1.myContainer'> <Annotation Term='NS1.MyValueTerm' String='Huh??' /> </Annotations> <Annotations Target='NS1.myContainer/personSet'> <Annotation Term='NS1.MyValueTerm' String='Aha!!!' /> </Annotations> </Schema>"; AssertHelper.AssertXElementEquals(expected, result); }
private StubEdmModel CreateDefinitionModel() { var model = new StubEdmModel(); var barValueTerm = new StubValueTerm("", "bar") { Type = EdmCoreModel.Instance.GetInt32(true) }; model.Add(barValueTerm); var bazValueTerm = new StubValueTerm("", "baz") { Type = EdmCoreModel.Instance.GetString(true) }; model.Add(bazValueTerm); var p1 = new StubEdmStructuralProperty("p1") { Type = EdmCoreModel.Instance.GetString(true) }; var p2 = new StubEdmStructuralProperty("p2") { Type = EdmCoreModel.Instance.GetString(true) }; var foobazTypeTerm = new StubTypeTerm("", "foobaz") { p1, p2 }; model.Add(foobazTypeTerm); var p10 = new StubEdmStructuralProperty("p10") { Type = EdmCoreModel.Instance.GetString(true) }; var bazfooTypeTerm = new StubTypeTerm("", "bazfoo") { p10 }; model.Add(bazfooTypeTerm); return(model); }
public void Simple_TermDefinitions_WithEntityTypes_InDifferentNamespaces_Should_Be_Generated_Separately() { var model = new StubEdmModel() { new StubEdmEntityType("NS0", "Person") { new StubEdmStructuralProperty("Name") { Type = EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: null, isUnicode: true, isNullable: false) }, }, new StubTerm("NS1", "fooValueTerm") { Type = EdmCoreModel.Instance.GetInt32(true) }, new StubTerm("NS1", "barValueTerm") { Type = EdmCoreModel.Instance.GetString(false) }, }; var fileContents = this.generator.GenerateDefinitionCsdl(EdmVersion.V40, model); Assert.AreEqual(2, fileContents.Count()); var result1 = fileContents.ElementAt(0); string expected1 = @" <Schema Namespace='NS0' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <EntityType Name='Person'> <Property Name='Name' Type='Edm.String' Nullable='false' /> </EntityType> </Schema>"; AssertHelper.AssertXElementEquals(expected1, result1); var result2 = fileContents.ElementAt(1); string expected2 = @" <Schema Namespace='NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Term Name='fooValueTerm' Type='Edm.Int32' /> <Term Name='barValueTerm' Type='Edm.String' Nullable='false' /> </Schema>"; AssertHelper.AssertXElementEquals(expected2, result2); }
private StubEdmModel CreateApplicationModel() { var model = new StubEdmModel(); var valueTerm = new StubValueTerm("", "foo") { Type = EdmCoreModel.Instance.GetInt32(true) }; model.Add(valueTerm); var barValueTerm = this.definitionModel.SchemaElements.OfType <IEdmValueTerm>().FirstOrDefault(t => t.Name == "bar"); var valueAnnotation = new StubValueAnnotation() { Term = barValueTerm, Value = new StubStringConstantExpression("zzz") }; valueTerm.AddVocabularyAnnotation(valueAnnotation); return(model); }
public void Simple_TermDefinitions_Should_Be_Generated() { var model = new StubEdmModel() { new StubTerm("NS1", "fooValueTerm") { Type = EdmCoreModel.Instance.GetInt32(true) }, new StubTerm("NS1", "barValueTerm") { Type = EdmCoreModel.Instance.GetString(false) }, }; XElement result = this.generator.GenerateDefinitionCsdl(EdmVersion.V40, model).Single(); string expected = @" <Schema Namespace='NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Term Name='fooValueTerm' Type='Edm.Int32' /> <Term Name='barValueTerm' Type='Edm.String' Nullable='false' /> </Schema>"; AssertHelper.AssertXElementEquals(expected, result); }
public void Simple_VocabularyAnnotation_Should_Be_Generated() { var model = new StubEdmModel(); var entity = new StubEdmEntityType("NS1", "Person"); var vt = new StubTerm("NS1", "MyValueTerm") { Type = EdmCoreModel.Instance.GetString(true) }; var va1 = new StubVocabularyAnnotation() { Term = vt, Value = new StubStringConstantExpression("Great!!!") }; var va2 = new StubVocabularyAnnotation() { Term = vt, Qualifier = "phone", Value = new StubStringConstantExpression("Fabulous!!!") }; entity.AddVocabularyAnnotation(va1); entity.AddVocabularyAnnotation(va2); model.Add(entity); XElement result = this.generator.GenerateApplicationCsdl(EdmVersion.V40, model); string expected = @" <Schema Namespace='Application.NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'> <Annotations Target='NS1.Person'> <Annotation Term='NS1.MyValueTerm' String='Great!!!' /> <Annotation Term='NS1.MyValueTerm' Qualifier='phone' String='Fabulous!!!' /> </Annotations> </Schema>"; AssertHelper.AssertXElementEquals(expected, result); }