コード例 #1
0
        public void Given_a_corresponding_Animal_Pets_can_be_persisted_and_retrieved()
        {
            //Arrange
            var sutProvider  = new DataProvider <Pet>(_config, Pet.ToDomainConverter);
            var columns      = sutProvider.LoadAllColumns();
            var sutPersister = new PetPersister(columns, _config);
            var animalRecord = TestData.Animals.Chihuahua;


            ErrorMessage error;

            if (!PersistAnimal(out error, ref animalRecord))
            {
                Assert.Fail(error.Message);
            }

            var petRecord     = new Pet(animalRecord.AnimalId, "Princess");
            var persistResult = sutPersister.TryPersist(ref petRecord, out error);

            //Assert
            Assert.IsTrue(persistResult);
            Assert.IsNull(error);
            Assert.IsNotNull(petRecord.PetId);
            Assert.IsInstanceOf <int>(petRecord.PetId);

            var readResult = sutProvider.LoadAll().First();

            Assert.AreEqual(petRecord, readResult);
            Assert.AreEqual(petRecord.PetId, readResult.PetId);
        }
コード例 #2
0
        private bool PersistPet(out ErrorMessage error, ref Pet pet)
        {
            var provider  = new DataProvider <Pet>(_config, Pet.ToDomainConverter);
            var columns   = provider.LoadAllColumns();
            var persister = new PetPersister(columns, _config);

            return(persister.TryPersist(ref pet, out error));
        }