Пример #1
0
        public void UpdateTest <T>()
        {
            const int PET_COUNT = 3;

            // Arrange
            var person = new Person {
                FamilyName = "Summers", FirstName = "Scott", PetCount = PET_COUNT
            };                                                                                             // Create 'Person' to 'find/select' for test.

            var efCodeFirstLibRepository = new EfCodeFirstLibRepository();
            var createdPerson            = efCodeFirstLibRepository.PersonCreate(person);

            var createdPersonPrimaryKeyValues = new object[] { createdPerson.PersonId };                      // Specify 'primary key' to 'find/select' newly created 'Person'.
            var existingPerson = efCodeFirstLibRepository.PersonRead(createdPersonPrimaryKeyValues);          // 'Find/select' newly created 'Person' to update.

            var updatedValuesPerson = efCodeFirstLibRepository.DeepCloneViaJsonSerialization(existingPerson); // 'Clone' the 'foundPerson' to make update easier (i.e. easier than manual/copy object initialiation).

            const int PET_COUNT_INCREASE       = 10;
            const int EXPECTED_PET_COUNT_TOTAL = PET_COUNT + PET_COUNT_INCREASE;

            updatedValuesPerson.PetCount = updatedValuesPerson.PetCount + PET_COUNT_INCREASE; // 'Updating' the newly created 'Person' to increase the 'PetCount' property (increment by 10).

            // Act
            efCodeFirstLibRepository.PersonUpdate(existingPerson, updatedValuesPerson);

            DeleteEntity(createdPerson); // Cleanup: Attempt to delete here/now in case an assert fails.

            // Assert
            Assert.IsNotNull(updatedValuesPerson);
            Assert.IsTrue(updatedValuesPerson.PetCount.Equals(EXPECTED_PET_COUNT_TOTAL));
        }
Пример #2
0
        private static void RunCreateReadUpdateDeleteRepoExample()
        {
            var personSmith = new Person {
                FamilyName = "Smith", FirstName = "Pat", PetCount = 1
            };                                                                                                      // Create 'Person' object to be added to database/repository.

            var efCodeFirstLibRepository = new EfCodeFirstLibRepository();

            var createdPersonSmith = efCodeFirstLibRepository.PersonCreate(personSmith);                            // Insert new 'Person' record (from specified object values).

            var foundPersonSmith = efCodeFirstLibRepository.PersonFind(createdPersonSmith);                         // Find newly created 'Person' record (e.g. 'Identity/Primary Key' will have been incremented).

            var updatedPersonSmith = efCodeFirstLibRepository.DeepCloneViaJsonSerialization(foundPersonSmith);      // Modify 'PetCount' property (incrementy by 10).

            updatedPersonSmith.PetCount = updatedPersonSmith.PetCount + 10;

            efCodeFirstLibRepository.PersonUpdate(foundPersonSmith, updatedPersonSmith);                            // Update 'Person' record (with increased 'PetCount').

            efCodeFirstLibRepository.DeleteEntity(foundPersonSmith);                                                // Remove/delete 'Person' record.
        }