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