Exemplo n.º 1
0
        public async Task BotLogic_GetAllLiveBots_Should_Only_Return_Live_Bots()
        {
            // Arrange
            var       randomHelper        = new Mock <IRandomHelper>();
            var       botRepository       = new Mock <IRepository <Bot> >();
            var       scriptRepository    = new Mock <IRepository <BotScript> >();
            var       playerRepository    = new Mock <IRepository <Player> >();
            var       botMapper           = new BotMapper();
            var       botToCreateMapper   = new BotToCreateMapper();
            var       arenaLogic          = new Mock <IArenaLogic>();
            var       configurationHelper = new Mock <IConfigurationHelper>();
            IBotLogic botLogic            = new BotLogic(
                randomHelper.Object, botRepository.Object, scriptRepository.Object, playerRepository.Object,
                botMapper, botToCreateMapper, arenaLogic.Object, configurationHelper.Object);

            var bots = new List <Bot>
            {
                new Bot
                {
                    Name          = "BOT1",
                    CurrentHealth = 0
                },
                new Bot
                {
                    Name          = "BOT2",
                    CurrentHealth = 1
                },
                new Bot
                {
                    Name          = "BOT3",
                    CurrentHealth = 0
                }
            };

            // Mock
            botRepository.Setup(x => x.Find(Any.Predicate <Bot>(), Any.Include <Bot, Player>()))
            .ReturnsAsync((Expression <Func <Bot, bool> > predicate, Expression <Func <Bot, Player> > include) =>
                          (IList <Bot>)bots.Where(predicate.Compile()).ToList());

            // Act
            var result = await botLogic.GetAllLiveBots();

            // Assert
            result.Should().HaveCount(1);
            result.Should().Contain(x => x.Name == "BOT2");
        }