public void write_multiple_calls_with_json_supplied() { // Just forcing the table and schema objects to be created var initialTarget = Target.Random(); theSession.Store(initialTarget); theSession.SaveChanges(); var batch = theStore.Advanced.CreateUpdateBatch(); var target1 = Target.Random(); var target2 = Target.Random(); var target3 = Target.Random(); var upsert = theMapping.UpsertFunction; var serializer = new TestsSerializer(); batch.Sproc(upsert).Param("docId", target1.Id).JsonBody("doc", serializer.ToJson(target1)).Param("docVersion", Guid.NewGuid()).Param("docDotNetType", typeof(Target).AssemblyQualifiedName); batch.Sproc(upsert).Param("docId", target2.Id).JsonBody("doc", serializer.ToJson(target2)).Param("docVersion", Guid.NewGuid()).Param("docDotNetType", typeof(Target).AssemblyQualifiedName); batch.Sproc(upsert).Param("docId", target3.Id).JsonBody("doc", serializer.ToJson(target3)).Param("docVersion", Guid.NewGuid()).Param("docDotNetType", typeof(Target).AssemblyQualifiedName); batch.Execute(); batch.Connection.Dispose(); var targets = theSession.Query <Target>().ToArray(); targets.Any(x => x.Id == target1.Id).ShouldBeTrue(); targets.Any(x => x.Id == target2.Id).ShouldBeTrue(); targets.Any(x => x.Id == target3.Id).ShouldBeTrue(); }
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 get_with_json() { var serializer = new TestsSerializer(); var target = new Target(); var json = serializer.ToJson(target); var map = new NulloIdentityMap(serializer); var target2 = map.Get<Target>(target.Id, json, null); target2.Id.ShouldBe(target.Id); }
public void remove_item() { var target = Target.Random(); var target2 = Target.Random(); target2.Id = target.Id; var serializer = new TestsSerializer(); var map = new IdentityMap(serializer, null); var target3 = map.Get<Target>(target.Id, serializer.ToJson(target), null); // now remove it map.Remove<Target>(target.Id); var target4 = map.Get<Target>(target.Id, serializer.ToJson(target2), null); target4.ShouldNotBeNull(); target4.ShouldNotBeTheSameAs(target3); }
public void lazy_get_hit() { var serializer = new TestsSerializer(); var target = new Target(); var json = serializer.ToJson(target); var map = new NulloIdentityMap(serializer); var target2 = map.Get <Target>(target.Id, () => new FetchResult <Target>(target, json, null)); target2.Id.ShouldBe(target.Id); }
public void lazy_get_hit() { var serializer = new TestsSerializer(); var target = new Target(); var json = serializer.ToJson(target); var map = new NulloIdentityMap(serializer); var target2 = map.Get<Target>(target.Id, () => new FetchResult<Target>(target, json, null)); target2.Id.ShouldBe(target.Id); }
public void get_with_json() { var serializer = new TestsSerializer(); var target = new Target(); var json = serializer.ToJson(target); var map = new NulloIdentityMap(serializer); var target2 = map.Get <Target>(target.Id, json.ToReader(), null); target2.Id.ShouldBe(target.Id); }
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 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 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).ToReader(), null); var target3 = map.Get <Target>(target.Id, serializer.ToJson(target).ToReader(), null); var target4 = map.Get <Target>(target.Id, serializer.ToJson(target).ToReader(), null); var target5 = map.Get <Target>(target.Id, serializer.ToJson(target).ToReader(), 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); }
public void get_value_on_first_request() { var target = Target.Random(); var serializer = new TestsSerializer(); var map = new IdentityMap(serializer, null); var target2 = map.Get <Target>(target.Id, serializer.ToJson(target), null); target2.Id.ShouldBe(target.Id); target2.ShouldNotBeTheSameAs(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), null); target2.Id.ShouldBe(target.Id); target2.ShouldNotBeTheSameAs(target); }
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); }
public void get_value_on_first_request_with_lazy_json() { var target = Target.Random(); var serializer = new TestsSerializer(); var map = new IdentityMap(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, null)); }); 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 TestsSerializer(); 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, null); }); target2.Id.ShouldBe(target.Id); target2.ShouldNotBeTheSameAs(target); }
public void get_value_on_subsequent_requests_with_lazy_json() { var target = Target.Random(); var serializer = new TestsSerializer(); var map = new IdentityMap(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); }
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), null); var b1 = map.Get<Target>(a.Id, serializer.ToJson(b), null); var c1 = map.Get<Target>(a.Id, serializer.ToJson(c), null); var d1 = map.Get<Target>(a.Id, serializer.ToJson(d), null); // 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 IdentityMap(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); }
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), null); a1.Long++; var b1 = map.Get<Target>(b.Id, serializer.ToJson(b), null); var c1 = map.Get<Target>(c.Id, serializer.ToJson(c), null); c1.Long++; var d1 = map.Get<Target>(d.Id, serializer.ToJson(d), 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 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), null); a1.Long++; var b1 = map.Get<Target>(b.Id, serializer.ToJson(b), null); var c1 = map.Get<Target>(c.Id, serializer.ToJson(c), null); c1.Long++; var d1 = map.Get<Target>(d.Id, serializer.ToJson(d), null); var changes = map.DetectChanges(); changes.Each(x => x.ChangeCommitted()); map.DetectChanges().Any().ShouldBeFalse(); }