Пример #1
0
        public async void HandlesValidBotChanged()
        {
            var bots = new List<BotModel>
            {
                new BotModel { Id = "BOTID1", Name = "NameA" },
                new BotModel { Id = "BOTID2" }
            };

            var mockState = new Mock<IBotState>();
            mockState.Setup(s => s.Bots)
                     .Returns(bots)
                     .Verifiable();

            var message = new BotChanged
            {
                Type = EventType.BotChanged,
                Bot = new BotModel { Id = "BOTID1", Name = "NameB" }
            };

            var handler = new BotHandler();
            handler.BotState = mockState.Object;

            var result = await handler.HandleMessageAsync(message);

            mockState.Verify();
            Assert.Equal(2, bots.Count);
            Assert.Equal("NameB", bots.First(b => b.Id == "BOTID1").Name);
        }
Пример #2
0
        public async void HandlesValidBotAdded()
        {
            var bots = new List<BotModel>
            {
                new BotModel { Id = "BOTID1" },
                new BotModel { Id = "BOTID2" }
            };

            var mockState = new Mock<IBotState>();
            mockState.Setup(s => s.Bots)
                     .Returns(bots)
                     .Verifiable();

            var message = new BotAdded
            {
                Type = EventType.BotAdded,
                Bot = new BotModel { Id = "BOTID3" }
            };

            var handler = new BotHandler();
            handler.BotState = mockState.Object;

            var result = await handler.HandleMessageAsync(message);

            mockState.Verify();
            Assert.Equal(3, bots.Count);
            Assert.Equal("BOTID3", bots.Last().Id);
        }
Пример #3
0
        public async void AddsMissingChangedBot()
        {
            var bots = new List <BotModel>
            {
                new BotModel {
                    Id = "BOTID2"
                }
            };

            var mockState = new Mock <IBotState>();

            mockState.Setup(s => s.Bots)
            .Returns(bots)
            .Verifiable();

            var message = new BotChanged
            {
                Type = EventType.BotChanged,
                Bot  = new BotModel {
                    Id = "BOTID1", Name = "NameB"
                }
            };

            var handler = new BotHandler();

            handler.BotState = mockState.Object;

            var result = await handler.HandleMessageAsync(message);

            mockState.Verify();
            Assert.Equal(2, bots.Count);
            Assert.Equal("NameB", bots.First(b => b.Id == "BOTID1").Name);
        }
Пример #4
0
        public async void HandlesValidBotAdded()
        {
            var bots = new List <BotModel>
            {
                new BotModel {
                    Id = "BOTID1"
                },
                new BotModel {
                    Id = "BOTID2"
                }
            };

            var mockState = new Mock <IBotState>();

            mockState.Setup(s => s.Bots)
            .Returns(bots)
            .Verifiable();

            var message = new BotAdded
            {
                Type = EventType.BotAdded,
                Bot  = new BotModel {
                    Id = "BOTID3"
                }
            };

            var handler = new BotHandler();

            handler.BotState = mockState.Object;

            var result = await handler.HandleMessageAsync(message);

            mockState.Verify();
            Assert.Equal(3, bots.Count);
            Assert.Equal("BOTID3", bots.Last().Id);
        }