本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.IsCollection方法的典型用法代码示例。如果您正苦于以下问题:C# List.IsCollection方法的具体用法?C# List.IsCollection怎么用?C# List.IsCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.IsCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromEventPattern
public void FromEventPattern()
{
var tester = new EventTester();
{
var list = new List<int>();
var d = Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>((h) => h.Invoke, h => tester.genericEventHandler += h, h => tester.genericEventHandler -= h)
.Subscribe(xx =>
{
list.Add(xx.EventArgs.MyProperty);
Observable.Return(xx.EventArgs.MyProperty)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(x));
});
try { tester.Fire(5); } catch { }
try { tester.Fire(1); } catch { }
try { tester.Fire(10); } catch { }
list.IsCollection(5, 5, 1, 10, 10);
d.Dispose();
tester.Fire(1000);
list.Count.Is(5);
}
}
示例2: OfType
public void OfType()
{
var subject = new Subject<object>();
var list = new List<int>();
subject.OfType(default(int)).Subscribe(x => list.Add(x));
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext("hogehoge");
subject.OnNext(3);
list.IsCollection(1, 2, 3);
}
示例3: CurrentThread2
public void CurrentThread2()
{
var scheduler = Scheduler.CurrentThread;
var list = new List<string>();
scheduler.Schedule(() =>
{
list.Add("one");
scheduler.Schedule(TimeSpan.FromSeconds(3), () =>
{
list.Add("after 3");
});
scheduler.Schedule(TimeSpan.FromSeconds(1), () =>
{
list.Add("after 1");
});
});
list.IsCollection("one", "after 1", "after 3");
}
示例4: ToObservable
public void ToObservable()
{
{
var msgs = new List<string>();
new[] { 1, 10, 100, 1000, 10000, 20000 }.ToObservable(Scheduler.CurrentThread)
.Do(i => msgs.Add("DO:" + i))
.Scan((x, y) =>
{
if (y == 100) throw new Exception("exception");
msgs.Add("x:" + x + " y:" + y);
return x + y;
})
.Subscribe(x => msgs.Add(x.ToString()), e => msgs.Add(e.Message), () => msgs.Add("comp"));
msgs.IsCollection("DO:1", "1", "DO:10", "x:1 y:10", "11", "DO:100", "exception");
}
{
var msgs = new List<string>();
new[] { 1, 10, 100, 1000, 10000, 20000 }.ToObservable(Scheduler.Immediate)
.Do(i => msgs.Add("DO:" + i))
.Scan((x, y) =>
{
if (y == 100) throw new Exception("exception");
msgs.Add("x:" + x + " y:" + y);
return x + y;
})
.Subscribe(x => msgs.Add(x.ToString()), e => msgs.Add(e.Message), () => msgs.Add("comp"));
msgs.IsCollection("DO:1", "1", "DO:10", "x:1 y:10", "11", "DO:100", "exception",
"DO:1000", "x:11 y:1000",
"DO:10000", "x:1011 y:10000",
"DO:20000", "x:11011 y:20000"
);
}
}
示例5: ForEachAsync
public void ForEachAsync()
{
{
var list = new List<int>();
var xs = Observable.Range(1, 10).ForEachAsync(x => list.Add(x)).ToArray().Wait();
list.IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
xs.Length.Is(1);
xs[0].Is(Unit.Default);
}
{
var list = new List<int>();
var listI = new List<int>();
var xs = Observable.Range(1, 10).ForEachAsync((x, i) =>
{
list.Add(x);
listI.Add(i);
}).ToArray().Wait();
list.IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
listI.IsCollection(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
xs.Length.Is(1);
xs[0].Is(Unit.Default);
}
}
示例6: ResultSelectorEnumerableWithIndex
public void ResultSelectorEnumerableWithIndex()
{
SetScehdulerForImport();
{
// OnCompleted Case
var a = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3), (x, i1, y, i2) => Tuple.Create(x, i1, y, i2))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
a.OnCompleted();
// check
list.IsCollection("OnNext((10, 0, 0, 0))", "OnNext((10, 0, 1, 1))", "OnNext((10, 0, 2, 2))", "OnNext((100, 1, 1, 0))", "OnNext((100, 1, 1, 1))", "OnNext((100, 1, 1, 2))", "OnCompleted()");
}
{
// OnError Case
var a = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3), (x, i1, y, i2) => Tuple.Create(x, i1, y, i2))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
a.OnError(new Exception());
// check
list.IsCollection("OnNext((10, 0, 0, 0))", "OnNext((10, 0, 1, 1))", "OnNext((10, 0, 2, 2))", "OnNext((100, 1, 1, 0))", "OnNext((100, 1, 1, 1))", "OnNext((100, 1, 1, 2))", "OnError(System.Exception)");
}
UniRx.Scheduler.SetDefaultForUnity();
}
示例7: DoOnTerminate
public void DoOnTerminate()
{
var list = new List<int>();
Observable.Empty<int>().DoOnTerminate(() => list.Add(1000)).DefaultIfEmpty().Wait();
list.IsCollection(1000);
list.Clear();
Observable.Range(1, 5).DoOnTerminate(() => list.Add(1000)).Wait();
list.IsCollection(1000);
list.Clear();
Observable.Range(1, 5).Concat(Observable.Throw<int>(new Exception())).DoOnTerminate(() => list.Add(1000)).Subscribe(_ => { }, _ => { }, () => { });
list.IsCollection(1000);
}
示例8: Subject
public void Subject()
{
// OnCompletedPattern
{
var subject = new Subject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(1, 10, 100, 1000);
subject.OnCompleted();
onCompletedCallCount.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(4);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(0);
onCompletedCallCount.Is(1);
// ++subscription
onNext.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(0);
onCompletedCallCount.Is(1);
}
// OnErrorPattern
{
var subject = new Subject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(1, 10, 100, 1000);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(4);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
onNext.Clear();
exception.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(1);
onCompletedCallCount.Is(0);
}
}
示例9: SelectorWithIndex
public void SelectorWithIndex()
{
{
// OnCompleted Case
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnNext((400, 1))", "OnCompleted()");
}
{
// OnError A
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnError(new Exception());
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
}
{
// OnError B
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnError(new Exception());
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
}
}
示例10: Selector
public void Selector()
{
{
// OnCompleted Case
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany(x => (x == 10) ? b : c)
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext(200)", "OnNext(300)", "OnNext(400)", "OnCompleted()");
}
{
// OnError A
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany(x => (x == 10) ? b : c)
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnError(new Exception());
b.OnCompleted();
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext(200)", "OnNext(300)", "OnError(System.Exception)");
}
{
// OnError B
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany(x => (x == 10) ? b : c)
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
a.OnCompleted();
b.OnError(new Exception());
c.OnNext(400);
c.OnCompleted();
// check
list.IsCollection("OnNext(200)", "OnNext(300)", "OnError(System.Exception)");
}
{
// OnCompleted Case2
var a = new Subject<int>();
var b = new Subject<int>();
var c = new Subject<int>();
var list = new List<string>();
a.SelectMany(x => (x == 10) ? b : c)
.Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
a.OnNext(10);
a.OnNext(100);
// do
b.OnNext(200);
c.OnNext(300);
b.OnCompleted();
c.OnCompleted();
// check
list.IsCollection("OnNext(200)", "OnNext(300)");
a.OnCompleted();
list.IsCollection("OnNext(200)", "OnNext(300)", "OnCompleted()");
}
}
示例11: Enq
public void Enq()
{
var q = new UniRx.InternalUtil.ThreadSafeQueueWorker();
var l = new List<int>();
q.Enqueue(x => l.Add((int)x), 1);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -1);
q.Enqueue(x => l.Add((int)x), 2);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -2);
q.Enqueue(x => l.Add((int)x), 3);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -3);
q.Enqueue(x => l.Add((int)x), 4);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -4);
q.Enqueue(x => l.Add((int)x), 5);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -5);
q.Enqueue(x => l.Add((int)x), 6);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -6);
q.Enqueue(x => l.Add((int)x), 7);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -7);
q.Enqueue(x => l.Add((int)x), 8);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -8);
q.Enqueue(x => l.Add((int)x), 9);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -9);
q.Enqueue(x => l.Add((int)x), 10);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -10);
q.Enqueue(x => l.Add((int)x), 11);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -11);
q.Enqueue(x => l.Add((int)x), 12);
q.ExecuteAll(ex => { });
l.IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
l.Clear();
q.ExecuteAll(ex => { });
l.IsCollection(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11);
l.Clear();
q.ExecuteAll(ex => { });
l.Count.Is(0);
q.Enqueue(x => l.Add((int)x), 1);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -1);
q.Enqueue(x => l.Add((int)x), 2);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -2);
q.Enqueue(x => l.Add((int)x), 3);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -3);
q.Enqueue(x => l.Add((int)x), 4);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -4);
q.Enqueue(x => l.Add((int)x), 5);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -5);
q.Enqueue(x => l.Add((int)x), 6);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -6);
q.Enqueue(x => l.Add((int)x), 7);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -7);
q.Enqueue(x => l.Add((int)x), 8);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -8);
q.Enqueue(x => l.Add((int)x), 9);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -9);
q.Enqueue(x => l.Add((int)x), 10);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -10);
q.Enqueue(x => l.Add((int)x), 11);
q.Enqueue(x => q.Enqueue(_ => l.Add((int)x), null), -11);
q.Enqueue(x => l.Add((int)x), 12);
q.ExecuteAll(ex => { });
l.IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
l.Clear();
q.ExecuteAll(ex => { });
l.IsCollection(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11);
l.Clear();
q.ExecuteAll(ex => { });
l.Count.Is(0);
}
示例12: FromEventUnity
public void FromEventUnity()
{
SetScehdulerForImport();
var tester = new EventTester();
{
var list = new List<int>();
var d = Observable.FromEvent<int>(h => tester.intAction += h, h => tester.intAction -= h)
.Subscribe(xx =>
{
list.Add(xx);
Observable.Return(xx)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(x));
});
try { tester.Fire(5); } catch { }
try { tester.Fire(1); } catch { }
try { tester.Fire(10); } catch { }
list.IsCollection(5, 5, 1, 10, 10);
d.Dispose();
tester.Fire(1000);
list.Count.Is(5);
}
{
var i = 0;
var list = new List<int>();
var d = Observable.FromEvent(h => tester.unitAction += h, h => tester.unitAction -= h)
.Subscribe(xx =>
{
list.Add(i);
Observable.Return(i)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(i));
});
try { i = 5; tester.Fire(5); } catch { }
try { i = 1; tester.Fire(1); } catch { }
try { i = 10; tester.Fire(10); } catch { }
list.IsCollection(5, 5, 1, 10, 10);
d.Dispose();
tester.Fire(1000);
list.Count.Is(5);
}
UniRx.Scheduler.SetDefaultForUnity();
}
示例13: DoOnTerminate
public void DoOnTerminate()
{
SetScehdulerForImport();
var list = new List<int>();
Observable.Empty<int>().DoOnTerminate(() => list.Add(1000)).DefaultIfEmpty().Wait();
list.IsCollection(1000);
list.Clear();
Observable.Range(1, 5).DoOnTerminate(() => list.Add(1000)).Wait();
list.IsCollection(1000);
list.Clear();
Observable.Range(1, 5).Concat(Observable.Throw<int>(new Exception())).DoOnTerminate(() => list.Add(1000)).Subscribe(_ => { }, _ => { }, () => { });
list.IsCollection(1000);
UniRx.Scheduler.SetDefaultForUnity();
}
示例14: ReplaySubject
public void ReplaySubject()
{
SetScehdulerForImport();
// OnCompletedPattern
{
var subject = new ReplaySubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
var _ = subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(1, 10, 100, 1000);
// replay subscription
onNext.Clear();
_.Dispose();
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1, 10, 100, 1000);
subject.OnCompleted();
onCompletedCallCount.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(4);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(0);
onCompletedCallCount.Is(1);
// ++subscription
onNext.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1, 10, 100, 1000);
exception.Count.Is(0);
onCompletedCallCount.Is(1);
}
// OnErrorPattern
{
var subject = new ReplaySubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(1, 10, 100, 1000);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(4);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
onNext.Clear();
exception.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1, 10, 100, 1000);
exception.Count.Is(1);
onCompletedCallCount.Is(0);
}
UniRx.Scheduler.SetDefaultForUnity();
}
示例15: AsyncSubjectTest
public void AsyncSubjectTest()
{
SetScehdulerForImport();
// OnCompletedPattern
{
var subject = new AsyncSubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.Count.Is(0);
subject.OnCompleted();
onNext.IsCollection(1000);
onCompletedCallCount.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(1);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(0);
onCompletedCallCount.Is(1);
// ++subscription
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1000, 1000);
exception.Count.Is(0);
onCompletedCallCount.Is(2);
}
// OnErrorPattern
{
var subject = new AsyncSubject<int>();
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.Count.Is(0);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(0);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(2);
onCompletedCallCount.Is(0);
}
UniRx.Scheduler.SetDefaultForUnity();
}