コード例 #1
0
        public void DropTable_DatabaseServiceThrowsExceptions_ReturnsValidResults()
        {
            // Arrange
            string dbName    = "testDatabase";
            string tableName = "testTable";

            Dictionary <Exception, Type> resultsDictionary = new Dictionary <Exception, Type>
            {
                { new ArgumentException(), typeof(BadRequestResult) },
                { new DatabaseNotFoundException(), typeof(NotFoundResult) },
                { new TableNotFoundException(), typeof(NotFoundResult) },
                { new DbServiceException(), typeof(InternalServerErrorResult) }
            };

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

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

                // Act
                IHttpActionResult actionResult = target.DropTable(dbName, tableName);

                // Assert
                Assert.IsInstanceOf(result.Value, actionResult);
            }
        }
コード例 #2
0
        public void DropTable_DatabaseServiceDropsTable_ReturnsOkResult()
        {
            // Arrange
            string dbName    = "testDatabase";
            string tableName = "testTable";

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

            // Act
            IHttpActionResult actionResult = target.DropTable(dbName, tableName);

            // Assert
            Assert.IsInstanceOf <OkResult>(actionResult);

            this._dbServiceMock.Verify(s => s.DropTable(dbName, tableName), Times.Once);
        }