Esempio n. 1
0
        public void Persist_WhenCalled()
        {
            var cfg1 = _tracker.Configure <Foo>()
                       .Id(f => f.Int.ToString())
                       .Properties(f => new { f.B, x = f.Timespan })
                       .PersistOn(nameof(Foo.Event1));

            var cfg2 = _tracker.Configure <Foo2>()
                       .PersistOn(nameof(Foo2.DerivedEvent))
                       .Properties(f2 => new { f2.DerivedFooProp1 });

            var foo2 = new Foo2()
            {
                Double          = 123,
                Int             = 321,
                Timespan        = new TimeSpan(1, 2, 3),
                DerivedFooProp1 = "str1",
                DerivedFooProp2 = "str2",
                B = new Bar()
                {
                    Id = Guid.NewGuid(), Str = "BarStr"
                }
            };

            _tracker.Track(foo2);
            _tracker.Persist(foo2);

            Assert.NotSame(cfg1, cfg2);

            var data = _store.GetData(foo2.Int.ToString());

            Assert.Equal(3, data.Count);
            Assert.Equal(foo2.DerivedFooProp1, data["DerivedFooProp1"]);
            Assert.Equal(foo2.Timespan, data["x"]);
            Assert.Equal(foo2.B.Id, (data["B"] as Bar).Id);
            Assert.Equal(foo2.B.Str, (data["B"] as Bar).Str);
        }