Exemplo n.º 1
0
        public void CanQueryAndReturnSubClassedObjects_EvenWhenQueriedByInterface()
        {
            using (var session = new Session())
            {
                session.Drop<IDiscriminated>();

                var obj = new InterfaceDiscriminatedClass();
                session.Add(obj);

                var query = new MongoQuery<IDiscriminated>(session.Provider);

                var dtos = query.ToList();

                Assert.Equal(1, dtos.Count);
                Assert.Equal(obj.Id, dtos.Single().Id);
            }
        }
Exemplo n.º 2
0
        public void SerializationOfInheritenceIsNotLossy_EvenWhenDiscriminatorIsOnAnInterfaceAndWeTryToDeserializeUsingTheInterface()
        {
            var obj1 = new InterfaceDiscriminatedClass();
            var hydratedObj1 = (InterfaceDiscriminatedClass)BsonDeserializer.Deserialize<IDiscriminated>(BsonSerializer.Serialize(obj1));

            Assert.Equal(obj1.Id, hydratedObj1.Id);
        }
Exemplo n.º 3
0
        public void CanQueryAndReturnSubClassedObjects_EvenWhenQueriedByInterface()
        {
            using (var session = new Session())
            {
                session.Drop<IDiscriminated>();

                var obj = new InterfaceDiscriminatedClass();
                session.Add(obj);

                var queryable = session.DB.GetCollection<IDiscriminated>().AsQueryable();
                var dtos = queryable.ToList();

                Assert.Equal(1, dtos.Count);
                Assert.Equal(obj.Id, dtos.Single().Id);
                Assert.Equal(false, queryable.QueryStructure().IsComplex);
            }
        }