Пример #1
0
        public void Get()
        {
            var id   = Guid.NewGuid();
            var modl = ModlReflect.New(typeof(EmptyClass), id) as EmptyClass;

            modl.Save();

            modl = ModlReflect.Get(typeof(EmptyClass), id) as EmptyClass;
            Assert.Equal(typeof(EmptyClass), modl.GetType());
            Assert.False(modl.IsNew());
            Assert.Equal(id, modl.Id().Get <Guid>());
        }
Пример #2
0
        public void CreateNew()
        {
            var modl = ModlReflect.New(typeof(EmptyClass));

            Assert.Equal(typeof(EmptyClass), modl.GetType());
            Assert.True((modl as EmptyClass).IsNew());

            var id = Guid.NewGuid();

            modl = ModlReflect.New(typeof(EmptyClass), id);
            Assert.Equal(typeof(EmptyClass), modl.GetType());
            Assert.True((modl as EmptyClass).IsNew());
            Assert.True(id == (modl as EmptyClass).Id());
        }
Пример #3
0
        // Set up a proeprty that will hold the current item being enumerated.
        //public SampleDataSourceItem Current { get; private set; }

        public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel)
        {
            foreach (var id in ModlReflect.List(typeof(T)))
            {
                yield return((T)ModlReflect.Get(typeof(T), id));
            }

            //return new List<M>();

            //for (var i = 0; i < 10; i++)
            //{
            //    yield return (T)Modl.New(typeof(T));
            //}


            //// Create an expression that returns the current item when invoked.
            //Expression currentItemExpression = Expression.Property(Expression.Constant(this), "Current");

            //// Now replace references like the "i" in "select i" that refers to the "i" in "from i in items"
            //var mapping = new QuerySourceMapping();
            //mapping.AddMapping(queryModel.MainFromClause, currentItemExpression);
            ////queryModel.TransformExpressions(e => ReferenceReplacingExpressionTreeVisitor.ReplaceClauseReferences(e, mapping, true));

            //// Create a lambda that takes our SampleDataSourceItem and passes it through the select clause
            //// to produce a type of T.  (T may be SampleDataSourceItem, in which case this is an identity function.)
            //var currentItemProperty = Expression.Parameter(typeof(SampleDataSourceItem));
            //var projection = Expression.Lambda<Func<SampleDataSourceItem, T>>(queryModel.SelectClause.Selector, currentItemProperty);
            //var projector = projection.Compile();

            //// Pretend we're getting SampleDataSourceItems from somewhere...
            //for (var i = 0; i < 10; i++)
            //{
            //    // Set the current item so currentItemExpression can access it.
            //    Current = new SampleDataSourceItem
            //    {
            //        Name = "Name " + i,
            //        Description = "This describes the item in position " + i
            //    };

            //    // Use the projector to convert (if necessary) the current item to what is being selected and return it.
            //    yield return projector(Current);
            //}
        }
Пример #4
0
        public void GetAll()
        {
            foreach (var m in ModlReflect.GetAll(typeof(EmptyClass)).Select(x => x as EmptyClass))
            {
                m.Delete();
            }

            var modlList = ModlReflect.GetAll(typeof(EmptyClass)).ToList();

            Assert.Equal(0, modlList.Count);

            var modl  = new EmptyClass().Save();
            var modl2 = new EmptyClass().Save();

            var modlList2 = ModlReflect.GetAll(typeof(EmptyClass)).Select(x => x as EmptyClass).ToList();

            Assert.Equal(2, modlList2.Count);
            Assert.True(modlList2.Any(x => x.Id() == modl.Id()));
            Assert.True(modlList2.Any(x => x.Id() == modl2.Id()));
        }
Пример #5
0
        public void List()
        {
            var modl = ModlReflect.New(typeof(EmptyClass)) as EmptyClass;

            modl.Save();

            var modl2 = ModlReflect.New(typeof(EmptyClass)) as EmptyClass;

            modl2.Save();

            var modlList = ModlReflect.List(typeof(EmptyClass)).ToList();

            Assert.NotEqual(0, modlList.Count);
            Assert.True(modlList.Any(x => (Guid)x == modl.Id().Get <Guid>()));
            Assert.True(modlList.Any(x => (Guid)x == modl2.Id().Get <Guid>()));

            var modlList2 = ModlReflect.List <Guid>(typeof(EmptyClass)).ToList();

            Assert.NotEqual(0, modlList2.Count);
            Assert.True(modlList2.Any(x => x == modl.Id().Get <Guid>()));
            Assert.True(modlList2.Any(x => x == modl2.Id().Get <Guid>()));
        }