github.com/CiscoM31/godata@v1.0.10/metadata_model_test.go (about) 1 package godata 2 3 import ( 4 "testing" 5 ) 6 7 func TestSimpleMetadata(t *testing.T) { 8 9 entity1 := GoDataEntityType{ 10 Name: "TestEntity1", 11 Key: &GoDataKey{PropertyRef: &GoDataPropertyRef{Name: "Id"}}, 12 Properties: []*GoDataProperty{ 13 {Name: "Id", Type: "Edm.Int32"}, 14 {Name: "FirstName", Type: "Edm.String"}, 15 {Name: "LastName", Type: "Edm.String"}, 16 }, 17 } 18 19 schema := GoDataSchema{ 20 Namespace: "TestSchema", 21 EntityTypes: []*GoDataEntityType{&entity1}, 22 } 23 24 services := GoDataServices{ 25 Schemas: []*GoDataSchema{&schema}, 26 } 27 28 root := GoDataMetadata{ 29 XMLNamespace: "http://docs.oasis-open.org/odata/ns/edmx", 30 Version: "4.0", 31 DataServices: &services, 32 } 33 34 expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 35 expected += "<edmx:Edmx xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\">\n" 36 expected += " <edmx:DataServices>\n" 37 expected += " <Schema Namespace=\"TestSchema\">\n" 38 expected += " <EntityType Name=\"TestEntity1\">\n" 39 expected += " <Key>\n" 40 expected += " <PropertyRef Name=\"Id\"></PropertyRef>\n" 41 expected += " </Key>\n" 42 expected += " <Property Name=\"Id\" Type=\"Edm.Int32\"></Property>\n" 43 expected += " <Property Name=\"FirstName\" Type=\"Edm.String\"></Property>\n" 44 expected += " <Property Name=\"LastName\" Type=\"Edm.String\"></Property>\n" 45 expected += " </EntityType>\n" 46 expected += " </Schema>\n" 47 expected += " </edmx:DataServices>\n" 48 expected += "</edmx:Edmx>" 49 50 actual, err := root.Bytes() 51 52 if err != nil { 53 t.Error(err) 54 } 55 56 if string(actual) != expected { 57 t.Error("Expected: \n"+expected, "\n\nGot: \n"+string(actual)) 58 } 59 }