コード例 #1
0
        public async Task Redis_Should_AddAndGetSimpleItem()
        {
            var ds = GetValidStream();

            var record = new DataStreamRecord()
            {
                DeviceId  = DEVICE_ID,
                StreamId  = ds.Id,
                StreamKey = ds.Key
            };

            var originalTimeStamp = DateTime.UtcNow.ToJSONString();

            record.Timestamp = originalTimeStamp;
            record.Data.Add("int1", 100);
            record.Data.Add("dec1", 100.12);
            record.Data.Add("str1", "hello world");

            Assert.IsTrue((await _redisConnector.AddItemAsync(record)).Successful);

            var result = await _redisConnector.GetItemsAsync(DEVICE_ID, new Core.Models.UIMetaData.ListRequest());

            Assert.IsTrue(result.Successful);
            Assert.AreEqual(1, result.Model.Count());

            Assert.AreEqual(originalTimeStamp, result.Model.First().Timestamp);
            Assert.AreEqual(Convert.ToInt32(100), Convert.ToInt32(result.Model.First()["int1"]));
            Assert.AreEqual(Math.Round(100.12, 2), Math.Round(Convert.ToDouble(result.Model.First()["dec1"]), 2));
            Assert.AreEqual("hello world", result.Model.First()["str1"]);
        }