Beispiel #1
0
        public async Task ShouldGetCustomers()
        {
            var emp = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var repository = new CustomerRepository(emp);

            await InitFakeBackingStoreAsync(emp.Manager.CompositionContext.Name);
            var customers = await repository.GetCustomersAsync(null);

            Assert.IsTrue(customers.Any(), "Should have some customers");
        }
Beispiel #2
0
        public async Task ShouldSynchronizeDeletesBetweenEntityManagers()
        {
            CompositionContext compositionContextWithSyncInterceptor = CompositionContext.Fake
                .WithGenerator(typeof(IEntityManagerSyncInterceptor), () => new SyncInterceptor())
                .WithName("ShouldSynchronizeDeletesBetweenEntityManagers");
            CompositionContextResolver.Add(compositionContextWithSyncInterceptor);

            var rep1 = new CustomerRepository(
                EntityManagerProviderFactory.CreateTestEntityManagerProvider(
                    "ShouldSynchronizeDeletesBetweenEntityManagers"));
            var rep2 = new CustomerRepository(
                EntityManagerProviderFactory.CreateTestEntityManagerProvider(
                    "ShouldSynchronizeDeletesBetweenEntityManagers"));

            await InitFakeBackingStoreAsync("ShouldSynchronizeDeletesBetweenEntityManagers");
            var customers = await rep1.GetCustomersAsync(null);
            var customers2 = await rep2.GetCustomersAsync(null);

            Customer customer = customers.First();

            Assert.IsNotNull(
                rep1.EntityManagerProvider.Manager.FindEntity(customer.EntityAspect.EntityKey),
                "Customer should be in EM1's cache");
            Assert.IsNotNull(
                rep2.EntityManagerProvider.Manager.FindEntity(customer.EntityAspect.EntityKey),
                "Customer should be in EM2's cache");

            rep1.DeleteCustomer(customer);
            Assert.IsNull(
                rep1.EntityManagerProvider.Manager.FindEntity(customer.EntityAspect.EntityKey),
                "Customer should have been removed from first cache");
            Assert.IsNotNull(
                rep2.EntityManagerProvider.Manager.FindEntity(customer.EntityAspect.EntityKey),
                "Customer should still be in second EntityManager");

            await rep1.SaveAsync();
            Assert.IsNull(rep2.EntityManagerProvider.Manager.FindEntity(customer.EntityAspect.EntityKey),
                "Customer should have been removed from second EntityManager");
        }