public void detect_changes_then_clear_the_changes()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get <Target>(a.Id, serializer.ToJson(a).ToReader(), null);

            a1.Long++;

            var b1 = map.Get <Target>(b.Id, serializer.ToJson(b).ToReader(), null);
            var c1 = map.Get <Target>(c.Id, serializer.ToJson(c).ToReader(), null);

            c1.Long++;

            var d1 = map.Get <Target>(d.Id, serializer.ToJson(d).ToReader(), null);


            var changes = map.DetectChanges();

            changes.Each(x => x.ChangeCommitted());


            map.DetectChanges().Any().ShouldBeFalse();
        }
        public void detect_changes_with_multiple_dirties()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get <Target>(a.Id, serializer.ToJson(a).ToReader(), null);

            a1.Long++;

            var b1 = map.Get <Target>(b.Id, serializer.ToJson(b).ToReader(), null);
            var c1 = map.Get <Target>(c.Id, serializer.ToJson(c).ToReader(), null);

            c1.Long++;

            var d1 = map.Get <Target>(d.Id, serializer.ToJson(d).ToReader(), null);


            var changes = map.DetectChanges();

            changes.Count().ShouldBe(2);
            changes.Any(x => x.Id.As <Guid>() == a1.Id).ShouldBeTrue();
            changes.Any(x => x.Id.As <Guid>() == c1.Id).ShouldBeTrue();
        }
        public void has_negative()
        {
            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Has <Target>(Guid.NewGuid()).ShouldBeFalse();
        }
Exemple #4
0
        public void get_with_miss_in_database()
        {
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Get <Target>(Guid.NewGuid(), () => null).ShouldBeNull();
        }
        public void has_positive()
        {
            var target     = Target.Random();
            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);

            map.Has <Target>(target.Id).ShouldBeTrue();
        }
        public void retrieve()
        {
            var target     = Target.Random();
            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);

            map.Retrieve <Target>(target.Id).ShouldBeTheSameAs(target);
        }
        public void store()
        {
            var target     = Target.Random();
            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);


            map.Get <Target>(target.Id, "".ToReader(), null).ShouldBeTheSameAs(target);
        }
        public void store()
        {
            var target     = Target.Random();
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer);

            map.Store(target.Id, target);


            map.Get <Target>(target.Id, "").ShouldBeTheSameAs(target);
        }
        public void get_value_on_first_request()
        {
            var target = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get <Target>(target.Id, serializer.ToJson(target).ToReader(), null);

            target2.Id.ShouldBe(target.Id);
            target2.ShouldNotBeTheSameAs(target);
        }
        public void get_value_on_first_request()
        {
            var target = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get<Target>(target.Id, serializer.ToJson(target));

            target2.Id.ShouldBe(target.Id);
            target2.ShouldNotBeTheSameAs(target);
        }
        public void get_with_concrete_type()
        {
            var serializer = new JsonNetSerializer();
            var camaro     = new NulloIdentityMapTests.Camaro();

            var json = serializer.ToJson(camaro);

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Get <NulloIdentityMapTests.Car>(camaro.Id, typeof(NulloIdentityMapTests.Camaro), json.ToReader(), null)
            .ShouldBeOfType <NulloIdentityMapTests.Camaro>()
            .Id.ShouldBe(camaro.Id);
        }
        public void get_with_concrete_type()
        {
            var serializer = new JsonNetSerializer();
            var camaro = new NulloIdentityMapTests.Camaro();

            var json = serializer.ToJson(camaro);

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Get<NulloIdentityMapTests.Car>(camaro.Id, typeof(NulloIdentityMapTests.Camaro), json)
                .ShouldBeOfType<NulloIdentityMapTests.Camaro>()
                .Id.ShouldBe(camaro.Id);


        }
Exemple #13
0
        public void get_value_on_first_request_with_lazy_json()
        {
            var target = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var json         = serializer.ToJson(target);
            var clonedTarget = serializer.FromJson <Target>(json);

            var target2 = map.Get <Target>(target.Id, () =>
            {
                return(new FetchResult <Target>(clonedTarget, json));
            });

            target2.Id.ShouldBe(target.Id);
            target2.ShouldNotBeTheSameAs(target);
        }
        public void get_value_on_first_request_with_lazy_json()
        {
            var target = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var json = serializer.ToJson(target);
            var clonedTarget = serializer.FromJson<Target>(json);

            var target2 = map.Get<Target>(target.Id, () =>
            {
                
                return new FetchResult<Target>(clonedTarget, json);
            });

            target2.Id.ShouldBe(target.Id);
            target2.ShouldNotBeTheSameAs(target);
        }
        public void remove_item()
        {
            var target  = Target.Random();
            var target2 = Target.Random();

            target2.Id = target.Id;

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target3 = map.Get <Target>(target.Id, serializer.ToJson(target).ToReader(), null);

            // now remove it
            map.Remove <Target>(target.Id);

            var target4 = map.Get <Target>(target.Id, serializer.ToJson(target2).ToReader(), null);

            target4.ShouldNotBeNull();
            target4.ShouldNotBeTheSameAs(target3);
        }
        public void detect_changes_with_no_changes()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get <Target>(a.Id, serializer.ToJson(a).ToReader(), null);
            var b1 = map.Get <Target>(a.Id, serializer.ToJson(b).ToReader(), null);
            var c1 = map.Get <Target>(a.Id, serializer.ToJson(c).ToReader(), null);
            var d1 = map.Get <Target>(a.Id, serializer.ToJson(d).ToReader(), null);

            // no changes

            map.DetectChanges().Any().ShouldBeFalse();
        }
        public void get_value_on_subsequent_requests()
        {
            var target = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get<Target>(target.Id, serializer.ToJson(target));
            var target3 = map.Get<Target>(target.Id, serializer.ToJson(target));
            var target4 = map.Get<Target>(target.Id, serializer.ToJson(target));
            var target5 = map.Get<Target>(target.Id, serializer.ToJson(target));

            target2.Id.ShouldBe(target.Id);
            target3.Id.ShouldBe(target.Id);
            target4.Id.ShouldBe(target.Id);
            target5.Id.ShouldBe(target.Id);

            target2.ShouldBeTheSameAs(target3);
            target2.ShouldBeTheSameAs(target4);
            target2.ShouldBeTheSameAs(target5);
        }
Exemple #18
0
        public void get_value_on_subsequent_requests()
        {
            var target = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get <Target>(target.Id, serializer.ToJson(target), null);
            var target3 = map.Get <Target>(target.Id, serializer.ToJson(target), null);
            var target4 = map.Get <Target>(target.Id, serializer.ToJson(target), null);
            var target5 = map.Get <Target>(target.Id, serializer.ToJson(target), null);

            target2.Id.ShouldBe(target.Id);
            target3.Id.ShouldBe(target.Id);
            target4.Id.ShouldBe(target.Id);
            target5.Id.ShouldBe(target.Id);

            target2.ShouldBeTheSameAs(target3);
            target2.ShouldBeTheSameAs(target4);
            target2.ShouldBeTheSameAs(target5);
        }
Exemple #19
0
        public void get_value_on_subsequent_requests_with_lazy_json()
        {
            var target = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get <Target>(target.Id, () => new FetchResult <Target>(target, serializer.ToJson(target)));
            var target3 = map.Get <Target>(target.Id, () => new FetchResult <Target>(target, serializer.ToJson(target)));
            var target4 = map.Get <Target>(target.Id, () => new FetchResult <Target>(target, serializer.ToJson(target)));
            var target5 = map.Get <Target>(target.Id, () => new FetchResult <Target>(target, serializer.ToJson(target)));

            target2.Id.ShouldBe(target.Id);
            target3.Id.ShouldBe(target.Id);
            target4.Id.ShouldBe(target.Id);
            target5.Id.ShouldBe(target.Id);

            target2.ShouldBeTheSameAs(target3);
            target2.ShouldBeTheSameAs(target4);
            target2.ShouldBeTheSameAs(target5);
        }
        public void store()
        {
            var target = Target.Random();
            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);


            map.Get<Target>(target.Id, "", null).ShouldBeTheSameAs(target);
        }
        public void retrieve()
        {
            var target = Target.Random();
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);

            map.Retrieve<Target>(target.Id).ShouldBeTheSameAs(target);
        }
        public void has_negative()
        {
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);
            map.Has<Target>(Guid.NewGuid()).ShouldBeFalse();
        }
        public void has_positive()
        {
            var target = Target.Random();
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            map.Store(target.Id, target);

            map.Has<Target>(target.Id).ShouldBeTrue();

        }
        public void get_with_miss_in_database()
        {
            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);
            map.Get<Target>(Guid.NewGuid(), () => null).ShouldBeNull();
        }
        public void remove_item()
        {
            var target = Target.Random();
            var target2 = Target.Random();
            target2.Id = target.Id;

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target3 = map.Get<Target>(target.Id, serializer.ToJson(target));

            // now remove it
            map.Remove<Target>(target.Id);

            var target4 = map.Get<Target>(target.Id, serializer.ToJson(target2));
            target4.ShouldNotBeNull();
            target4.ShouldNotBeTheSameAs(target3);

        }
        public void detect_changes_then_clear_the_changes()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get<Target>(a.Id, serializer.ToJson(a));
            a1.Long++;

            var b1 = map.Get<Target>(b.Id, serializer.ToJson(b));
            var c1 = map.Get<Target>(c.Id, serializer.ToJson(c));
            c1.Long++;

            var d1 = map.Get<Target>(d.Id, serializer.ToJson(d));


            var changes = map.DetectChanges();

            changes.Each(x => x.ChangeCommitted());


            map.DetectChanges().Any().ShouldBeFalse();
        }
        public void detect_changes_with_multiple_dirties()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get<Target>(a.Id, serializer.ToJson(a));
            a1.Long++;

            var b1 = map.Get<Target>(b.Id, serializer.ToJson(b));
            var c1 = map.Get<Target>(c.Id, serializer.ToJson(c));
            c1.Long++;

            var d1 = map.Get<Target>(d.Id, serializer.ToJson(d));


            var changes = map.DetectChanges();
            changes.Count().ShouldBe(2);
            changes.Any(x => x.Id.As<Guid>() == a1.Id).ShouldBeTrue();
            changes.Any(x => x.Id.As<Guid>() == c1.Id).ShouldBeTrue();
        }
        public void detect_changes_with_no_changes()
        {
            var a = Target.Random();
            var b = Target.Random();
            var c = Target.Random();
            var d = Target.Random();

            var serializer = new JilSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);


            var a1 = map.Get<Target>(a.Id, serializer.ToJson(a));
            var b1 = map.Get<Target>(a.Id, serializer.ToJson(b));
            var c1 = map.Get<Target>(a.Id, serializer.ToJson(c));
            var d1 = map.Get<Target>(a.Id, serializer.ToJson(d));

            // no changes

            map.DetectChanges().Any().ShouldBeFalse();
        }
        public void get_value_on_subsequent_requests_with_lazy_json()
        {
            var target = Target.Random();

            var serializer = new TestsSerializer();

            var map = new DirtyTrackingIdentityMap(serializer, null);

            var target2 = map.Get<Target>(target.Id, () => new FetchResult<Target>(target, serializer.ToJson(target), null));
            var target3 = map.Get<Target>(target.Id, () => new FetchResult<Target>(target, serializer.ToJson(target), null));
            var target4 = map.Get<Target>(target.Id, () => new FetchResult<Target>(target, serializer.ToJson(target), null));
            var target5 = map.Get<Target>(target.Id, () => new FetchResult<Target>(target, serializer.ToJson(target), null));

            target2.Id.ShouldBe(target.Id);
            target3.Id.ShouldBe(target.Id);
            target4.Id.ShouldBe(target.Id);
            target5.Id.ShouldBe(target.Id);

            target2.ShouldBeTheSameAs(target3);
            target2.ShouldBeTheSameAs(target4);
            target2.ShouldBeTheSameAs(target5);
        }