Пример #1
0
        public void NamedTypeTest()
        {
            var address = new BifoqlNamedType("Address", BifoqlType.Map(BifoqlType.Property("street", BifoqlType.String)));
            var person  = new BifoqlNamedType("Person", BifoqlType.Map(BifoqlType.Property("name", BifoqlType.String), BifoqlType.Property("address", BifoqlType.Named(() => address))));

            var optionalPerson = BifoqlType.Map(BifoqlType.Property("p",
                                                                    BifoqlType.Index(BifoqlType.Named(() => person),
                                                                                     BifoqlType.IndexParameter("id", BifoqlType.Number),
                                                                                     BifoqlType.IndexParameter("locale", BifoqlType.String, optional: true))));

            var s = new Schema(optionalPerson, address, person);

            var schema =
                @"{
    p: (id: number, locale?: string) => Person
}

Address = {
    street: string
}

Person = {
    name: string,
    address: Address
}
";

            Assert.Equal(schema, s.BuildDocumentation());
        }
Пример #2
0
        public void IndexedType()
        {
            var type = new Schema(BifoqlType.Index(BifoqlType.String,
                                                   BifoqlType.IndexParameter("a", BifoqlType.Number, true),
                                                   BifoqlType.IndexParameter("b", BifoqlType.Boolean),
                                                   BifoqlType.IndexSwitch("c")));

            Assert.Equal("(a?: number, b: boolean, c?: boolean) => string", type.BuildDocumentation());
        }
Пример #3
0
        public void MapWithOverloadedLookups()
        {
            var expected =
                @"{
    foo: string,
    foo: (id: number) => string
}";
            var type = new Schema(BifoqlType.Map(
                                      BifoqlType.Property("foo", BifoqlType.String),
                                      BifoqlType.Property("foo", BifoqlType.Index(BifoqlType.String,
                                                                                  BifoqlType.IndexParameter("id", BifoqlType.Number)
                                                                                  ))));

            Assert.Equal(expected, type.BuildDocumentation());
        }
Пример #4
0
        public void NamedTypeWithDocumentationTest()
        {
            var person = new BifoqlNamedType("Person", BifoqlType.Map(BifoqlType.Property("name", BifoqlType.String)), "A human being");

            var optionalPerson = BifoqlType.Map(BifoqlType.Property("p",
                                                                    BifoqlType.Index(BifoqlType.Named(() => person),
                                                                                     BifoqlType.IndexParameter("id", BifoqlType.Number),
                                                                                     BifoqlType.IndexParameter("locale", BifoqlType.String, optional: true))));

            var s = new Schema(optionalPerson, person);

            var schema =
                @"{
    p: (id: number, locale?: string) => Person
}

// A human being
Person = {
    name: string
}
";

            Assert.Equal(schema, s.BuildDocumentation());
        }