public void UserInitiatedTransactionTest <T>() { // Arrange var person = new Person { FamilyName = "McCoy", FirstName = "Henry", PetCount = 5 }; // Create 'Person' to use in test. var student = new Student() { CourseCount = 5 }; var efCodeFirstLibRepository = new EfCodeFirstLibRepository(); // Act var wasUserInitiatedTransactionSuccessful = efCodeFirstLibRepository.AddPersonAndStudentTransaction(person, student); var createdPersonPrimaryKeyValues = new object[] { person.PersonId }; // Specify 'primary key' to 'find/select' newly created 'Person'. var createdStudentPrimaryKeyValues = new object[] { student.StudentId }; // Specify 'primary key' to 'find/select' newly created 'Student'. var foundPerson = efCodeFirstLibRepository.PersonRead(createdPersonPrimaryKeyValues); // Attempt to find created 'Person' (null is expected, since newly created 'Person' should be deleted). var foundStudent = efCodeFirstLibRepository.StudentRead(createdStudentPrimaryKeyValues); // Attempt to find created 'Student' (null is expected, since newly created 'Person' should be deleted). DeleteEntity(foundStudent); // Cleanup: Attempt to delete here/now in case an assert fails. (Deleting 'Student' first due to 'PersonId' foreign key constraint.) DeleteEntity(foundPerson); // Cleanup: Attempt to delete here/now in case an assert fails. // Assert Assert.IsTrue(wasUserInitiatedTransactionSuccessful); }
private static void RunUserInitiatedTransactionExample() { var person = new Person { FamilyName = "Baker", FirstName = "Chris", PetCount = 1 }; // Create 'Person' object to be added to database/repository. var student = new Student() { CourseCount = 5 }; var efCodeFirstLibRepository = new EfCodeFirstLibRepository(); var wasUserInitiatedTransactionSuccessful = efCodeFirstLibRepository.AddPersonAndStudentTransaction(person, student); }