public void DataMap_NestedMap()
        {
            NestedCollections n;

            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("nestedMap", new Dictionary <string, object>()
            {
                { "one",
                  new Dictionary <string, object>()
                  {
                      { "two",
                            new Dictionary <string, object>()
                            {
                                { "stringField", "one, two" }
                            } },
                      { "extra",
                            new Dictionary <string, object>()
                            {
                                { "stringField", "one, extra" }
                            } }
                  } }
            });

            n = new NestedCollections(data);

            Assert.IsFalse(n.hasCollectionWithDefault);
            Assert.IsFalse(n.hasNestedArray);
            Assert.IsTrue(n.hasNestedMap);
            Assert.IsFalse(n.hasMixed);
            Assert.AreEqual("one, two", n.nestedMap["one"]["two"].stringField);
            Assert.AreEqual("one, extra", n.nestedMap["one"]["extra"].stringField);
        }
        public void DataMap_OmitAll()
        {
            NestedCollections n = new NestedCollections(new Dictionary <string, object>());

            Assert.IsFalse(n.hasCollectionWithDefault);
            Assert.IsFalse(n.hasNestedArray);
            Assert.IsFalse(n.hasNestedMap);
            Assert.IsFalse(n.hasMixed);
        }
        public void DataMap_Mixed()
        {
            NestedCollections n;

            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("mixed", new List <object>()
            {
                new Dictionary <string, object>()
                {
                    { "one",
                      new List <object>()
                      {
                          new Dictionary <string, object>()
                          {
                              { "stringField", "0, one, 0" }
                          },
                          new Dictionary <string, object>()
                          {
                              { "stringField", "0, one, 1" }
                          }
                      } },
                    { "extra",
                      new List <object>()
                      {
                          new Dictionary <string, object>()
                          {
                              { "stringField", "0, extra, 0" }
                          }
                      } }
                }
            });

            n = new NestedCollections(data);

            Assert.IsFalse(n.hasCollectionWithDefault);
            Assert.IsFalse(n.hasNestedArray);
            Assert.IsFalse(n.hasNestedMap);
            Assert.IsTrue(n.hasMixed);
            Assert.AreEqual("0, one, 0", n.mixed[0]["one"][0].stringField);
            Assert.AreEqual("0, one, 1", n.mixed[0]["one"][1].stringField);
            Assert.AreEqual("0, extra, 0", n.mixed[0]["extra"][0].stringField);
        }
示例#4
0
        public void NestedCollection_FromSerializedData()
        {
            NestedCollections n;

            string serialized = @"{
                'mixed':[{
                    'one':[{'stringField':'0, one, 0'},{'stringField':'0, one, 1'}],
                    'extra':[{'stringField':'0, extra, 0'}]
                }]}";

            Dictionary <string, object> data = DataUtil.StringToMap(serialized);

            n = new NestedCollections(data);

            Assert.IsFalse(n.hasCollectionWithDefault);
            Assert.IsFalse(n.hasNestedArray);
            Assert.IsFalse(n.hasNestedMap);
            Assert.IsTrue(n.hasMixed);
            Assert.AreEqual("0, one, 0", n.mixed[0]["one"][0].stringField);
            Assert.AreEqual("0, one, 1", n.mixed[0]["one"][1].stringField);
            Assert.AreEqual("0, extra, 0", n.mixed[0]["extra"][0].stringField);
        }
        public void DataMap_NestedArray()
        {
            NestedCollections n;

            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("nestedArray", new List <object>()
            {
                new List <object>()
                {
                    new List <object>()
                    {
                        new Dictionary <string, object>()
                        {
                            { "stringField", "hello, nested!" }
                        }
                    },
                    new List <object>()
                    {
                        new Dictionary <string, object>()
                        {
                            { "stringField", "another" }
                        }
                    }
                }
            });

            n = new NestedCollections(data);

            Assert.IsFalse(n.hasCollectionWithDefault);
            Assert.IsTrue(n.hasNestedArray);
            Assert.IsFalse(n.hasNestedMap);
            Assert.IsFalse(n.hasMixed);
            Assert.AreEqual("hello, nested!", n.nestedArray[0][0][0].stringField);
            Assert.AreEqual("another", n.nestedArray[0][1][0].stringField);
        }
        public virtual IQueryable <TEntity> Set <TEntity>()
            where TEntity : class
        {
            if (typeof(TEntity) == typeof(BaseInheritanceRelationshipEntity))
            {
                return((IQueryable <TEntity>)BaseEntities.AsQueryable());
            }

            if (typeof(TEntity) == typeof(DerivedInheritanceRelationshipEntity))
            {
                return((IQueryable <TEntity>)BaseEntities.OfType <DerivedInheritanceRelationshipEntity>().AsQueryable());
            }

            if (typeof(TEntity) == typeof(BaseReferenceOnBase))
            {
                return((IQueryable <TEntity>)BaseReferencesOnBase.AsQueryable());
            }

            if (typeof(TEntity) == typeof(BaseReferenceOnDerived))
            {
                return((IQueryable <TEntity>)BaseReferencesOnDerived.AsQueryable());
            }

            if (typeof(TEntity) == typeof(ReferenceOnBase))
            {
                return((IQueryable <TEntity>)ReferencesOnBase.AsQueryable());
            }

            if (typeof(TEntity) == typeof(ReferenceOnDerived))
            {
                return((IQueryable <TEntity>)ReferencesOnDerived.AsQueryable());
            }

            if (typeof(TEntity) == typeof(NestedReferenceBase))
            {
                return((IQueryable <TEntity>)NestedReferences.AsQueryable());
            }

            if (typeof(TEntity) == typeof(BaseCollectionOnBase))
            {
                return((IQueryable <TEntity>)BaseCollectionsOnBase.AsQueryable());
            }

            if (typeof(TEntity) == typeof(BaseCollectionOnDerived))
            {
                return((IQueryable <TEntity>)BaseCollectionsOnDerived.AsQueryable());
            }

            if (typeof(TEntity) == typeof(CollectionOnBase))
            {
                return((IQueryable <TEntity>)CollectionsOnBase.AsQueryable());
            }

            if (typeof(TEntity) == typeof(CollectionOnDerived))
            {
                return((IQueryable <TEntity>)CollectionsOnDerived.AsQueryable());
            }

            if (typeof(TEntity) == typeof(NestedCollectionBase))
            {
                return((IQueryable <TEntity>)NestedCollections.AsQueryable());
            }

            if (typeof(TEntity) == typeof(PrincipalEntity))
            {
                return((IQueryable <TEntity>)PrincipalEntities.AsQueryable());
            }

            if (typeof(TEntity) == typeof(ReferencedEntity))
            {
                return((IQueryable <TEntity>)ReferencedEntities.AsQueryable());
            }

            throw new InvalidOperationException("Invalid entity type: " + typeof(TEntity));
        }
        public void FullCycle()
        {
            NestedCollections n;

            NestedCollectionsBuilder b = new NestedCollectionsBuilder();

            b.mixed = new List <Dictionary <string, List <SimpleRecord> > >()
            {
                new Dictionary <string, List <SimpleRecord> >()
                {
                    { "one",
                      new List <SimpleRecord>()
                      {
                          new SimpleRecord(new Dictionary <string, object>()
                            {
                                { "stringField", "0, one, 0" }
                            }),
                          new SimpleRecord(new Dictionary <string, object>()
                            {
                                { "stringField", "0, one, 1" }
                            })
                      } },
                    { "extra",
                      new List <SimpleRecord>()
                      {
                          new SimpleRecord(new Dictionary <string, object>()
                            {
                                { "stringField", "0, extra, 0" }
                            })
                      } }
                }
            };
            b.nestedMap = new Dictionary <string, Dictionary <string, SimpleRecordProjection> >()
            {
                { "one",
                  new Dictionary <string, SimpleRecordProjection>()
                  {
                      { "two",
                            new SimpleRecordProjection(new Dictionary <string, object>()
                            {
                                { "stringField", "one, two" }
                            }) },
                      { "extra",
                            new SimpleRecordProjection(new Dictionary <string, object>()
                            {
                                { "stringField", "one, extra" }
                            }) }
                  } }
            };

            n = b.Build();

            NestedCollections reclaimed = new NestedCollections(n.Data());

            Assert.AreNotSame(n, reclaimed);
            Assert.IsFalse(n.hasCollectionWithDefault || reclaimed.hasCollectionWithDefault);
            Assert.IsFalse(n.hasNestedArray || reclaimed.hasNestedArray);
            Assert.IsTrue(n.hasNestedMap && reclaimed.hasNestedMap);
            Assert.IsTrue(n.hasMixed && reclaimed.hasMixed);
            Assert.AreEqual(n.nestedMap["one"]["two"].stringField, reclaimed.nestedMap["one"]["two"].stringField);
            Assert.AreEqual(n.nestedMap["one"]["extra"].stringField, reclaimed.nestedMap["one"]["extra"].stringField);
            Assert.AreEqual(n.mixed[0]["one"][0].stringField, reclaimed.mixed[0]["one"][0].stringField);
            Assert.AreEqual(n.mixed[0]["one"][1].stringField, reclaimed.mixed[0]["one"][1].stringField);
            Assert.AreEqual(n.mixed[0]["extra"][0].stringField, reclaimed.mixed[0]["extra"][0].stringField);
        }