public void save_is_idempotent()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var update = new UpdateEvent()
            {
                Text = "update"
            };

            _projection.On(insert);
            _projection.On(update);

            update.Text = "skipped update";
            _projection.On(update);

            var loaded = _collection.Where(x => x.Id == update.AggregateId).Single();

            Assert.AreEqual(2, loaded.ProcessedEvents.Count);
            Assert.IsTrue(loaded.ProcessedEvents.Contains(insert.MessageId));
            Assert.IsTrue(loaded.ProcessedEvents.Contains(update.MessageId));
            Assert.AreEqual("update", loaded.Text);
            Assert.AreEqual(2, SpyNotifier.Counter);
        }
        public void upsert_update_old_readmodel()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var update = new InsertEvent()
            {
                Text = "one"
            };

            update.AssignIdForTest(insert.AggregateId);

            _collection.Insert(insert, new MyReadModel()
            {
                Id   = insert.AggregateId,
                Text = "created"
            });

            _collection.Upsert(
                update,
                update.AggregateId,
                () => new MyReadModel()
            {
                Id   = insert.AggregateId,
                Text = "created"
            },
                r => { r.Text = "updated"; }
                );

            var saved = _collection.All.FirstOrDefault(x => x.Id == insert.AggregateId);

            Assert.IsNotNull(saved);
            Assert.AreEqual("updated", saved.Text);
        }
Exemplo n.º 3
0
        public void delete_is_idempotent()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var delete = new DeleteEvent();

            _projection.On(insert);
            _projection.On(delete);
            _projection.On(delete);

            var loaded = _collection.FindOneById(delete.AggregateId);

            Assert.IsNull(loaded);
        }
Exemplo n.º 4
0
        public void delete_does_not_generates_multiple_notifications()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var delete = new DeleteEvent();

            _projection.On(insert);
            _projection.On(delete);
            _projection.On(delete);

            var loaded = _collection.FindOneById(delete.AggregateId);

            Assert.AreEqual(2, SpyNotifier.Counter);
        }
Exemplo n.º 5
0
        public async Task delete_does_not_generates_multiple_notifications()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var delete = new DeleteEvent();

            await _projection.On(insert);

            await _projection.On(delete);

            await _projection.On(delete);

            Assert.AreEqual(2, SpyNotifier.Counter);
        }
        public void insert_is_idempotent()
        {
            var evt = new InsertEvent()
            {
                Text = "one"
            };

            _projection.On(evt);
            evt.Text = "two";
            _projection.On(evt);

            var loaded = _collection.Where(x => x.Id == evt.AggregateId).Single();

            Assert.AreEqual(1, loaded.ProcessedEvents.Count);
            Assert.IsTrue(loaded.ProcessedEvents.Contains(evt.MessageId));
            Assert.AreEqual("one", loaded.Text);
            Assert.AreEqual(1, SpyNotifier.Counter);
        }
Exemplo n.º 7
0
        public async Task delete_is_idempotent()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };
            var delete = new DeleteEvent();

            await _projection.On(insert);

            await _projection.On(delete);

            await _projection.On(delete);

            var loaded = await _collection.FindOneByIdAsync(delete.AggregateId.AsString());

            Assert.IsNull(loaded);
        }
Exemplo n.º 8
0
        public async Task upsert_create_new_readmodel()
        {
            var insert = new InsertEvent()
            {
                Text = "one"
            };

            await _collection.UpsertAsync(
                insert,
                insert.AggregateId.AsString(),
                () => new MyReadModel()
            {
                Id   = insert.AggregateId.AsString(),
                Text = "created"
            },
                r => { r.Text = "updated"; }
                );

            var saved = _collection.All.FirstOrDefault(x => x.Id == insert.AggregateId.AsString());

            Assert.IsNotNull(saved);
            Assert.AreEqual("created", saved.Text);
        }