Exemple #1
0
        public void TestUpdateLeagueSuccess()
        {
            var league = new League
            {
                Type    = "Soccer",
                Name    = "West Chester coed over 30",
                Address = new Address
                {
                    street = "400 Boot Rd",
                    city   = "Downingtown",
                    state  = "PA",
                    zip    = "19053"
                },
                Image = "http://editor.swagger.io/photos"
            };

            var databaseFactory  = new TestDatabaseFactory();
            var leagueController = new LeaguesController(databaseFactory);

            SetupControllerForTests(leagueController);

            // Add new league
            var response = leagueController.PostLeague(league);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created), "The expected status code is 201 created");

            // Get the newly created league
            var leagues = leagueController.Get(league.Type, league.Name);

            Assert.That(leagues.Count, Is.EqualTo(1), "The number of leagues shoud be one");
            var createdLeague = leagues[0];

            // Modify league name
            createdLeague.Name = createdLeague.Name + "_Updated";

            // Update league
            var ret = leagueController.PutLeague(createdLeague.Id, createdLeague);

            // Get updated league
            leagues = leagueController.Get(league.Type, league.Name);
            Assert.That(leagues.Count, Is.EqualTo(1), "The number of leagues should be one");
            var modifiedLeague = leagues[0];

            Assert.That(modifiedLeague.Id, Is.EqualTo(createdLeague.Id), "The league Id should remain the same");
            Assert.That(modifiedLeague.Name, Is.EqualTo(createdLeague.Name), "The league name should remain the same");
        }
Exemple #2
0
        public void TestGetLeagueByName()
        {
            IDatabaseFactory databaseFactory = new TestDatabaseFactory();
            var leagueController             = new LeaguesController(databaseFactory);

            var leagues = (List <League>)leagueController.Get("Soccer", "Coed");

            Assert.That(leagues.Count, Is.EqualTo(2), "The number of leagues should be two");
            Assert.AreEqual("Bucks County Coed", leagues[0].Name);
            Assert.AreEqual("Montgomery County Coed League over 30", leagues[1].Name);
        }
        public void GetAll_ShouldSucceed()
        {
            var expectedOutput = _modelMocker.CreateMany <League>();

            _autoMocker.GetMock <IRepository>().Setup(x => x.GetAllLeagues()).Returns(Task.FromResult(expectedOutput));

            var output = _sutController.Get().Result as OkObjectResult;

            output.ShouldNotBeNull();
            output.StatusCode.ShouldNotBeNull();
            output.StatusCode.ShouldBe((int)HttpStatusCode.OK);
            JsonConvert.SerializeObject(output.Value).ShouldBe(JsonConvert.SerializeObject(expectedOutput));
        }
        public void LeaguesController_Get_ReturnsAllLeagues()
        {
            //Arrange
            var repositoryMock = new Mock <IUnitOfWork>();

            //Setup mock to dictate behavior of repository and it will return a list of leagues when called:
            repositoryMock.Setup(x => x.Repository.GetAll <League>()).Returns(leagues);
            //Create instance of leagues controller that will have mock repository injected; this is what will be used during the unit test
            var leaguesController = new LeaguesController(repositoryMock.Object);

            //Act
            var result = leaguesController.Get();

            //Assert
            repositoryMock.Verify(x => x.Repository.GetAll <League>(), Times.Once); // Ensure repository was called
            Assert.IsNotNull(result);                                               // Test to make sure return is not null
            Assert.IsInstanceOfType(result, typeof(IList <League>));                // Test type
            CollectionAssert.AreEqual(result.ToList(), leagues.ToList());           // Test the return is identical to what we expected
        }
        public void LeaguesController_GetWithValidLeagueId_ReturnsSingleLeague()
        {
            //Arrange
            const int leagueId       = 1;
            var       repositoryMock = new Mock <IUnitOfWork>();
            var       singleLeague   = leagues.Where(x => x.Id == leagueId).AsQueryable();

            //Setup mock to dictate behavior of repository and it will return a single league matching Id used in test when called:
            repositoryMock.Setup(x => x.Repository.GetQuery <League>(It.IsAny <Expression <Func <League, bool> > >())).Returns(singleLeague);
            //Create instance of leagues controller that will have mock repository injected; this is what will be used during the unit test
            var leaguesController = new LeaguesController(repositoryMock.Object);


            //Act
            var result = leaguesController.Get(leagueId);

            //Assert
            repositoryMock.Verify(x => x.Repository.GetQuery <League>(It.IsAny <Expression <Func <League, bool> > >()), Times.Once); // Ensure repository was called
            Assert.IsNotNull(result);                                                                                                // Test to make sure return is not null
            Assert.IsInstanceOfType(result, typeof(League));                                                                         // Test type
            Assert.AreEqual(result, singleLeague.SingleOrDefault());                                                                 // Test the return collection (with a single league) is identical to what we expected
        }