Exemplo n.º 1
0
        public void detect_changes_negative()
        {
            var target = Target.Random();
            var entity = new TrackedEntity(target.Id, new JilSerializer(), typeof(Target), target);

            entity.DetectChange().ShouldBeNull();
        }
Exemplo n.º 2
0
        public void change_is_cleared()
        {
            var target = Target.Random();
            var entity = new TrackedEntity(target.Id, new TestsSerializer(), typeof(Target), target,null);
            target.Long++;

            var change = entity.DetectChange();
            change.ChangeCommitted();

            entity.DetectChange().ShouldBeNull();
        }
Exemplo n.º 3
0
        public void detect_changes_positive()
        {
            var target = Target.Random();
            var entity = new TrackedEntity(target.Id, new JilSerializer(), typeof(Target), target);
            target.Long++;

            var change = entity.DetectChange();

            change.ShouldNotBeNull();
            change.DocumentType.ShouldBe(typeof(Target));
            change.Id.ShouldBe(target.Id);
            change.Json.ShouldBe(new JilSerializer().ToJson(target));
        }
Exemplo n.º 4
0
        public async Task <T> GetAsync <T>(object id, Func <CancellationToken, Task <FetchResult <T> > > result, CancellationToken token = default(CancellationToken)) where T : class
        {
            var dict     = _objects[typeof(T)];
            var hashCode = id.GetHashCode();

            if (dict.ContainsKey(hashCode))
            {
                return(dict[hashCode].Document.As <T>());
            }

            var fetchResult = await result(token).ConfigureAwait(false);

            if (fetchResult == null)
            {
                return(null);
            }

            dict[hashCode] = new TrackedEntity(id, typeof(T), fetchResult.Document, fetchResult.Json, _serializer);

            return(fetchResult?.Document);
        }
Exemplo n.º 5
0
 public void detect_changes_with_no_document()
 {
     var entity = new TrackedEntity(Guid.NewGuid(), new JilSerializer(), typeof (Target), null);
     entity.DetectChange().ShouldBeNull();
 }
Exemplo n.º 6
0
 public DocumentChange(TrackedEntity entity, string json)
 {
     _entity = entity;
     Json = json;
     
 }
Exemplo n.º 7
0
 public DocumentChange(TrackedEntity entity, string json)
 {
     _entity = entity;
     Json    = json;
 }