Ejemplo n.º 1
0
        public async Task GetAll()
        {
            MockApplicationLifetime  appLifetime  = new MockApplicationLifetime();
            MockReliableStateManager stateManager = new MockReliableStateManager();

            IReliableDictionary <string, DeviceEvent> store =
                await stateManager.GetOrAddAsync <IReliableDictionary <string, DeviceEvent> >(DataService.EventDictionaryName);

            Dictionary <string, DeviceEvent> expected = new Dictionary <string, DeviceEvent>();

            expected.Add("device1", new DeviceEvent(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromMinutes(1))));
            expected.Add("device2", new DeviceEvent(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromMinutes(2))));


            using (ITransaction tx = stateManager.CreateTransaction())
            {
                foreach (var item in expected)
                {
                    await store.SetAsync(tx, item.Key, item.Value);
                }
            }

            DevicesController target = new DevicesController(stateManager, appLifetime);
            IActionResult     result = await target.GetAsync();

            Assert.True(result is OkObjectResult);

            IEnumerable <dynamic> actual = ((OkObjectResult)result).Value as IEnumerable <dynamic>;

            foreach (dynamic item in actual)
            {
                Assert.Equal <DateTimeOffset>(expected[item.Id].Timestamp, item.Timestamp);
            }
        }
Ejemplo n.º 2
0
        public async Task GetAllEmpty()
        {
            MockApplicationLifetime  appLifetime  = new MockApplicationLifetime();
            MockReliableStateManager stateManager = new MockReliableStateManager();

            IReliableDictionary <string, DeviceEvent> store =
                await stateManager.GetOrAddAsync <IReliableDictionary <string, DeviceEvent> >(DataService.EventDictionaryName);

            DevicesController target = new DevicesController(stateManager, appLifetime);
            IActionResult     result = await target.GetAsync();

            Assert.True(result is OkObjectResult);

            IEnumerable <dynamic> actual = ((OkObjectResult)result).Value as IEnumerable <dynamic>;

            Assert.False(actual.Any());
        }