コード例 #1
0
            public void Execute_Func_throws_on_null_parameters()
            {
                var mockExecutionStrategy =
                    new Mock <DbExecutionStrategy>
                {
                    CallBase = true
                }.Object;

                Assert.Equal(
                    "operation",
                    Assert.Throws <ArgumentNullException>(() => mockExecutionStrategy.Execute((Func <int>)null)).ParamName);
            }
コード例 #2
0
            public void Exception_thrown_if_CommandBehavior_is_not_SequentialAccess()
            {
                var entityCommandDefinition = new Mock <EntityCommandDefinition>(null, null, null)
                {
                    CallBase = true
                }.Object;

                Assert.Equal(
                    Strings.ADP_MustUseSequentialAccess,
                    Assert.Throws <InvalidOperationException>(
                        () => entityCommandDefinition.Execute(default(EntityCommand), CommandBehavior.Default)).Message);
            }
コード例 #3
0
            public void Execute_Action_throws_on_null_parameters()
            {
                var mockExecutionStrategy =
                    new Mock <ExecutionStrategyBase>
                {
                    CallBase = true
                }.Object;

                Assert.Equal(
                    "action",
                    Assert.Throws <ArgumentNullException>(() => mockExecutionStrategy.Execute(null)).ParamName);
            }
コード例 #4
0
        public void Project_Validation(int locationWidth, int locationHeight, int x, int y, Direction startDirection, string command, string expected)
        {
            IRoverCommand _commander = new Mock <RoverCommand>(command).Object;
            var           rover      = new Rover();

            rover.Initialize(new Location(locationWidth, locationHeight), new Coordinate {
                X = x, Y = y
            }, startDirection);
            _commander.SetReceiver(rover);
            _commander.Execute();

            Assert.AreEqual(rover.ToString(), expected);
        }
コード例 #5
0
        public void Validate_Rules_NullEntity()
        {
            // if
            var rule = new Mock <IValidationRule <TestValidatableEntity> >();

            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(sp => sp.GetService(typeof(IEnumerable <IValidationRule <TestValidatableEntity> >)))
            .Returns(new List <IValidationRule <TestValidatableEntity> > {
                rule.Object
            });

            // when
            var validator = new NonBlockingValidator(serviceProvider.Object);

            validator.Validate(null as TestValidatableEntity);

            // then
            rule.Verify(rule => rule.Execute(It.IsAny <TestValidatableEntity>(), It.IsAny <NonBlockingValidationContext>()), Times.Never());
        }
コード例 #6
0
        public void ExecuteMethodChangesElementStatusBeforeExecutingTheFxGroup()
        {
            ISetParamMgr setterParamMgr = _element as ISetParamMgr;
            ISetPortMgrs setterPortsMgr = _element as ISetPortMgrs;
            ISetSimpleFx setterFx = _element as ISetSimpleFx;

            ValidationResults results1 = null;
            ValidationResults results2 = null;
            var mockParamMgr = new Mock<IIdentNodeCoresParamMgr>();
            var mockInPortMgr = new Mock<IInputPortMgr>();
            var mockOutPortMgr = new Mock<IOutputPortMgr>();
            var mockFx = new Mock<IIdentNodeCoresFx>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.DefaultBehavior.Strict = StrictFlags.ArbitraryMethodsAllowed;
                recorder.ExpectAndReturn(_element.OutPortMgr, mockOutPortMgr).RepeatAlways();
                recorder.ExpectAndReturn(mockOutPortMgr.PortStatuses, null).RepeatAlways();
                recorder.ExpectAndReturn(mockInPortMgr.Validate(out results1), true);
                recorder.ExpectAndReturn(mockParamMgr.Validate(out results2), true);
                mockFx.Execute(null, null, null, null);
                (_element as SimpleElementBase).Log(LogReasons.Start, null, null);
            }

            ElementStatus initialStatus = _element.Status;

            setterPortsMgr.SetInputMgr(mockInPortMgr);
            setterParamMgr.SetMgr(mockParamMgr);
            setterFx.SetFxGroup(mockFx);
            _element.Execute();
            ElementStatus expectedStatus = _element.Status;
            MockManager.Verify();

            Assert.Equal(ElementStatus.Incomplete, initialStatus);
            Assert.Equal(ElementStatus.Executing, expectedStatus);
        }
コード例 #7
0
            public void Execute_Func_throws_on_null_parameters()
            {
                var mockExecutionStrategy =
                    new Mock<DbExecutionStrategy>
                        {
                            CallBase = true
                        }.Object;

                Assert.Equal(
                    "operation",
                    Assert.Throws<ArgumentNullException>(() => mockExecutionStrategy.Execute((Func<int>)null)).ParamName);
            }
コード例 #8
0
            public void Execute_Action_throws_on_null_parameters()
            {
                var mockExecutionStrategy =
                    new Mock<ExecutionStrategyBase>
                        {
                            CallBase = true
                        }.Object;

                Assert.Equal(
                    "action",
                    Assert.Throws<ArgumentNullException>(() => mockExecutionStrategy.Execute(null)).ParamName);
            }
コード例 #9
0
        public void Execute_WhenStatusIsComplete()
        {
            var mockEl = new Mock<DummyCompoundElement>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(mockEl.Status, ElementStatus.Complete).Repeat(2);
                mockEl.ResetWithNotification(false);
                mockEl.ExecutionProper();
            }

            mockEl.Execute();
            MockManager.Verify();
        }
コード例 #10
0
        public void Execute_WhenStatusIsValidating()
        {
            var mockEl = new Mock<DummyCompoundElement>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(mockEl.Status, ElementStatus.Validating).Repeat(4);
                mockEl.Cancel();
                mockEl.ExecutionProper();
            }

            mockEl.Execute();
            MockManager.Verify();
        }