public void CRUD() { //Modl<Car>.Settings.ConfigurePipeline(new JsonModl<Car>(), new FileModl<Car>()); //ModlConfig.GlobalSettings.Serializer = new JsonModl(); //ModlConfig.GlobalSettings.Endpoint = new FileModl(); //Modl<Manufacturer>.Settings.Serializer = new JsonModl(); //Modl<Manufacturer>.Settings.Endpoint = new FileModl(); //Car car = Modl<Car>.New(); var car = new Car(); Assert.False(car.IsModified()); car.Name = "M3"; car.Manufacturer.Val = new Manufacturer("BMW"); car.Type = new CarType(); car.Type.Description = "Sedan"; car.Tags = new List<string>(); car.Tags.Add("Nice"); car.Tags.Add("Fast"); car.Tags.Add("Blue"); car.Tags.Add("Awful"); Assert.Equal("Sedan", car.Type.Description); Assert.True(car.IsModified()); car.Save(); Assert.False(car.IsNew()); Assert.False(car.IsModified()); car.Manufacturer.Val.Save(); Car car2 = Modl<Car>.Get(car.Id); AssertEqual(car, car2); Assert.Equal("Sedan", car2.Type.Description); car2.Manufacturer.Val.Name = "Mercedes"; Assert.Equal("Mercedes", car2.Manufacturer.Val.Name); car2.Manufacturer.Val.Save(); Car car3 = Modl<Car>.Get(car.Id); Assert.Equal("Mercedes", car3.Manufacturer.Val.Name); car3.Delete(); Assert.True(car3.IsDeleted()); Assert.False(car3.Manufacturer.Val.IsDeleted()); car3.Manufacturer.Val.Delete(); Assert.True(car3.Manufacturer.Val.IsDeleted()); Assert.Throws<NotFoundException>(() => Modl<Car>.Get(car.Id)); }
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()); }