public void DeleteTest() { ObjectMappingForTest item = repository.GetByIdAsync(2).Result; Assert.IsNotNull(item, "Не найден объект по ID."); repository.Delete(2); context.SaveChanges(); item = repository.GetByIdAsync(2).Result; Assert.IsNull(item, "Не удален объект в контекста."); }
public void ValidateContextTest() { var options = new DbContextOptionsBuilder <ApplicationContextForTest>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; ApplicationContextForTest context = new ApplicationContextForTest(options); ObjectMappingForTest objectMappingForTest = new ObjectMappingForTest(); context.SaveChanges(); context.Set <ObjectMappingForTest>().Add(objectMappingForTest); // var result = Assert.ThrowsException<DbEntityValidationException>(() => context.SaveChanges()); //Assert.IsFalse(validateContextResult.IsSuccess); //Assert.AreEqual(1, validateContextResult.Count); //Assert.AreEqual(2, validateContextResult[0].Fields.Count); //Assert.AreEqual("IntValue", validateContextResult[0].Fields[0].Name); //Assert.AreEqual("Строка", validateContextResult[0].Fields[1].Name); }
private void ReCreateContext() { var options = new DbContextOptionsBuilder <ApplicationContextForTest>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; context = new ApplicationContextForTest(options); repository = new Repository <ObjectMappingForTest>(context); repository.Add(new ObjectMappingForTest() { Id = 1, IntValue = 1, StrValue = "1", IntValue2 = 11 }); repository.Add(new ObjectMappingForTest() { Id = 2, IntValue = 2, StrValue = "2", IntValue2 = 22 }); repository.Add(new ObjectMappingForTest() { Id = 3, IntValue = 3, StrValue = "3", IntValue2 = 33 }); repository.Add(new ObjectMappingForTest() { Id = 4, IntValue = 4, StrValue = "4", IntValue2 = 44 }); repository.Add(new ObjectMappingForTest() { Id = 5, IntValue = 5, StrValue = "5", IntValue2 = 55 }); repository.Add(new ObjectMappingForTest() { Id = 6, IntValue = 6, StrValue = "6", IntValue2 = 66 }); repository.Add(new ObjectMappingForTest() { Id = 7, IntValue = 7, StrValue = "7", IntValue2 = 7 }); context.SaveChanges(); }