本文整理汇总了C#中CommandProcessor.PublishCommand方法的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessor.PublishCommand方法的具体用法?C# CommandProcessor.PublishCommand怎么用?C# CommandProcessor.PublishCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandProcessor
的用法示例。
在下文中一共展示了CommandProcessor.PublishCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CancelCommandGroup_CancelAGroup_AllCommandsInGroupAreCancelled
public void CancelCommandGroup_CancelAGroup_AllCommandsInGroupAreCancelled()
{
int[] commandsCanceled = {0};
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(false);
var processor = new CommandProcessor(null, fakeFilterManager);
var commands = new[]
{
new TestCommand(CommandState.New, groupId: "GroupA"),
new TestCommand(CommandState.New, groupId: "GroupB"),
new TestCommand(CommandState.New, groupId: "GroupA"),
new TestCommand(CommandState.New, groupId: "GroupA"),
new TestCommand(CommandState.New, groupId: "GroupB"),
new TestCommand(CommandState.New, groupId: "GroupA"),
new TestCommand(CommandState.New, groupId: "GroupC"),
};
foreach (var command in commands)
{
command.RegisterForStateChange(Observer.Create<CommandState>(b =>
{
if (b == CommandState.Canceled)
{
commandsCanceled[0]++;
}
}));
processor.PublishCommand(command);
}
processor.CancelCommandGroup("GroupA");
Assert.AreEqual(4, commandsCanceled[0]);
}
示例2: CancelCommand_CommandIsBlockedAndShouldFailIfBlocked_CommandFails
public void CancelCommand_CommandIsBlockedAndShouldFailIfBlocked_CommandFails()
{
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New, blockCanExecute: true, shouldFailIfBlocked:true);
command.RegisterForStateChange(Observer.Create<CommandState>(b =>
{
if (b == CommandState.Failed)
{
resetEvent.Set();
}
}));
processor.PublishCommand(command);
resetEvent.Wait();
Assert.AreEqual(CommandState.Failed, command.CurrentState);
}
示例3: PublishCommand_CommandIsNotNew_ThrowsException
public void PublishCommand_CommandIsNotNew_ThrowsException()
{
bool wasThrown = false;
Exception thrownException = null;
var fakeFilterManager = A.Fake<IFilterManager>();
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.Canceled);
try
{
processor.PublishCommand(command);
}
catch (CommandProcessorException ex)
{
thrownException = ex;
wasThrown = true;
}
Assert.IsTrue(wasThrown);
Assert.AreEqual("Command is not new", thrownException.Message);
}
示例4: InputSource_NewMessageIsRecievedByComamnds_InterpretResponseIsCalled
public void InputSource_NewMessageIsRecievedByComamnds_InterpretResponseIsCalled()
{
var interpretResponseCalled = false;
var inputSource = new Subject<ProcessorInput>();
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(inputSource, fakeFilterManager);
var command = new TestCommand(CommandState.New, interpretResponseAction: i =>
{
interpretResponseCalled = true;
resetEvent.Set();
return false;
});
command.RegisterForStateChange(Observer.Create<CommandState>(b =>
{
if (b == CommandState.Executing)
{
resetEvent.Set();
}
}));
processor.PublishCommand(command);
resetEvent.Wait();
inputSource.OnNext(new ProcessorInput());
resetEvent.Wait();
Assert.IsTrue(interpretResponseCalled);
}
示例5: InputSource_CommandSucceedsDueToInput_CommandIsCompleted
public void InputSource_CommandSucceedsDueToInput_CommandIsCompleted()
{
var commandCompleted = false;
var inputSource = new Subject<ProcessorInput>();
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(inputSource, fakeFilterManager);
var command = new TestCommand(CommandState.New, interpretResponseAction: i => true);
command.RegisterForStateChange(Observer.Create<CommandState>(b =>
{
if (b == CommandState.Executing)
{
resetEvent.Set();
}
}));
processor.PublishCommand(command, Observer.Create<ICommandResponse<Unit>>(_ => { }, () =>
{
commandCompleted = true;
resetEvent.Set();
}));
resetEvent.Wait();
inputSource.OnNext(new ProcessorInput());
resetEvent.Wait();
Assert.IsTrue(commandCompleted);
}
示例6: RerunBlockedCommand_CommandIsBlocked_CommandIsPendingAgain
public void RerunBlockedCommand_CommandIsBlocked_CommandIsPendingAgain()
{
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New, blockCanExecute: true);
command.RegisterForStateChange(Observer.Create<IObservedChange<CommandBase, CommandState>>(b =>
{
if (b.Value == CommandState.Blocked)
{
resetEvent.Set();
}
}));
processor.PublishCommand(command);
resetEvent.Wait();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(false);
command.RegisterForStateChange(Observer.Create<IObservedChange<CommandBase, CommandState>>(b =>
{
if (b.Value == CommandState.Pending)
{
resetEvent.Set();
}
}));
processor.RerunBlockedCommand(command);
resetEvent.Wait();
Assert.AreEqual(CommandState.Pending, command.CurrentState);
}
示例7: PublishCommand_NoObserver_CommandIsChangedToPending
public void PublishCommand_NoObserver_CommandIsChangedToPending()
{
var fakeFilterManager = A.Fake<IFilterManager>();
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New);
processor.PublishCommand(command);
Assert.AreEqual(CommandState.Pending, command.CurrentState);
}
示例8: PublishCommand_FilterThrewExceptionAndCommandIsPending_CommandStillPending
public void PublishCommand_FilterThrewExceptionAndCommandIsPending_CommandStillPending()
{
bool isPendingWithException = false;
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Throws(new Exception());
var processor = new CommandProcessor(null, fakeFilterManager);
var evt = new ManualResetEventSlim(false);
var command = new TestCommand(CommandState.New, shouldFailIfFiltered: false,
// ReSharper disable RedundantArgumentName
//We want to keep this verbose to clarity
startRequestAction: (s, e) =>
// ReSharper restore RedundantArgumentName
{
isPendingWithException = (s == CommandState.Pending &&
e != null);
evt.Set();
});
processor.PublishCommand(command);
evt.Wait();
Assert.IsTrue(isPendingWithException);
}
示例9: CommandPublish_CommandShouldCompleteWhenAfterExecuting_CommandSucceded
public void CommandPublish_CommandShouldCompleteWhenAfterExecuting_CommandSucceded()
{
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New, shouldCompleteAfterExecute: true);
processor.PublishCommand(command, Observer.Create<ICommandResponse<Unit>>(_ => { }, resetEvent.Set));
resetEvent.Wait();
Assert.AreEqual(CommandState.Successed, command.CurrentState);
}
示例10: CommandPublish_CommandHasFullfillmentAction_ActionCalled
public void CommandPublish_CommandHasFullfillmentAction_ActionCalled()
{
var actionCalled = false;
var resetEvent = new ManualResetEventSlim(false);
var inputSource = new Subject<ProcessorInput>();
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(inputSource, fakeFilterManager);
var command = new TestCommand(CommandState.New, interpretResponseAction: r => true, fullfillmentAction: i =>
{
actionCalled
=
true;
resetEvent
.
Set
();
});
processor.PublishCommand(command);
inputSource.OnNext(new ProcessorInput());
resetEvent.Wait();
Assert.IsTrue(actionCalled);
}
示例11: CommandPublish_CommandHasErrorAction_ActionCalled
public void CommandPublish_CommandHasErrorAction_ActionCalled()
{
var actionCalled = false;
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New
, errorAction: (i, ex) =>
{
actionCalled = true;
resetEvent.Set();
},
executeAction: new Action(() =>
{
throw new Exception();
}));
processor.PublishCommand(command);
resetEvent.Wait();
Assert.IsTrue(actionCalled);
}
示例12: CommandPublishGeneric_CommandGotFullfillmentWithReturnValue_ReturnValue
public void CommandPublishGeneric_CommandGotFullfillmentWithReturnValue_ReturnValue()
{
var resetEvent = new ManualResetEventSlim(false);
var inputSource = new Subject<ProcessorInput>();
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(inputSource, fakeFilterManager);
var command = new TestCommand<bool>(CommandState.New, returnValue:true, interpretResponseAction: r => true, fullfillmentAction: i => resetEvent.Set());
processor.PublishCommand(command);
inputSource.OnNext(new ProcessorInput());
resetEvent.Wait();
Assert.IsTrue(command.ReturnValue);
}
示例13: CancelCommand_CommandIsPending_CommandIsCancled
public void CancelCommand_CommandIsPending_CommandIsCancled()
{
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(false);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New, shouldFailIfFiltered: false,
// ReSharper disable RedundantArgumentName
//We want to keep this verbose to clarity
startRequestAction: (s, e) => resetEvent.Set());
// ReSharper restore RedundantArgumentName
processor.PublishCommand(command);
resetEvent.Wait();
processor.CancelCommand(command);
Assert.AreEqual(CommandState.Canceled, command.CurrentState);
}
示例14: PublishCommand_CommandPassesFilter_CommandIsExecuted
public void PublishCommand_CommandPassesFilter_CommandIsExecuted()
{
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var evt = new ManualResetEventSlim(false);
var command = new TestCommand(CommandState.New);
command.RegisterForStateChange(Observer.Create<CommandState>(b =>
{
if (b == CommandState.Executing)
{
evt.Set();
}
}));
processor.PublishCommand(command);
evt.Wait();
Assert.AreEqual(CommandState.Executing, command.CurrentState);
}
示例15: CommandPublish_CommandThrowsExceptionWhileExecuting_CommandFailsWithThatException
public void CommandPublish_CommandThrowsExceptionWhileExecuting_CommandFailsWithThatException()
{
bool wasThrown = false;
Exception thrownException = new Exception("Text");
Exception expectedException = null;
var resetEvent = new ManualResetEventSlim(false);
var fakeFilterManager = A.Fake<IFilterManager>();
A.CallTo(() => fakeFilterManager.Process(A<CommandBase>.Ignored)).Returns(true);
var processor = new CommandProcessor(null, fakeFilterManager);
var command = new TestCommand(CommandState.New, executeAction: () =>
{
throw thrownException;
});
processor.PublishCommand(command, Observer.Create<ICommandResponse<Unit>>(_ => { }, ex =>
{
expectedException = ex;
wasThrown = true;
resetEvent.Set();
}));
resetEvent.Wait();
Assert.IsTrue(wasThrown);
Assert.AreEqual(expectedException, thrownException);
}