public void MappingTest() { var strategy = new EntityModelMappingStrategy(); using (var context = new DbContextByMappingStrategy(builder => strategy.Mapping(builder, typeof(EntityModel.EntityModel)))) { for (int i = 0; i < 10; i++) { context.Add(new EntityModel.EntityModel()); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(builder => strategy.Mapping(builder, typeof(EntityModel.EntityModel)))) { var datas = context.Set <EntityModel.EntityModel>().ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); Assert.All(datas, data => Assert.NotEqual(Guid.Empty, data.Id)); } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var cogmStrategy = new ChildOfGuidMappingStrategy(); var pogmStrategy = new ParentOfGuidMappingStrategy(); Action <ModelBuilder> mappingAction = modelBuild => { emStrategy.Mapping(modelBuild, typeof(OneOfInt32EntityModel)); cogmStrategy.Mapping(modelBuild, typeof(OneOfInt32EntityModel)); pogmStrategy.Mapping(modelBuild, typeof(ManyOfInt32EntityModel)); }; using (var context = new DbContextByMappingStrategy(mappingAction)) { var oneEntityModel = new OneOfInt32EntityModel { CountOfChild = 10, Children = new List <ManyOfInt32EntityModel>(10) }; for (int i = 0; i < 10; i++) { oneEntityModel.Children.Add(new ManyOfInt32EntityModel { Parent = oneEntityModel }); } context.Add(oneEntityModel); Assert.Equal(11, context.SaveChanges()); } using (var context = new DbContextByMappingStrategy(mappingAction)) { var data = context.Set <OneOfInt32EntityModel>() .Include(one => one.Children) .SingleOrDefault(); Assert.NotNull(data); Assert.NotEqual(0, data.Id); Assert.Equal(10, data.CountOfChild); Assert.NotNull(data.Children); Assert.Equal(10, data.Children.Count); Assert.All(data.Children.AsEnumerable(), child => { Assert.NotEqual(0, child.Id); Assert.Equal(data.Id, child.ParentId); Assert.NotNull(child.Parent); Assert.Equal(child.ParentId, child.Parent.Id); }); } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var cmStrategy = new CnvMappingStrategy(); Action <ModelBuilder> action = builder => { emStrategy.Mapping(builder, typeof(CnvOfEntityModel)); cmStrategy.Mapping(builder, typeof(CnvOfEntityModel)); }; using (var context = new DbContextByMappingStrategy(action)) { for (int i = 0; i < 10; i++) { context.Cnvs.Add(new CnvOfEntityModel { Code = $"C_00{i}", Description = $"D_{i}", Name = $"N_{i}", Value = $"V_{i}" }); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(action)) { var datas = context.Cnvs.ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); for (int i = 0; i < 10; i++) { Assert.NotEqual(Guid.Empty, datas[0].Id); Assert.Equal($"C_00{i}", datas[i].Code); Assert.Equal($"D_{i}", datas[i].Description); Assert.Equal($"N_{i}", datas[i].Name); Assert.Equal($"V_{i}", datas[i].Value); } } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var nmStrategy = new NoteMappingStrategy(); Action <ModelBuilder> action = builder => { emStrategy.Mapping(builder, typeof(NoteOfEntityModel)); nmStrategy.Mapping(builder, typeof(NoteOfEntityModel)); }; using (var context = new DbContextByMappingStrategy(action)) { for (int i = 0; i < 10; i++) { context.Add(new NoteOfEntityModel { Note = $"Note_{i}", SecondNote = $"SecondNote_{i}", ThirdNote = $"ThirdNote_{i}" }); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(action)) { var datas = context.Notes.ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); for (int i = 0; i < 10; i++) { Assert.NotEqual(Guid.Empty, datas[i].Id); Assert.Equal($"Note_{i}", datas[i].Note); Assert.Equal($"SecondNote_{i}", datas[i].SecondNote); Assert.Equal($"ThirdNote_{i}", datas[i].ThirdNote); } } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var tmStrategy = new TimeMappingStrategy(); Action <ModelBuilder> action = builder => { emStrategy.Mapping(builder, typeof(TimeOfEntityModel)); tmStrategy.Mapping(builder, typeof(TimeOfEntityModel)); }; using (var context = new DbContextByMappingStrategy(action)) { for (int i = 0; i < 10; i++) { context.Times.Add(new TimeOfEntityModel { CreateTime = DateTime.MinValue, ModifyTime = DateTime.MaxValue }); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(action)) { var datas = context.Times.ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); Assert.All(datas, data => { Assert.Equal(DateTime.MinValue, data.CreateTime); Assert.Equal(DateTime.MaxValue, data.ModifyTime); }); } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var vmStrategy = new VersionMappingStrategy(); Action <ModelBuilder> action = builder => { emStrategy.Mapping(builder, typeof(VersionOfEntityModel)); vmStrategy.Mapping(builder, typeof(VersionOfEntityModel)); }; using (var context = new DbContextByMappingStrategy(action)) { for (int i = 0; i < 10; i++) { context.Versions.Add(new VersionOfEntityModel { Version = new byte[] { 1, 2, 3, 4, 5, 6 } }); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(action)) { var datas = context.Versions.ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); Assert.All(datas, data => { Assert.NotEqual(Guid.Empty, data.Id); Assert.NotNull(data.Version); Assert.NotEqual(0, data.Version.Length); }); } }
public void MappingTest() { var emStrategy = new EntityModelMappingStrategy(); var smStrategy = new StateMappingStrategy(); Action <ModelBuilder> action = builder => { emStrategy.Mapping(builder, typeof(StateOfEntityModel)); smStrategy.Mapping(builder, typeof(StateOfEntityModel)); }; using (var context = new DbContextByMappingStrategy(action)) { for (int i = 0; i < 10; i++) { context.States.Add(new StateOfEntityModel { State = i }); } context.SaveChanges(); } using (var context = new DbContextByMappingStrategy(action)) { var datas = context.States.ToList(); Assert.NotNull(datas); Assert.Equal(10, datas.Count); for (int i = 0; i < datas.Count; i++) { Assert.NotEqual(Guid.Empty, datas[i].Id); Assert.Equal(i, datas[i].State); } } }