public void CanGetWithSync()
        {
            var apiEntity1 = new ApiSample
            {
                Id = Guid.NewGuid()
            };
            var apiEntity2 = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            var sampleController = new SampleController(this.service);
            var apiSync          = sampleController.GetAsync(-1).Result;

            Assert.AreEqual(0, apiSync.LastSync);
            Assert.AreEqual(0, apiSync.Data.Length);
            Assert.AreEqual(0, apiSync.DeletedData.Length);

            this.service.WriteAsync(apiEntity1).Wait();
            apiSync = sampleController.GetAsync(apiSync.LastSync).Result;
            Assert.AreEqual(1, apiSync.LastSync);
            Assert.AreEqual(1, apiSync.Data.Length);
            Assert.AreEqual(apiEntity1.Id, apiSync.Data[0].Id);
            Assert.AreEqual(0, apiSync.DeletedData.Length);

            this.service.WriteAsync(apiEntity2).Wait();
            this.service.RemoveAsync(apiEntity1).Wait();
            apiSync = sampleController.GetAsync(apiSync.LastSync).Result;
            Assert.AreEqual(3, apiSync.LastSync);
            Assert.AreEqual(1, apiSync.Data.Length);
            Assert.AreEqual(apiEntity2.Id, apiSync.Data[0].Id);
            Assert.AreEqual(1, apiSync.DeletedData.Length);
            Assert.AreEqual(apiEntity1.Id, apiSync.DeletedData[0]);
        }
Exemplo n.º 2
0
        public void CanRemoveEntities()
        {
            var apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity3 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };

            service.Write(apiEntity1);
            service.Remove(apiEntity1);
            var readedEntities = service.Read(x => !x.IsDeleted);

            Assert.AreEqual(0, readedEntities.Length);

            service.Write(new[] { apiEntity2, apiEntity3 });
            service.Remove(new[] { apiEntity2, apiEntity3 });
            readedEntities = service.Read(x => !x.IsDeleted);
            Assert.AreEqual(0, readedEntities.Length);
        }
Exemplo n.º 3
0
        public void CanReadSyncedDataWithFilter()
        {
            ApiSample[] apiEntities;
            Guid[]      deletedIds;
            var         apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "1"
            };

            service.Write(apiEntity1);

            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "2"
            };

            service.Write(apiEntity2);

            var sync = service.ReadSyncedData(0, out apiEntities, out deletedIds, x => x.SomeData == "2");

            Assert.AreEqual(1, apiEntities.Length);
            Assert.AreEqual(2, sync);
        }
Exemplo n.º 4
0
        public void CanRemoveEntities()
        {
            var apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity3 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };

            this.service.WriteAsync(apiEntity1).Wait();
            this.service.RemoveAsync(apiEntity1).Wait();
            var readedEntities = this.service.ReadAsync(x => !x.IsDeleted).Result;

            Assert.AreEqual(0, readedEntities.Count);

            this.service.WriteAsync(new[] { apiEntity2, apiEntity3 }).Wait();
            this.service.RemoveAsync(new[] { apiEntity2, apiEntity3 }).Wait();
            readedEntities = this.service.ReadAsync(x => !x.IsDeleted).Result;
            Assert.AreEqual(0, readedEntities.Count);
        }
        public async Task CanRemoveEntitiesAsync()
        {
            var apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };
            var apiEntity3 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "testData"
            };

            await service.WriteAsync(apiEntity1);

            await service.RemoveAsync(apiEntity1);

            var readedEntities = await service.ReadAsync(x => !x.IsDeleted);

            Assert.AreEqual(0, readedEntities.Length);

            await service.WriteAsync(new[] { apiEntity2, apiEntity3 });

            await service.RemoveAsync(new[] { apiEntity2, apiEntity3 });

            readedEntities = await service.ReadAsync(x => !x.IsDeleted);

            Assert.AreEqual(0, readedEntities.Length);
        }
Exemplo n.º 6
0
        public void ExistsIsCorrect()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            this.service.WriteAsync(apiEntity).Wait();
            Assert.IsTrue(this.service.ExistsAsync(apiEntity.Id).Result);
            Assert.IsFalse(this.service.ExistsAsync(Guid.NewGuid()).Result);
        }
Exemplo n.º 7
0
        public void ExistsIsCorrect()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            service.Write(apiEntity);
            Assert.IsTrue(service.Exists(apiEntity.Id));
            Assert.IsFalse(service.Exists(Guid.NewGuid()));
        }
        public void CanGetById()
        {
            var apiEntity = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            this.service.WriteAsync(apiEntity).Wait();
            var sampleController = new SampleController(this.service);
            var resultApiEntity  = sampleController.GetAsync(apiEntity.Id).Result;

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, resultApiEntity));
        }
Exemplo n.º 9
0
        public void CanGetById()
        {
            var apiEntity = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            service.Write(apiEntity);
            var sampleController = new SampleController(service);
            var resultApiEntity  = sampleController.Get(apiEntity.Id);

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, resultApiEntity));
        }
Exemplo n.º 10
0
        public void CanWriteAndRead()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            this.service.WriteAsync(apiEntity).Wait();
            var readedApiEntity = this.service.ReadAsync(apiEntity.Id).Result;

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, readedApiEntity));
        }
Exemplo n.º 11
0
        public void CanWriteAndRead()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            service.Write(apiEntity);
            var readedApiEntity = service.Read(apiEntity.Id);

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, readedApiEntity));
        }
Exemplo n.º 12
0
        public async Task ExistsIsCorrectAsync()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            await service.WriteAsync(apiEntity);

            Assert.IsTrue(await service.ExistsAsync(apiEntity.Id));
            Assert.IsFalse(await service.ExistsAsync(Guid.NewGuid()));
        }
Exemplo n.º 13
0
        public async Task CanWriteAndReadAsync()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            await service.WriteAsync(apiEntity);

            var readedApiEntity = await service.ReadAsync(apiEntity.Id);

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, readedApiEntity));
        }
Exemplo n.º 14
0
        public void CanPostApiEntity()
        {
            var apiEntity = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            var sampleController = new SampleController(service);

            sampleController.Post(apiEntity);

            var readedEtity = service.Read(apiEntity.Id);

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, readedEtity));
        }
        public void CanPostApiEntity()
        {
            var apiEntity = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            var sampleController = new SampleController(this.service);

            sampleController.PostAsync(apiEntity).Wait();

            var readedEtity = this.service.ReadAsync(apiEntity.Id).Result;

            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, readedEtity));
        }
Exemplo n.º 16
0
        public void TryReadIsCorrect()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            service.Write(apiEntity);
            ApiSample resultApiEntity;
            var       readResult = service.TryRead(apiEntity.Id, out resultApiEntity);

            Assert.IsTrue(readResult);
            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, resultApiEntity));

            readResult = service.TryRead(Guid.NewGuid(), out resultApiEntity);
            Assert.IsFalse(readResult);
            Assert.AreEqual(default(ApiSample), resultApiEntity);
        }
Exemplo n.º 17
0
        public async Task CanReadSyncedDataWithFilterAsync()
        {
            var apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "1"
            };
            await service.WriteAsync(apiEntity1);

            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "2"
            };
            await service.WriteAsync(apiEntity2);

            var syncResult = await service.ReadSyncedDataAsync(0, x => x.SomeData == "2");

            Assert.AreEqual(1, syncResult.NewData.Length);
            Assert.AreEqual(2, syncResult.LastSync);
        }
Exemplo n.º 18
0
        public async Task CanReadSyncedDataAsync()
        {
            var syncResult = await service.ReadSyncedDataAsync(0);

            Assert.AreEqual(0, syncResult.LastSync);

            var apiEntity1 = new ApiSample
            {
                Id = Guid.NewGuid()
            };
            await service.WriteAsync(apiEntity1);

            var apiEntity2 = new ApiSample
            {
                Id = Guid.NewGuid()
            };
            await service.WriteAsync(apiEntity2);

            syncResult = await service.ReadSyncedDataAsync(syncResult.LastSync);

            var apiEntities = syncResult.NewData;

            Assert.AreEqual(2, apiEntities.Length);
            Assert.AreEqual(2, syncResult.LastSync);

            var previousSync = syncResult.LastSync;

            syncResult = await service.ReadSyncedDataAsync(syncResult.LastSync);

            Assert.AreEqual(previousSync, syncResult.LastSync);

            await service.RemoveAsync(apiEntity2);

            syncResult = await service.ReadSyncedDataAsync(syncResult.LastSync);

            var deletedIds = syncResult.DeletedIds;

            Assert.AreEqual(1, deletedIds.Length);
            Assert.AreEqual(3, syncResult.LastSync);
        }
Exemplo n.º 19
0
        public void CanReadSyncedData()
        {
            ApiSample[] apiEntities;
            Guid[]      deletedIds;
            var         sync = service.ReadSyncedData(0, out apiEntities, out deletedIds);

            Assert.AreEqual(0, sync);

            var apiEntity1 = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            service.Write(apiEntity1);

            var apiEntity2 = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            service.Write(apiEntity2);

            sync = service.ReadSyncedData(sync, out apiEntities, out deletedIds);

            Assert.AreEqual(2, apiEntities.Length);
            Assert.AreEqual(2, sync);

            var previousSync = sync;

            sync = service.ReadSyncedData(sync, out apiEntities, out deletedIds);

            Assert.AreEqual(previousSync, sync);

            service.Remove(apiEntity2);
            sync = service.ReadSyncedData(sync, out apiEntities, out deletedIds);
            Assert.AreEqual(1, deletedIds.Length);
            Assert.AreEqual(3, sync);
        }
Exemplo n.º 20
0
        public void CanReadSyncedDataWithFilter()
        {
            var apiEntity1 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "1"
            };

            this.service.WriteAsync(apiEntity1).Wait();

            var apiEntity2 = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "2"
            };

            this.service.WriteAsync(apiEntity2).Wait();

            var apiSync = this.service.ReadSyncedDataAsync(0, x => x.SomeData == "2").Result;

            Assert.AreEqual(1, apiSync.Data.Length);
            Assert.AreEqual(2, apiSync.LastSync);
        }
Exemplo n.º 21
0
        public async Task TryReadIsCorrectAsync()
        {
            var apiEntity = new ApiSample
            {
                Id       = Guid.NewGuid(),
                SomeData = "test"
            };

            await service.WriteAsync(apiEntity);

            var readResult = await service.TryReadAsync(apiEntity.Id);

            var resultApiEntity = readResult.Item2;

            Assert.IsTrue(readResult.Item1);
            Assert.IsTrue(ObjectsComparer.AreEqual(apiEntity, resultApiEntity));

            readResult = await service.TryReadAsync(Guid.NewGuid());

            resultApiEntity = readResult.Item2;
            Assert.IsFalse(readResult.Item1);
            Assert.AreEqual(default(ApiSample), resultApiEntity);
        }
Exemplo n.º 22
0
        public void CanReadSyncedData()
        {
            var apiSync = this.service.ReadSyncedDataAsync(0).Result;

            Assert.AreEqual(0, apiSync.LastSync);

            var apiEntity1 = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            this.service.WriteAsync(apiEntity1).Wait();

            var apiEntity2 = new ApiSample
            {
                Id = Guid.NewGuid()
            };

            this.service.WriteAsync(apiEntity2).Wait();

            apiSync = this.service.ReadSyncedDataAsync(apiSync.LastSync).Result;

            Assert.AreEqual(2, apiSync.Data.Length);
            Assert.AreEqual(2, apiSync.LastSync);

            var previousSync = apiSync.LastSync;

            apiSync = this.service.ReadSyncedDataAsync(apiSync.LastSync).Result;

            Assert.AreEqual(previousSync, apiSync.LastSync);

            this.service.RemoveAsync(apiEntity2).Wait();
            apiSync = this.service.ReadSyncedDataAsync(apiSync.LastSync).Result;
            Assert.AreEqual(1, apiSync.DeletedData.Length);
            Assert.AreEqual(3, apiSync.LastSync);
        }
Exemplo n.º 23
0
 public void Post(ApiSample apiSample)
 {
     service.Write(apiSample);
 }
 public async Task PostAsync(ApiSample apiSample)
 {
     await this.service.WriteAsync(apiSample).ConfigureAwait(false);
 }