コード例 #1
0
        public async Task MoviesController_GetAllMovies_WhenImdbBaseUrlConfigurationSettingIsMissing_ShouldReturnHttpErrorResponse()
        {
            // Arrange
            var expectedExceptionMessage             = "The Configuration Setting: ImdbBaseUrl is missing from the configuration file";
            var configurationSettingMissingException = new ConfigurationSettingMissingException(expectedExceptionMessage);

            var moviesController = new MoviesControllerForTest(configurationSettingMissingException);

            // Act
            var actionResult = await moviesController.Get().ConfigureAwait(false);

            var actualExceptionResult = (ExceptionActionResult)actionResult.Result;

            // Assert
            Assert.IsInstanceOfType(actualExceptionResult.Exception, typeof(ConfigurationSettingMissingException));
            Assert.AreEqual(expectedExceptionMessage, actualExceptionResult.Exception.Message);
        }
コード例 #2
0
        public async Task GetMovies_WhenAnExceptionIsThrownInTheDomainLayer_ShouldThrow()
        {
            // Arrange
            var expectedMessage   = "Some Exception Message";
            var expectedException = new ConfigurationSettingMissingException(expectedMessage);
            var moviesController  = new MovieControllerForTest(expectedException);

            // Act
            try
            {
                await moviesController.GetMovies();

                Assert.Fail("We were expecting an exception of type: ConfigurationSettingMissingException to be thrown, but no exception was thrown");
            }
            catch (ConfigurationSettingMissingException e)
            {
                // Assert
                Assert.AreEqual(expectedMessage, e.Message);
            }
        }