コード例 #1
0
        public async Task ShouldRetrieveCustomerWithIdFromCache()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork <Customer>(provider);

            var id = SampleDataProvider.CreateGuid(1);

            Assert.IsFalse(unitOfWork.Entities.ExistsInCache(id));
            Customer customer = null;

            try
            {
                customer = unitOfWork.Entities.WithIdFromCache(id);
            }
            catch (EntityNotFoundException)
            {
                // Expected exception
            }
            Assert.IsNull(customer);

            // Fetch from data source
            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            await unitOfWork.Entities.WithIdFromDataSourceAsync(id);

            Assert.IsTrue(unitOfWork.Entities.ExistsInCache(id));
            customer = unitOfWork.Entities.WithIdFromCache(id);
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.CustomerID == id);
        }
コード例 #2
0
        public async Task ShouldRetrieveCustomerWithId()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork <Customer>(provider);

            var id = SampleDataProvider.CreateGuid(1);

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            var customer = await unitOfWork.Entities.WithIdAsync(id);

            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.CustomerID == id);
        }