public void CreateTable_DatabaseServiceThrowsExceptions_ReturnsValidResults()
        {
            // Arrange
            string      dbName      = "testDatabase";
            TableScheme tableScheme = new TableScheme("testTable", new List <Domain.Models.Attribute>());

            Dictionary <Exception, Type> resultsDictionary = new Dictionary <Exception, Type>
            {
                { new ArgumentException(), typeof(BadRequestResult) },
                { new DatabaseNotFoundException(), typeof(BadRequestErrorMessageResult) },
                { new InvalidTableSchemeException(), typeof(BadRequestErrorMessageResult) },
                { new TableAlreadyExistsException(), typeof(ConflictResult) },
                { new DbServiceException(), typeof(InternalServerErrorResult) }
            };

            foreach (KeyValuePair <Exception, Type> result in resultsDictionary)
            {
                // Arrange - mock dbService
                this._dbServiceMock.Setup(s => s.CreateTable(dbName, tableScheme))
                .Throws(result.Key);

                // Arrange - create target
                DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object);

                // Act
                IHttpActionResult actionResult = target.CreateTable(dbName, tableScheme);

                // Assert
                Assert.IsInstanceOf(result.Value, actionResult);
            }
        }
        public void CreateTable_DatabaseServiceCreatesTable_ReturnsCreatedAtRouteResult()
        {
            // Arrange
            string      dbName      = "testDatabase";
            TableScheme tableScheme = new TableScheme("testTable", new List <Domain.Models.Attribute>());

            // Arrange - create target
            DatabaseApiController target = new DatabaseApiController(this._dbServiceMock.Object);

            // Act
            IHttpActionResult actionResult = target.CreateTable(dbName, tableScheme);

            CreatedAtRouteNegotiatedContentResult <TableScheme> createdResult =
                actionResult as CreatedAtRouteNegotiatedContentResult <TableScheme>;

            // Assert
            Assert.IsNotNull(createdResult);
            Assert.AreEqual("GetTable", createdResult.RouteName);
            Assert.AreEqual(dbName, createdResult.RouteValues["dbName"]);
            Assert.AreEqual(tableScheme.Name, createdResult.RouteValues["tableName"]);

            this._dbServiceMock.Verify(s => s.CreateTable(dbName, tableScheme), Times.Once);
        }