本文整理汇总了C#中Promise.Then方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.Then方法的具体用法?C# Promise.Then怎么用?C# Promise.Then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.Then方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _if_onRejected_is_not_a_function_it_must_be_ignored_1
public void _if_onRejected_is_not_a_function_it_must_be_ignored_1()
{
var promise = new Promise<object>();
var resultPromise = promise
.Then(
v => Promise.Resolved(),
null
);
var resolved = 0;
var errors = 0;
var e = new Exception();
resultPromise.Then(() => ++resolved);
resultPromise.Catch(ex =>
{
Assert.Equal(e, ex);
++errors;
});
promise.Reject(e);
Assert.Equal(0, resolved);
Assert.Equal(1, errors);
}
示例2: CanResolvePromiseAndTriggerThenHandler
public void CanResolvePromiseAndTriggerThenHandler()
{
var promise = new Promise();
var completed = 0;
promise.Then(() => ++completed);
promise.Resolve();
Assert.AreEqual(1, completed);
}
示例3: can_resolve_promise_and_trigger_then_handler
public void can_resolve_promise_and_trigger_then_handler()
{
var promise = new Promise();
var completed = 0;
promise.Then(() => ++completed);
promise.Resolve();
Assert.Equal(1, completed);
}
示例4: can_resolve_simple_promise
public void can_resolve_simple_promise() {
var promisedValue = 5;
var promise = new Promise<int>(promisedValue);
var completed = 0;
promise.Then(v => {
Assert.Equal(promisedValue, v);
++completed;
});
Assert.Equal(1, completed);
}
示例5: can_resolve_promise_and_trigger_then_handler
public void can_resolve_promise_and_trigger_then_handler() {
var promise = new Promise<int>();
var completed = 0;
var promisedValue = 15;
promise.Then(v => {
Assert.Equal(promisedValue, v);
++completed;
});
promise.Resolve(promisedValue);
Assert.Equal(1, completed);
}
示例6: can_chain_promise
public void can_chain_promise()
{
var promise = new Promise();
var chainedPromise = new Promise();
var completed = 0;
promise
.Then(() => chainedPromise)
.Then(() => ++completed);
promise.Resolve();
chainedPromise.Resolve();
Assert.Equal(1, completed);
}
示例7: PromisesShouldWorkProperly
public void PromisesShouldWorkProperly()
{
// 1) Tests that multiple Then and a Done block are called as expected.
Promise<bool> p1 = new Promise<bool>();
CountedPromise<bool> cp = new CountedPromise<bool>(3);
p1.Then(value => {
cp.Resolve(value);
})
.Then(value => {
cp.Resolve(value);
})
.Done(value => {
cp.Resolve(value);
});
p1.Resolve(true);
cp.WhenCompleted.ExpectSuccess(success => PromisesShouldWorkProperlyPart2());
}
示例8: _must_have_a_value_which_must_not_change
public void _must_have_a_value_which_must_not_change()
{
var promisedValue = new object();
var fulfilledPromise = new Promise<object>();
var handled = 0;
fulfilledPromise.Then(v =>
{
Assert.Equal(promisedValue, v);
++handled;
});
fulfilledPromise.Resolve(promisedValue);
Assert.Throws<ApplicationException>(() => fulfilledPromise.Resolve(new object()));
Assert.Equal(1, handled);
}
示例9: _if_onFulfilled_is_not_a_function_it_must_be_ignored_2
public void _if_onFulfilled_is_not_a_function_it_must_be_ignored_2()
{
var promise = new Promise<object>();
var resultPromise = promise
.Then(
(Func<object, IPromise>)null,
ex => { }
);
var resolves = 0;
var errors = 0;
resultPromise.Then(() => ++resolves);
resultPromise.Catch(ex => ++errors);
promise.Resolve(new object());
Assert.Equal(1, resolves);
Assert.Equal(0, errors);
}
示例10: can_chain_promise_and_convert_to_non_value_promise
public void can_chain_promise_and_convert_to_non_value_promise()
{
var promise = new Promise<int>();
var chainedPromise = new Promise();
var promisedValue = 15;
var completed = 0;
promise
.Then(v => chainedPromise)
.Then(() =>
{
++completed;
});
promise.Resolve(promisedValue);
chainedPromise.Resolve();
Assert.Equal(1, completed);
}
示例11: can_chain_promise_and_convert_to_promise_that_yields_a_value
public void can_chain_promise_and_convert_to_promise_that_yields_a_value()
{
var promise = new Promise();
var chainedPromise = new Promise<string>();
var chainedPromiseValue = "some-value";
var completed = 0;
promise
.Then(() => chainedPromise)
.Then(v =>
{
Assert.Equal(chainedPromiseValue, v);
++completed;
});
promise.Resolve();
chainedPromise.Resolve(chainedPromiseValue);
Assert.Equal(1, completed);
}
示例12: can_chain_promise_and_convert_type_of_value
public void can_chain_promise_and_convert_type_of_value()
{
var promise = new Promise<int>();
var chainedPromise = new Promise<string>();
var promisedValue = 15;
var chainedPromiseValue = "blah";
var completed = 0;
promise
.Then(v => chainedPromise)
.Then(v =>
{
Assert.Equal(chainedPromiseValue, v);
++completed;
});
promise.Resolve(promisedValue);
chainedPromise.Resolve(chainedPromiseValue);
Assert.Equal(1, completed);
}
示例13: CanChainPromiseAndConvertToNonValuePromise
public void CanChainPromiseAndConvertToNonValuePromise()
{
var promise = new Promise<int>();
var chainedPromise = new Promise();
const int promisedValue = 15;
var completed = 0;
promise
.Then(v => chainedPromise)
.Then(() =>
{
++completed;
});
promise.Resolve(promisedValue);
chainedPromise.Resolve();
Assert.AreEqual(1, completed);
}
示例14: CanChainPromiseAndConvertTypeOfValue
public void CanChainPromiseAndConvertTypeOfValue()
{
var promise = new Promise<int>();
var chainedPromise = new Promise<string>();
const int promisedValue = 15;
const string chainedPromiseValue = "blah";
var completed = 0;
promise
.Then(v => chainedPromise)
.Then(v =>
{
Assert.AreEqual(chainedPromiseValue, v);
++completed;
});
promise.Resolve(promisedValue);
chainedPromise.Resolve(chainedPromiseValue);
Assert.AreEqual(1, completed);
}
示例15: ThenHandlerIsNotInvokedForRejectedPromise
public void ThenHandlerIsNotInvokedForRejectedPromise()
{
var promise = new Promise<int>();
promise.Then(v =>
{
throw new ApplicationException("This shouldn't happen");
});
promise.Reject(new ApplicationException("Rejection!"));
}