Exemplo n.º 1
0
        public void BatchRemoves()
        {
            Person[] people = Enumerable.Range(1, 100).Select(i => new Person("Name" + i, i)).ToArray();
            _updater.AddOrUpdate(people);
            _updater.Remove(people);
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            _cache.Count.Should().Be(0, "Everything should be removed");
            100.Should().Be(updates.Count(update => update.Reason == ChangeReason.Add), "Should be 100 adds");
            100.Should().Be(updates.Count(update => update.Reason == ChangeReason.Remove), "Should be 100 removes");
            200.Should().Be(updates.Count, "Should be 200 updates");
        }
        public void Clear()
        {
            Person[] people = Enumerable.Range(1, 100).Select(i => new Person("Name" + i, i)).ToArray();
            _updater.AddOrUpdate(people);
            _updater.Clear();
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            Assert.AreEqual(0, _cache.Count, "Everything should be removed");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Add), 100, "Should be 100 adds");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Remove), 100, "Should be 100 removes");
            Assert.AreEqual(updates.Count, 200, "Should be 200 updates");
        }
Exemplo n.º 3
0
        public void BatchSuccessiveUpdates()
        {
            Person[] people = Enumerable.Range(1, 100).Select(i => new Person("Name1", i)).ToArray();
            _updater.AddOrUpdate(people);

            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            _cache.Lookup("Name1").Value.Age.Should().Be(100);
            _cache.Count.Should().Be(1, "Successive updates should replace cache value");
            99.Should().Be(updates.Count(update => update.Reason == ChangeReason.Update), "Should be 99 updates");
            1.Should().Be(updates.Count(update => update.Reason == ChangeReason.Add), "Should be 1 add");
            100.Should().Be(updates.Count, "Should be 100 updates");
        }
        public void BatchSuccessiveUpdates()
        {
            Person[] people = Enumerable.Range(1, 100).Select(i => new Person("Name1", i)).ToArray();
            _updater.AddOrUpdate(people);

            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            Assert.AreEqual(new Person("Name1", 100), _cache.Lookup("Name1").Value);
            Assert.AreEqual(1, _cache.Count, "Sucessive updates should replace cache value");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Update), 99, "Should be 99 updates");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Add), 1, "Should be 1 add");
            Assert.AreEqual(updates.Count, 100, "Should be 100 updates");
        }
Exemplo n.º 5
0
        public void CanRemove()
        {
            const string key = "Adult1";

            var person = new Person(key, 50);

            _updater.AddOrUpdate(person);
            _updater.Remove(person);
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            _cache.Count.Should().Be(0);
            1.Should().Be(updates.Count(update => update.Reason == ChangeReason.Add), "Should be 1 add");
            1.Should().Be(updates.Count(update => update.Reason == ChangeReason.Remove), "Should be 1 remove");
            2.Should().Be(updates.Count, "Should be 2 updates");
        }
Exemplo n.º 6
0
        public void Remove()
        {
            const string key = "Adult1";

            var person = new Person(key, 50);

            _updater.AddOrUpdate(person, key);
            _updater.Remove(key);
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            Assert.AreEqual(0, _cache.Count);
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Add), 1, "Should be 1 add");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Remove), 1, "Should be 1 remove");
            Assert.AreEqual(updates.Count, 2, "Should be 2 updates");
        }
Exemplo n.º 7
0
        public void CanUpdate()
        {
            const string key = "Adult1";

            var newperson = new Person(key, 50);
            var updated   = new Person(key, 51);

            _updater.AddOrUpdate(newperson);
            _updater.AddOrUpdate(updated);
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            _cache.Lookup(key).Value.Should().Be(updated);
            _cache.Count.Should().Be(1);
            1.Should().Be(updates.Count(update => update.Reason == ChangeReason.Add), "Should be 1 adds");
            1.Should().Be(updates.Count(update => update.Reason == ChangeReason.Update), "Should be 1 update");
            2.Should().Be(updates.Count, "Should be 2 updates");
        }
Exemplo n.º 8
0
        public void Update()
        {
            const string key = "Adult1";

            var newperson = new Person(key, 50);
            var updated   = new Person(key, 51);

            _updater.AddOrUpdate(newperson, key);
            _updater.AddOrUpdate(updated, key);
            IChangeSet <Person, string> updates = _updater.AsChangeSet();

            Assert.AreEqual(updated, _cache.Lookup(key).Value);
            Assert.AreEqual(1, _cache.Count);
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Add), 1, "Should be 1 adds");
            Assert.AreEqual(updates.Count(update => update.Reason == ChangeReason.Update), 1, "Should be 1 update");
            Assert.AreEqual(updates.Count, 2, "Should be 2 updates");
        }