Exemplo n.º 1
0
        public void Linq_Visitor_Wit_DbRef()
        {
            var m = new BsonMapper();

            m.Entity <UserDomain>()
            .Id(x => x.DomainName);

            m.Entity <User>()
            .DbRef(x => x.Domain)
            .Field(x => x.Domain, "current-domain")
            .DbRef(x => x.Domains);

            // Json PATH

            Assert.AreEqual("$.Age", m.GetPath <User>(x => x.Age));
            Assert.AreEqual("$._id", m.GetPath <User>(x => x.Id));
            Assert.AreEqual("$.current-domain", m.GetPath <User>(x => x.Domain));
            Assert.AreEqual("$.Domains[*]", m.GetPath <User>(x => x.Domains));
            Assert.AreEqual("$.Domains[*].Age", m.GetPath <User>(x => x.Domains[0].Age));
            Assert.AreEqual("$.Domains[*].Age", m.GetPath <User>(x => x.Domains.Select(z => z.Age)));
            Assert.AreEqual("$.Domains[*].$id", m.GetPath <User>(x => x.Domains[0].DomainName));

            // Bson Field
            Assert.AreEqual("Domains", m.GetField <User>(x => x.Domains));
            Assert.AreEqual("Domains.Age", m.GetField <User>(x => x.Domains[0].Age));
            Assert.AreEqual("Domains.$id", m.GetField <User>(x => x.Domains[0].DomainName));

            // Query
            Assert.AreEqual("(_id = 123)", m.GetQuery <User>(x => x.Id == 123).ToString());
            Assert.AreEqual("(_id between [1 and 2])", m.GetQuery <User>(x => x.Id >= 1 && x.Id <= 2).ToString());
            Assert.AreEqual("(Domains.$id = \"admin\")", m.GetQuery <User>(x => x.Domains[0].DomainName == "admin").ToString());
        }
Exemplo n.º 2
0
        public void Linq_Visitor_Without_DbRef()
        {
            var m = new BsonMapper();

            m.UseLowerCaseDelimiter();

            // Json PATH

            Assert.AreEqual("$.age", m.GetPath <User>(x => x.Age));
            Assert.AreEqual("$._id", m.GetPath <User>(x => x.Id));
            Assert.AreEqual("$.domain", m.GetPath <User>(x => x.Domain));
            Assert.AreEqual("$.domains[*]", m.GetPath <User>(x => x.Domains));
            Assert.AreEqual("$.domains[*].age", m.GetPath <User>(x => x.Domains[0].Age));
            Assert.AreEqual("$.domains[*].age", m.GetPath <User>(x => x.Domains.Select(z => z.Age)));
            Assert.AreEqual("$.domains[*].domain_name", m.GetPath <User>(x => x.Domains[0].DomainName));

            // Bson Field
            Assert.AreEqual("domains", m.GetField <User>(x => x.Domains));
            Assert.AreEqual("domains.age", m.GetField <User>(x => x.Domains[0].Age));
            Assert.AreEqual("domains.domain_name", m.GetField <User>(x => x.Domains[0].DomainName));

            // Query
            Assert.AreEqual("(_id = 123)", m.GetQuery <User>(x => x.Id == 123).ToString());
            Assert.AreEqual("(_id between [1 and 2])", m.GetQuery <User>(x => x.Id >= 1 && x.Id <= 2).ToString());
            Assert.AreEqual("(domains.domain_name = \"admin\")", m.GetQuery <User>(x => x.Domains[0].DomainName == "admin").ToString());
        }