/// <summary> /// Configures the application. /// </summary> public static void ConfigureApplication(HttpConfiguration httpConfiguration) { // Configure the JSON formatter. httpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Register the error handling filters. httpConfiguration.Filters.Add(new ServiceExceptionFilterAttribute()); httpConfiguration.Filters.Add(new UnhandledExceptionFilterAttribute()); // Register the controller routes. CourseSchedulesController.RegisterRoutes(httpConfiguration.Routes); SessionsController.RegisterRoutes(httpConfiguration.Routes); }
/// <summary> /// Default constructor. /// </summary> public CourseSchedulesControllerTestHarness(bool shouldOpenDatabaseConnection, bool shouldCommitDatabaseTransaction) { // Build the mocked database objects. this.MockedDatabaseTransaction = new Mock <IDatabaseTransaction>(MockBehavior.Strict); this.MockedDatabaseConnection = new Mock <IDatabaseConnection>(MockBehavior.Strict); this.MockedDatabaseConnectionProvider = new Mock <IDatabaseConnectionProvider>(MockBehavior.Strict); // Mock the database connection. if (shouldOpenDatabaseConnection) { // Verify the database connection is opened. this.MockedDatabaseConnectionProvider .Setup(mock => mock.OpenDatabaseConnection()) .Returns(Task.FromResult <IDatabaseConnection>(this.MockedDatabaseConnection.Object)) .Verifiable(); // Verify the database transaction begins. this.MockedDatabaseConnection .Setup(mock => mock.BeginDatabaseTransaction()) .Returns(this.MockedDatabaseTransaction.Object) .Verifiable(); // Verify the database transaction is disposed. this.MockedDatabaseTransaction .Setup(mock => mock.Dispose()) .Verifiable(); // Verify the database connection is disposed. this.MockedDatabaseConnection .Setup(mock => mock.Dispose()) .Verifiable(); } // Mock the database transaction. if (shouldCommitDatabaseTransaction) { // Verify the database transaction is committed. this.MockedDatabaseTransaction .Setup(mock => mock.Commit()) .Verifiable(); } // Build the mocked Scheduling business logic component. this.MockedSchedulingBusinessLogicComponent = new Mock <ISchedulingBusinessLogicComponent>(MockBehavior.Strict); // Build the CourseSchedules controller. this.CourseSchedulesController = new CourseSchedulesController(this.MockedDatabaseConnectionProvider.Object, this.MockedSchedulingBusinessLogicComponent.Object); // Build the HTTP configuration. HttpConfiguration httpConfiguration = new HttpConfiguration(); GlobalHttpApplication.ConfigureApplication(httpConfiguration); // Build the mocked dependency resolver. MockedDependencyResolver mockedDependencyResolver = new MockedDependencyResolver(); mockedDependencyResolver.Setup(mock => mock.GetService(typeof(CourseSchedulesController))) .Returns(this.CourseSchedulesController); // Set the mocked dependency resolver. httpConfiguration.DependencyResolver = mockedDependencyResolver.Object; // Build the in memory HTTP server. HttpServer httpServer = new HttpServer(httpConfiguration); // Build the HTTP client. this.HttpClient = new HttpClient(httpServer); }