public void InterfaceIsImplementedAndNoDelegateIsDefined_InterfaceImplementationIsUsed()
        {
            var overridingActions = new ExplicitlyDefinedObjectActions<InterfaceRealizingEntity>();
            var actions = new ObjectActionsBasedOnDelegateOrInterface<InterfaceRealizingEntity>(overridingActions,_notifierMock.Object);

            var bigAnswer = actions.IsValid(_bigInterfaceRealizingObject);
            var smallAnswer = actions.IsValid(_smallInterfaceRealizingObject);
            actions.Ping(_bigInterfaceRealizingObject);

            Assert.That(bigAnswer, Is.True);
            Assert.That(smallAnswer, Is.False);
            Assert.That(_bigInterfaceRealizingObject.PingImplementationWasCalled, Is.True);
        }
        public void BothInterfaceImplementationAndDelegateAreDefined_DelegateIsUsed()
        {
            var overridingActions = new ExplicitlyDefinedObjectActions<InterfaceRealizingEntity>
            {
                IsValidDelegate = x => x.Value < 4,
                PingDelegate = _standalonePingImplementation,
            };
            var actions = new ObjectActionsBasedOnDelegateOrInterface<InterfaceRealizingEntity>(overridingActions, _notifierMock.Object);

            var bigAnswer = actions.IsValid(_bigInterfaceRealizingObject);
            var smallAnswer = actions.IsValid(_smallInterfaceRealizingObject);
            actions.Ping(_bigInterfaceRealizingObject);

            Assert.That(bigAnswer, Is.False);
            Assert.That(smallAnswer, Is.True);
            Assert.That(_bigInterfaceRealizingObject.PingImplementationWasCalled, Is.False);
            Assert.That(_standalonePingWasCalled, Is.True);
        }
        public void SetUpFixture()
        {
            _standalonePingImplementation = x => _standalonePingWasCalled = true;

            _normalDelegates = new ExplicitlyDefinedObjectActions<TestResource>
            {
                IsValidDelegate = resource => resource.Value.Contains(Mocks.ObjectActions.SubstringOfInvalidObject),
                PingDelegate = resource => { },
                ResetDelegate = resource => { },
                DisposeDelegate = resource => { }
            };

            _throwingDelegates = new ExplicitlyDefinedObjectActions<TestResource>
            {
                IsValidDelegate = resource => { throw new WebException(); },
                PingDelegate = resource => { throw new TimeoutException(); },
                ResetDelegate = resource => { throw new IndexOutOfRangeException(); },
                DisposeDelegate = resource => { throw new AccessViolationException(); }
            };
        }
 private void InitActionsWith(ExplicitlyDefinedObjectActions<TestResource> delegates)
 {
     _actions = new ObjectActionsBasedOnDelegateOrInterface<TestResource>(delegates, _notifierMock.Object);
 }
        public void NeitherInterfaceImplementationNorDelegate_EmptyMethodRealizationIsUsed()
        {
            var overridingActions = new ExplicitlyDefinedObjectActions<AutonomousEntity>();
            var actions = new ObjectActionsBasedOnDelegateOrInterface<AutonomousEntity>(overridingActions, _notifierMock.Object);

            var bigAnswer = actions.IsValid(_bigAutonomousObject);
            var smallAnswer = actions.IsValid(_smallAutonomousObject);
            actions.Ping(_bigAutonomousObject);

            Assert.That(bigAnswer, Is.True);
            Assert.That(smallAnswer, Is.True);
            Assert.That(_standalonePingWasCalled, Is.False);
        }