コード例 #1
0
        public void PushAddsItemAndRemovesOldestItemIfFull()
        {
            var store = new LimitedStore <int>(2);

            store.Push(11);
            store.Push(12);
            store.Push(13);
            Assert.Contains(12, store.InternalStore);
            Assert.Contains(13, store.InternalStore);
            Assert.DoesNotContain(11, store.InternalStore);
        }
コード例 #2
0
        public void SerializingAndDeserializingLimitedStoreToJsonDoesNotChangeOrderOfQueue()
        {
            var store = new LimitedStore <int>(2);

            store.Push(11);
            store.Push(12);
            store.Push(13);
            Assert.Equal(12, store.Peek());
            var json = JsonSerializer.Serialize(store);
            var deserializedStore = JsonSerializer.Deserialize <LimitedStore <int> >(json);

            Assert.Equal(12, deserializedStore.Peek());
        }
コード例 #3
0
        public void PushAddsItem()
        {
            var store = new LimitedStore <int>();

            store.Push(10);
            Assert.Contains(10, store.InternalStore);
        }
コード例 #4
0
        public void HandleMessage(string message)
        {
            var msg = JsonSerializer.Deserialize <TelegramUpdateDto>(message,
                                                                     new JsonSerializerOptions {
                IgnoreNullValues = true
            });

            if (!msg.Ok || msg.Updates.Count < 1)
            {
                return;
            }

            foreach (var m in msg.Updates)
            {
                if (_storedIds.Contains(m.Message.MessageId))
                {
                    continue;
                }

                _storedIds.Push(m.Message.MessageId);
                Console.WriteLine(
                    $"Received message '{m.Message.Text}' from {m.Message.User.Username} in {m.Message.Chat.Id} ({m.Message.Chat.Username ?? "No name"})");
                HandleNewMessage(m);
            }
        }