예제 #1
0
        // A test to see if the right Exeptions are thrown
        // in the CommentIndex method of the Translation controller.
        public void TestCommentIndexTrowsErrors()
        {
            var mockUnitOfWork = new MockUnitOfWork();
            var controller     = new TranslationController(mockUnitOfWork);

            // Act
            // The DataNotFoundExeption should be thrown
            // if the parameter does not match any id
            // in the database.
            try
            {
                var result = controller.CommentIndex(8);
            }
            // Assert
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(DataNotFoundException));
            }
            // Act
            // The MissingParameterExeption should be thrown
            // if the method takes null as a parameter.
            try
            {
                int?variable = null;
                var result   = controller.CommentIndex(variable);
            }
            // Assert
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(MissingParameterException));
            }
        }