Example #1
0
        public async Task Quando_Requisitar_GetAll_BadRequest()
        {
            // Arrange
            var serviceMock = new Mock <IGameService>();

            serviceMock.Setup(a => a.GetAll()).ReturnsAsync(new List <GameEntity>
            {
                new GameEntity {
                    GameId   = 5,
                    PlayerId = 4,
                    Win      = 2,
                    Id       = Guid.NewGuid(),
                },
                new GameEntity {
                    GameId   = 1,
                    PlayerId = 2,
                    Win      = 3,
                    Id       = Guid.NewGuid(),
                }
            });

            _controller = new GamesController(serviceMock.Object);
            _controller.ModelState.AddModelError("Id", "Formato Invalido");

            // Act
            var result = await _controller.GetAll();

            // Assert
            Assert.True(result is BadRequestObjectResult);
            Assert.False(_controller.ModelState.IsValid);
        }
Example #2
0
        public async Task Quando_Requisitar_GetAll()
        {
            // Arrange
            var serviceMock = new Mock <IGameService>();

            serviceMock.Setup(a => a.GetAll()).ReturnsAsync(new List <GameEntity>
            {
                new GameEntity {
                    GameId   = 5,
                    PlayerId = 4,
                    Win      = 2,
                    Id       = Guid.NewGuid(),
                },
                new GameEntity {
                    GameId   = 1,
                    PlayerId = 2,
                    Win      = 3,
                    Id       = Guid.NewGuid(),
                }
            });

            _controller = new GamesController(serviceMock.Object);

            // Act
            var result = await _controller.GetAll();

            // Assert
            Assert.True(result is OkObjectResult);
            var resultValue = ((OkObjectResult)result).Value as IEnumerable <GameEntity>;

            Assert.True(resultValue.Count() == 2);
        }
        public void GetAllAvailableGamesTest()
        {
            var itemsCollection = this.GenerateValidItems(15);

            var currentRepository = Mock.Create <IRepository <Game> >();

            Mock.Arrange(() => currentRepository.All()).Returns(() => itemsCollection.AsQueryable());

            var dataProvider = Mock.Create <IDataProvider>();

            Mock.Arrange(() => dataProvider.Games).Returns(() => currentRepository);

            var userProvider = Mock.Create <IUserIdProvider>();

            Mock.Arrange(() => userProvider.GetUserId()).Returns(() => "1");

            var controller = new GamesController(dataProvider, userProvider);

            ControllerSetup.SetupController(controller, "games");

            var actionResult = controller.GetAll();
            var response     = actionResult.ExecuteAsync(CancellationToken.None).Result;

            var actual = response.Content.ReadAsAsync <IEnumerable <GameSimpleModel> >()
                         .Result.Select(x => x.Id).ToList();

            var expected = itemsCollection.AsQueryable()
                           .Where(x => x.GameState == GameState.WaitingForOpponent)
                           .OrderBy(x => x.GameState)
                           .ThenBy(x => x.Name)
                           .ThenBy(x => x.DateCreated)
                           .ThenBy(x => x.Red.UserName)
                           .Take(10)
                           .Select(x => x.Id)
                           .ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }