public async Task SingleEvent()
        {
            ServiceCancellation cancelSource = new ServiceCancellation(CancellationToken.None);
            MockReliableStateManager stateManager = new MockReliableStateManager();

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

            IReliableQueue<DeviceEventSeries> queue =
                await stateManager.GetOrAddAsync<IReliableQueue<DeviceEventSeries>>(DataService.EventQueueName);

            string expectedDeviceId = "some-device";
            DeviceEvent expectedDeviceEvent = new DeviceEvent(new DateTimeOffset(1, TimeSpan.Zero));

            EventsController target = new EventsController(stateManager, statefulServiceContext, cancelSource);

            IActionResult result = await target.Post(expectedDeviceId, new[] {expectedDeviceEvent});

            Assert.True(result is OkResult);

            using (ITransaction tx = stateManager.CreateTransaction())
            {
                ConditionalValue<DeviceEvent> actualStoredEvent = await store.TryGetValueAsync(tx, expectedDeviceId);
                ConditionalValue<DeviceEventSeries> actualQueuedEvent = await queue.TryDequeueAsync(tx);

                Assert.True(actualStoredEvent.HasValue);
                Assert.Equal(expectedDeviceEvent.Timestamp, actualStoredEvent.Value.Timestamp);

                Assert.True(actualQueuedEvent.HasValue);
                Assert.Equal(expectedDeviceEvent.Timestamp, actualQueuedEvent.Value.Events.First().Timestamp);

                await tx.CommitAsync();
            }
        }
        public async Task AddMostRecentEvent()
        {
            ServiceCancellation cancelSource = new ServiceCancellation(CancellationToken.None);
            MockReliableStateManager stateManager = new MockReliableStateManager();

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

            IReliableQueue<DeviceEventSeries> queue =
                await stateManager.GetOrAddAsync<IReliableQueue<DeviceEventSeries>>(DataService.EventQueueName);

            string expectedDeviceId = "some-device";

            List<DeviceEvent> expectedDeviceList = new List<DeviceEvent>();
            DeviceEvent expectedDeviceEvent = new DeviceEvent(new DateTimeOffset(100, TimeSpan.Zero));
            for (int i = 0; i < 10; ++i)
            {
                expectedDeviceList.Add(new DeviceEvent(new DateTimeOffset(i, TimeSpan.Zero)));
            }
            expectedDeviceList.Insert(4, expectedDeviceEvent);

            EventsController target = new EventsController(stateManager, statefulServiceContext, cancelSource);

            IActionResult result = await target.Post(expectedDeviceId, expectedDeviceList);

            Assert.True(result is OkResult);

            using (ITransaction tx = stateManager.CreateTransaction())
            {
                ConditionalValue<DeviceEvent> actualStoredEvent = await store.TryGetValueAsync(tx, expectedDeviceId);
                ConditionalValue<DeviceEventSeries> actualQueuedEvent = await queue.TryDequeueAsync(tx);

                Assert.True(actualStoredEvent.HasValue);
                Assert.Equal(expectedDeviceEvent.Timestamp, actualStoredEvent.Value.Timestamp);

                Assert.True(actualQueuedEvent.HasValue);
                Assert.True(actualQueuedEvent.Value.Events.Select(x => x.Timestamp).SequenceEqual(expectedDeviceList.Select(x => x.Timestamp)));

                await tx.CommitAsync();
            }
        }