示例#1
0
文件: Basics.cs 项目: bazer/Modl
        public void CRUDExplicitId()
        {
            Manufacturer m1 = Modl <Manufacturer> .New(Guid.NewGuid());

            Assert.False(m1.IsModified());
            m1.Name = "BMW";
            Assert.True(m1.IsModified());
            m1.Save();
            Assert.False(m1.IsNew());
            Assert.False(m1.IsModified());

            Manufacturer m2 = Modl <Manufacturer> .Get(m1.ManufacturerID);

            AssertEqual(m1, m2);

            m2.Name = "Mercedes";
            Assert.Equal("Mercedes", m2.Name);
            m2.Save();

            Manufacturer m3 = Modl <Manufacturer> .Get(m1.ManufacturerID);

            Assert.Equal("Mercedes", m3.Name);
            m3.Delete();
            Assert.True(m3.IsDeleted());
            Assert.Throws <NotFoundException>(() => Modl <Manufacturer> .Get(m1.ManufacturerID));
        }
示例#2
0
文件: ModlBinder.cs 项目: bazer/Modl
        //public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, System.Type modelType)
        {
            var id = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + "." + Modl <M> .Definitions.IdProperty.PropertyName);

            if (id == null)
            {
                id = bindingContext.ValueProvider.GetValue(Modl <M> .Definitions.IdProperty.PropertyName);
            }

            if (id != null)
            {
                return(Modl <M> .Get(id.AttemptedValue));
            }

            return(Modl <M> .New());

            //if (bindingContext.ModelType.GetInterface("IModl") != null && value != null)
            //{
            //    if (MvcHelper.IsNumeric(value.AttemptedValue))
            //    {
            //        var method = bindingContext.ModelType.GetMethods(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public).Single(x => x.Name == "Get" && x.GetParameters()[0].ParameterType == typeof(int));
            //        return method.Invoke(null, new object[] { Convert.ToInt32(value.AttemptedValue), true });
            //    }
            //}

            //return base.BindModel(controllerContext, bindingContext);
        }
示例#3
0
文件: Basics.cs 项目: bazer/Modl
        public void SetIdExplicit()
        {
            var          id = Guid.NewGuid();
            Manufacturer m1 = Modl <Manufacturer> .New(id);

            m1.Name = "Audi";
            Assert.Equal(id, m1.ManufacturerID);
            m1.Save();
            Assert.Equal(id, m1.ManufacturerID);

            var m2 = Modl <Manufacturer> .Get(m1.ManufacturerID.ToString());

            AssertEqual(m1, m2);

            m2.Save();
            Assert.Equal(id, m2.ManufacturerID);

            m2.Delete();
        }
示例#4
0
        public void CreateNew()
        {
            var testClass = new EmptyClass();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            testClass = Modl <EmptyClass> .New();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            var id = Guid.NewGuid();

            testClass = Modl <EmptyClass> .New(id);

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());
            Assert.True(id == testClass.Id());
        }
示例#5
0
        public void CreateNew()
        {
            var testClass = new CustomIdStringClass();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            testClass = Modl <CustomIdStringClass> .New();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            var id = Guid.NewGuid().ToString();

            testClass = Modl <CustomIdStringClass> .New(id);

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());
            Assert.True(id == testClass.Id());
            Assert.Equal(id, testClass.CustomId);
        }
示例#6
0
        public void CreateNew()
        {
            var testClass = new CustomIdIntClass();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            testClass = Modl <CustomIdIntClass> .New();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            var id = 3433;

            testClass = Modl <CustomIdIntClass> .New(id);

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());
            Assert.True(id == testClass.Id());
            Assert.Equal(id, testClass.CustomId);
        }
示例#7
0
        public void CreateNew()
        {
            var testClass = new AutomaticIdGuidClass();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            testClass = Modl <AutomaticIdGuidClass> .New();

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());

            var id = Guid.NewGuid();

            testClass = Modl <AutomaticIdGuidClass> .New(id);

            Assert.True(testClass.IsNew());
            Assert.False(testClass.IsModified());
            Assert.True(testClass.Id().Equals(id));
            Assert.True(id == testClass.Id());
            Assert.Equal(id, testClass.CustomId);
        }
示例#8
0
文件: Basics.cs 项目: bazer/Modl
        public void CoreStuff()
        {
            Assert.Equal("Id", Modl <Car> .Definitions.IdProperty.PropertyName);

            var car = Modl <Car> .New();

            Assert.True(car.IsNew());
            Assert.False(car.IsModified());
            car.Name = "Audi";
            Assert.True(car.IsNew());
            Assert.True(car.IsModified());

            car = new Car();
            Assert.True(car.IsNew());
            Assert.False(car.IsModified());
            car.Name = "Audi";
            Assert.True(car.IsNew());
            Assert.True(car.IsModified());

            car = new Car().Modl().Modl().Modl().Modl();
            Assert.True(car.IsNew());
            Assert.False(car.IsModified());
            car.Name = "Audi";
            Assert.True(car.IsNew());
            Assert.True(car.IsModified());

            //car.Save();

            car = Modl <Car> .New();

            car.Manufacturer.Val = new Manufacturer("BMW");
            Assert.True(car.IsNew());
            Assert.True(car.IsModified());
            Assert.Equal("BMW", car.Manufacturer.Val.Name);
            Assert.True(car.Manufacturer.Val.IsNew());
            Assert.True(car.Manufacturer.Val.IsModified());
        }