示例#1
0
        public async Task TestReplaceExactNonExistentRecordReturnsFalseDoesNotCreateRecord()
        {
            bool res = await PocoView.ReplaceAsync(null, GetPoco(1, "1"), GetPoco(1, "2"));

            Assert.IsFalse(res);
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(1)));
        }
示例#2
0
        public async Task TestGetAndDeleteNonExistentRecordReturnsNull()
        {
            Poco?res = await PocoView.GetAndDeleteAsync(null, GetPoco(2, "2"));

            Assert.IsNull(res);
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(2)));
        }
示例#3
0
        public async Task TestDeleteExistingRecordReturnsTrue()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            Assert.IsTrue(await PocoView.DeleteAsync(null, GetPoco(1)));
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(1)));
        }
示例#4
0
        public async Task TestInsertAllDoesNotOverwriteExistingDataReturnsSkippedTuples()
        {
            var existing = new[] { GetPoco(2, "x"), GetPoco(4, "y") }.ToDictionary(x => x.Key);
            await PocoView.InsertAllAsync(null, existing.Values);

            var ids     = Enumerable.Range(1, 10).ToList();
            var records = ids.Select(x => GetPoco(x, x.ToString(CultureInfo.InvariantCulture)));

            IList <Poco> skipped = await PocoView.InsertAllAsync(null, records);

            var skippedArr = skipped.OrderBy(x => x.Key).ToArray();

            Assert.AreEqual(2, skippedArr.Length);
            Assert.AreEqual(2, skippedArr[0].Key);
            Assert.AreEqual("2", skippedArr[0].Val);

            Assert.AreEqual(4, skippedArr[1].Key);
            Assert.AreEqual("4", skippedArr[1].Val);

            foreach (var id in ids)
            {
                var res = await PocoView.GetAsync(null, GetPoco(id));

                if (existing.TryGetValue(res !.Key, out var old))
                {
                    Assert.AreEqual(old.Val, res.Val);
                }
示例#5
0
        public async Task TestInsertNonExistentKeyCreatesRecordReturnsTrue()
        {
            var res = await PocoView.InsertAsync(null, GetPoco(1, "1"));

            Assert.IsTrue(res);
            Assert.IsTrue(await PocoView.GetAsync(null, GetPoco(1)) != null);
        }
示例#6
0
        public async Task TestDeleteExactSameKeyAndValueReturnsTrueDeletesRecord()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            Assert.IsTrue(await PocoView.DeleteExactAsync(null, GetPoco(1, "1")));
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(1)));
        }
示例#7
0
        public async Task TestGetAndReplaceNonExistentRecordReturnsNullDoesNotCreateRecord()
        {
            Poco?res = await PocoView.GetAndReplaceAsync(null, GetPoco(1, "1"));

            Assert.IsNull(res);
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(1)));
        }
示例#8
0
        public async Task TestGetAndUpsertNonExistentRecordReturnsNull()
        {
            Poco?res = await PocoView.GetAndUpsertAsync(null, GetPoco(2, "2"));

            Assert.IsNull(res);
            Assert.AreEqual("2", (await PocoView.GetAsync(null, GetPoco(2))) !.Val);
        }
示例#9
0
        public async Task TestDeleteExactExistingKeyDifferentValueReturnsFalseDoesNotDelete()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            Assert.IsFalse(await PocoView.DeleteExactAsync(null, GetPoco(1)));
            Assert.IsFalse(await PocoView.DeleteExactAsync(null, GetPoco(1, "2")));
            Assert.IsNotNull(await PocoView.GetAsync(null, GetPoco(1)));
        }
示例#10
0
        public async Task TestReplaceExistingRecordReturnsTrueOverwrites()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            bool res = await PocoView.ReplaceAsync(null, GetPoco(1, "2"));

            Assert.IsTrue(res);
            Assert.AreEqual("2", (await PocoView.GetAsync(null, GetPoco(1))) !.Val);
        }
示例#11
0
        public async Task TestReplaceExactExistingRecordWithSameValueReturnsTrueReplacesOld()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            bool res = await PocoView.ReplaceAsync(null, GetPoco(1, "1"), GetPoco(1, "22"));

            Assert.IsTrue(res);
            Assert.AreEqual("22", (await PocoView.GetAsync(null, GetPoco(1))) !.Val);
        }
示例#12
0
        public async Task TestReplaceExactExistingRecordWithDifferentValueReturnsFalseDoesNotReplace()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            bool res = await PocoView.ReplaceAsync(null, GetPoco(1, "11"), GetPoco(1, "22"));

            Assert.IsFalse(res);
            Assert.AreEqual("1", (await PocoView.GetAsync(null, GetPoco(1))) !.Val);
        }
示例#13
0
        public async Task TestInsertExistingKeyDoesNotOverwriteReturnsFalse()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            var res = await PocoView.InsertAsync(null, GetPoco(1, "2"));

            Assert.IsFalse(res);
            Assert.AreEqual("1", (await PocoView.GetAsync(null, GetPoco(1))) !.Val);
        }
示例#14
0
        public async Task TestGetAndReplaceExistingRecordReturnsOldOverwrites()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "1"));

            Poco?res = await PocoView.GetAndReplaceAsync(null, GetPoco(1, "2"));

            Assert.IsNotNull(res);
            Assert.AreEqual("1", res !.Val);
            Assert.AreEqual("2", (await PocoView.GetAsync(null, GetPoco(1))) !.Val);
        }
示例#15
0
        public async Task TestGetAndDeleteExistingRecordRemovesAndReturns()
        {
            await PocoView.UpsertAsync(null, GetPoco(2, "2"));

            Poco?res = await PocoView.GetAndDeleteAsync(null, GetPoco(2));

            Assert.IsNotNull(res);
            Assert.AreEqual(2, res !.Key);
            Assert.AreEqual("2", res.Val);
            Assert.IsNull(await PocoView.GetAsync(null, GetPoco(2)));
        }
示例#16
0
        public async Task TestGetAndUpsertExistingRecordOverwritesAndReturns()
        {
            await PocoView.UpsertAsync(null, GetPoco(2, "2"));

            Poco?res = await PocoView.GetAndUpsertAsync(null, GetPoco(2, "22"));

            Assert.IsNotNull(res);
            Assert.AreEqual(2, res !.Key);
            Assert.AreEqual("2", res.Val);
            Assert.AreEqual("22", (await PocoView.GetAsync(null, GetPoco(2))) !.Val);
        }
示例#17
0
        public async Task TestUpsertOverridesPreviousValue()
        {
            var key = GetPoco(1);

            await PocoView.UpsertAsync(null, GetPoco(1, "foo"));

            Assert.AreEqual("foo", (await PocoView.GetAsync(null, key)) !.Val);

            await PocoView.UpsertAsync(null, GetPoco(1, "bar"));

            Assert.AreEqual("bar", (await PocoView.GetAsync(null, key)) !.Val);
        }
示例#18
0
        public async Task TestUpsertAllCreatesRecords()
        {
            var ids     = Enumerable.Range(1, 10).ToList();
            var records = ids.Select(x => GetPoco(x, x.ToString(CultureInfo.InvariantCulture)));

            await PocoView.UpsertAllAsync(null, records);

            foreach (var id in ids)
            {
                var res = await PocoView.GetAsync(null, GetPoco(id));

                Assert.AreEqual(id.ToString(CultureInfo.InvariantCulture), res !.Val);
            }
        }
示例#19
0
        public async Task TestUpsertGet()
        {
            await PocoView.UpsertAsync(null, GetPoco(1, "foo"));

            var keyTuple = GetPoco(1);
            var resTuple = (await PocoView.GetAsync(null, keyTuple)) !;

            Assert.IsNotNull(resTuple);

            Assert.AreEqual(1L, resTuple.Key);
            Assert.AreEqual("foo", resTuple.Val);

            Assert.IsNull(resTuple.UnmappedStr);
            Assert.AreEqual(default(Guid), resTuple.UnmappedId);
        }
示例#20
0
 public async Task TestDeleteExactNonExistentRecordReturnsFalse()
 {
     Assert.IsFalse(await PocoView.DeleteExactAsync(null, GetPoco(-1)));
 }