コード例 #1
0
        public void TransformError()
        {
            bool completed = false;
            bool error = false;

            var feeder = new SourceCache<Entity, int>(e => e.Key);

            var subscriber = feeder.Connect()
                            .Transform(e => new TransformEntityWithError(e))

                            .Finally(() => completed = true)
                            .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(Enumerable.Range(0, 10000).Select(_ => new Entity()).ToArray()));
            feeder.BatchUpdate(updater => updater.AddOrUpdate(new Entity()));

            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }
コード例 #2
0
        public void TransformError()
        {
            bool completed = false;
            bool error     = false;


            var feeder = new SourceCache <Entity, int>(e => e.Key);

            var subscriber = feeder.Connect()
                             .Transform(e => new TransformEntityWithError(e))

                             .Finally(() => completed = true)
                             .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(Enumerable.Range(0, 10000).Select(_ => new Entity()).ToArray()));
            feeder.BatchUpdate(updater => updater.AddOrUpdate(new Entity()));


            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }
コード例 #3
0
        public void ErrorUpdatingStreamIsHandled()
        {
            bool completed = false;
            bool error     = false;

            var feeder = new SourceCache <ErrorInKey, int>(p => p.Key);

            var subscriber = feeder.Connect().Finally(() => completed = true)
                             .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(new ErrorInKey()));
            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }
コード例 #4
0
        public void ErrorUpdatingStreamIsHandled()
        {
            bool completed = false;
            bool error = false;

            var feeder = new SourceCache<ErrorInKey, int>(p=>p.Key);

            var subscriber = feeder.Connect().Finally(() => completed = true)
                                 .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(new ErrorInKey()));
            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }
コード例 #5
0
        public void FilterError()
        {
            bool completed = false;
            bool error     = false;

            var feeder = new SourceCache <TransformEntityWithError, int>(e => e.Key);

            var subscriber = feeder.Connect()
                             .Filter(x => true)
                             .Finally(() => completed = true)
                             .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(new TransformEntityWithError(new Entity())));
            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }
コード例 #6
0
        public void Sack(EmployeeDto sackEmp)
        {
            //in the real world, go to service then updated the cache

            _employees.BatchUpdate(updater =>
            {
                //assign new boss to the workers of the sacked employee
                var workersWithNewBoss = updater.Items
                                         .Where(emp => emp.BossId == sackEmp.Id)
                                         .Select(dto => new EmployeeDto(dto.Id, dto.Name, sackEmp.BossId))
                                         .ToArray();

                updater.AddOrUpdate(workersWithNewBoss);

                //get rid of the existing person
                updater.Remove(sackEmp.Id);
            });
        }
コード例 #7
0
        public void FilterError()
        {
            bool completed = false;
            bool error = false;

            var feeder = new SourceCache<TransformEntityWithError, int>(e=>e.Key);

            var subscriber = feeder.Connect()
                            .Filter(x=>true)
                            .Finally(() => completed = true)
                            .Subscribe(updates => { Console.WriteLine(); }, ex => error = true);

            feeder.BatchUpdate(updater => updater.AddOrUpdate(new TransformEntityWithError(new Entity())));
            subscriber.Dispose();

            Assert.IsTrue(error, "Error has not been invoked");
            Assert.IsTrue(completed, "Completed has not been called");
        }