Exemple #1
0
        internal void DomainCollectionTests(Messenger m, IKeyed <int, PersonDO> collection)
        {
            GIVEN["a collection and a Messenger"] = () =>
                                                    collection = collection.Create(m = CreateMesseneger(), x => x.ID, x => {
                x.Apply <PersonAdded>((e, c) => c.Add(e));
                x.Apply <PersonChanged>((e, c) => c.Set(e.ID, e));
                x.Apply <PersonRemoved>((e, c) => c.Remove(e.ID));
            });

            WHEN["sending an add event"] = () => m.ApplyChange(new PersonAdded {
                ID = 1, Name = "N1"
            });
            THEN["the item is added"] = () => collection.Should().BeEquivalentTo(new PersonDO {
                ID = 1, Name = "N1"
            });

            WHEN["sending a set event"] = () => m.ApplyChange(new PersonChanged {
                ID = 1, Name = "N2"
            });
            THEN["the item is replaced"] = () => collection.Should().BeEquivalentTo(new PersonDO {
                ID = 1, Name = "N2"
            });

            WHEN["sending a remove event"] = () => m.ApplyChange(new PersonRemoved {
                ID = 1
            });
            THEN["the item is added"] = () => collection.Should().BeEquivalentTo();
        }