public void AddFailureLeagueNameExistsInTheRepo()
        {
            League league = new League();
            var    mock   = new Mock <ILeagueRepository>(MockBehavior.Strict);

            // Filling mock rull with repository
            mock.As <ICRUDRepository <League, int, LeagueFilter> >().Setup(m => m.Add(It.IsAny <League>()));
            mock.As <ILeagueRepository>().Setup(m => m.isLeagueNameExist(It.IsAny <int>(), It.IsAny <string>(), null))
            .Returns(Task.FromResult(true));

            var mockSeasonRepo = new Mock <ISeasonRepository>(MockBehavior.Strict);

            mockSeasonRepo.As <ICRUDRepository <Season, int, SeasonFilter> >().Setup(m => m.Get(It.IsAny <int>()))
            .Returns <int>(id => Task.FromResult(new Season()));

            // Creating the controller which we want to create
            LeagueController controller = new LeagueController(mock.Object, mockSeasonRepo.Object);

            // configuring the context for the controler
            fakeContext(controller);

            HttpResponseMessage response = controller.Post(league).Result;

            // the result should say "HttpStatusCode.BadRequest"
            Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest);
        }
        public void AddLeagueInTheRepo()
        {
            List <League> leagues = CreateLeagueList();
            List <League> added   = new List <League>();
            var           mock    = new Mock <ILeagueRepository>(MockBehavior.Strict);

            // Filling mock with data
            mock.As <ICRUDRepository <League, int, LeagueFilter> >().Setup(m => m.Add(It.IsAny <League>()))
            .Returns(Task.FromResult(leagues.FirstOrDefault()))
            .Callback <League>(c => added.Add(c));
            mock.As <ILeagueRepository>().Setup(m => m.isLeagueNameExist(It.IsAny <int>(), It.IsAny <string>(), null))
            .Returns(Task.FromResult(false));

            var mockSeasonRepo = new Mock <ISeasonRepository>(MockBehavior.Strict);

            mockSeasonRepo.As <ICRUDRepository <Season, int, SeasonFilter> >().Setup(m => m.Get(It.IsAny <int>()))
            .Returns <int>(id => Task.FromResult(new Season()));

            // Creating the controller which we want to create
            LeagueController controller = new LeagueController(mock.Object, mockSeasonRepo.Object);

            // configuring the context for the controler
            fakeContext(controller);

            // Testing all the list that we can retrieve correctly the leagues
            for (int i = 0; i < leagues.Count; i++)
            {
                HttpResponseMessage response = controller.Post(leagues[i]).Result;
                // the result should say "HttpStatusCode.Created"
                Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
            }

            // the added list should be the same as the list
            CollectionAssert.AreEqual(leagues, added);
        }