public LeaguesController() { //If default constructor is called, means it is "real" request //IDatabaseFactory factory = new MongoDBDatabaseFactory(); IDatabaseFactory factory = new TestDatabaseFactory(); databasePlaceholder = factory.GetLeagueRepository(); }
public void When_AllLecturersRunsAgainstEmptyDatabase_Then_EmptyCollectionIsReturned() { // Arrange var service = new LecturersService(new GetAllLecturersQuery(TestDatabaseFactory.CreateEmptyDatabase())); // Act var allLecturers = service.All(); // Assert allLecturers.Should().BeEmpty(); }
public void TestGetTeamsByLeague() { IDatabaseFactory databaseFactory = new TestDatabaseFactory(); var leagueController = new LeaguesController(databaseFactory); var teams = leagueController.GetTeamsByLeague(1); Assert.That(teams.Count, Is.EqualTo(2), "The number of teams should be two"); Assert.IsTrue(teams.Contains("1")); Assert.IsTrue(teams.Contains("2")); }
public void TestGetAllLeagues() { IDatabaseFactory databaseFactory = new TestDatabaseFactory(); var leagueController = new LeaguesController(databaseFactory); List <League> leagues = null; leagues = (List <League>)leagueController.GetAllLeagues(); Assert.AreEqual(2, leagues.Count); }
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 TestCreateLeague(League league, HttpStatusCode statusCode) { var databaseFactory = new TestDatabaseFactory(); var leagueController = new LeaguesController(databaseFactory); SetupControllerForTests(leagueController); HttpResponseMessage response; response = leagueController.PostLeague(league); Assert.That(response.StatusCode, Is.EqualTo(statusCode), "The expected status code is " + statusCode); }
private ReservationsService CreateReservationsServiceForStatisticsTests() { mockDb = TestDatabaseFactory.CreateDatabaseForStatistics(); mockQueryAllLectureHalls = new GetAllLectureHallsQuery(mockDb); mockQueryAllLectures = new GetAllLecturersQuery(mockDb); mockQueryAllReservations = new GetAllReservationsQuery(mockDb); mockQueryAddReservation = new AddReservationQuery(mockDb); mockQueryDeleteReservation = new DeleteReservationQuery(mockDb); mockQueryGetReservationById = new GetReservationByIdQuery(mockDb); return(new ReservationsService(mockQueryAllReservations, mockQueryGetReservationById, mockQueryAddReservation, mockQueryDeleteReservation, mockQueryAllLectures, mockQueryAllLectureHalls)); }
private ReservationsService CreateReservationsService(bool empty) { mockDb = empty ? TestDatabaseFactory.CreateEmptyDatabase() : TestDatabaseFactory.CreateDatabase(); mockQueryAllLectureHalls = new GetAllLectureHallsQuery(mockDb); mockQueryAllLectures = new GetAllLecturersQuery(mockDb); mockQueryAllReservations = new GetAllReservationsQuery(mockDb); mockQueryAddReservation = new AddReservationQuery(mockDb); mockQueryDeleteReservation = new DeleteReservationQuery(mockDb); mockQueryGetReservationById = new GetReservationByIdQuery(mockDb); return(new ReservationsService(mockQueryAllReservations, mockQueryGetReservationById, mockQueryAddReservation, mockQueryDeleteReservation, mockQueryAllLectures, mockQueryAllLectureHalls)); }
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"); }
public void TestCreateLeagueDuplicateData() { 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); HttpResponseMessage response; response = leagueController.PostLeague(league); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created), "The expected status code is 201 created"); //Try to add duplicate entry response = leagueController.PostLeague(league); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict), "The expected status code is 409 conflict"); Assert.That(response.Headers.Contains("X-Status-Reason"), Is.True, "The expected response should have \"X-Status-Reason\" header"); IEnumerable <string> values; response.Headers.TryGetValues("X-Status-Reason", out values); var enumerator = values.GetEnumerator(); Assert.That(enumerator.MoveNext(), Is.True, "X-Status-Reason header in the response should have at least one value"); Assert.That(enumerator.Current, Is.EqualTo(string.Format("The league with the name {0} already exists in the database", league.Name)), "unexpected response in header"); }
public void Init() { AutoMapperConfig.Init(); mockDb = TestDatabaseFactory.CreateDatabase(); mockQueryAllLecturers = new GetAllLecturersQuery(mockDb); }
public void Init() { AutoMapperConfig.Init(); _mockDb = TestDatabaseFactory.CreateDatabase(); _mockQueryAllSubjects = new GetAllSubjectsQuery(_mockDb); }