public void GetAllServiceTest()
        {
            var itemsCollection = this.GenerateValidItems(1);

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

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

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

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

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

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

            var controller = new TestEntitiesController(dataProvider, userProvider);

            ControllerSetup.SetupController(controller, "testentities");

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

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

            var expected = itemsCollection.AsQueryable().Select(a => a.Id).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void AddServiceTest()
        {
            var itemToAdd = this.CreateTestEntityModel();

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

            Mock.Arrange(() => currentRepository.Add(Arg.IsAny <TestEntity>())).DoNothing();

            var userRepo = Mock.Create <IRepository <User> >();

            Mock.Arrange(() => userRepo.Find(Arg.IsAny <string>())).Returns(() => new User());

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

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

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

            Mock.Arrange(() => userProvider.GetUserId()).DoNothing();

            var controller = new TestEntitiesController(dataProvider, userProvider);

            ControllerSetup.SetupController(controller, "testentities");

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

            var actual   = response.Content.ReadAsAsync <TestEntityModel>().Result;
            var expected = itemToAdd;

            Assert.AreEqual(expected.Name, actual.Name);
        }
Exemplo n.º 3
0
        public void GetTopPlayersTest()
        {
            var itemsCollection = this.GenerateValidItems(15);

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

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

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

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

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

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

            var controller = new ScoresController(dataProvider, userProvider);

            ControllerSetup.SetupController(controller, "scores");

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

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

            var expected = itemsCollection.AsQueryable().OrderByDescending(a => a.Rank).Select(a => a.Rank).Take(10).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        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);
        }