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)); }
//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); }
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(); }
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()); }
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); }
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); }
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); }
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()); }