Exemplo n.º 1
0
        public void DropDatabase_DatabaseServiceThrowsExceptions_ReturnsValidResults()
        {
            // Arrange
            string dbName = "testDatabase";

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

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

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

                // Act
                IHttpActionResult actionResult = target.DropDatabase(dbName);

                // Assert
                Assert.IsInstanceOf(result.Value, actionResult);
            }
        }
Exemplo n.º 2
0
        public void DropDatabase_DatabaseServiceDropsDatabase_ReturnsOkResult()
        {
            // Arrange
            string dbName = "testDatabase";

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

            // Act
            IHttpActionResult actionResult = target.DropDatabase(dbName);

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

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