public static void Create_ThrowsArgumentNullException_ForNullView()
        {
            // Arrange
            var factory       = new PresenterFactory();
            var presenterType = typeof(IPresenter <IView>);
            var viewType      = typeof(IView);

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => factory.Create(presenterType, viewType, null));
        }
        public static void Create_ThrowsArgumentNullException_ForNullPresenterType()
        {
            // Arrange
            var factory  = new PresenterFactory();
            var viewType = typeof(IView);
            var view     = Substitute.For <IView>();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => factory.Create(null, viewType, view));
        }
        public static void Create_ThrowsPresenterBindingException_WhenConstructorThrows()
        {
            // Arrange
            var factory       = new PresenterFactory();
            var presenterType = typeof(MyErrorPresenter);
            var viewType      = typeof(IView);
            var view          = Substitute.For <IView>();

            // Act & Assert
            Assert.Throws <PresenterBindingException>(() => factory.Create(presenterType, viewType, view));
        }
        public static void Release_DisposesPresenter()
        {
            // Arrange
            var factory = new PresenterFactory();
            var view    = Substitute.For <IView>();

            using (var presenter = new MyDisposablePresenter(view))
            {
                // Act
                factory.Release(presenter);

                // Assert
                Assert.True(presenter.DisposeWasCalled);
            }
        }
        public static void Create_ReturnsInstance()
        {
            // Arrange
            var factory       = new PresenterFactory();
            var presenterType = typeof(MyPresenter);
            var viewType      = typeof(IView);
            var view          = Substitute.For <IView>();

            // Act
            var presenter = factory.Create(
                presenterType,
                viewType,
                view);

            // Assert
            Assert.True(presenter is MyPresenter);
        }
        public static void Create_WrapsOriginalException_WhenConstructorThrows()
        {
            // Arrange
            var factory       = new PresenterFactory();
            var presenterType = typeof(MyErrorPresenter);
            var viewType      = typeof(IView);
            var view          = Substitute.For <IView>();

            try
            {
                // Act
                factory.Create(presenterType, viewType, view);
            }
            catch (PresenterBindingException ex)
            {
                // Assert
                Assert.True(ex.InnerException is ApplicationException);
            }
        }