示例#1
0
    public void Dispose()
    {
        using var src = new EventSource <String>();
        var rec = EventRecorder.From(src.Event);

        src.Invoke("aaa");
        rec.Dispose();
        src.Invoke("bbb");

        Check.That(rec.Count)
        .IsEqualTo(1);

        Check.That(rec.Events)
        .ContainsExactly("aaa");

        Check.That(rec.EventInfos)
        .HasSize(1);

        var info1 = rec.EventInfos[0];

        Check.That(info1.Value)
        .IsEqualTo("aaa");

        Check.That(info1.Index)
        .IsEqualTo(0);

        Check.That(info1.Timestamp - DateTimeOffset.Now)
        .IsLessThan(TimeSpan.FromMilliseconds(500));

        Check.That(info1.TimeOffset)
        .IsEqualTo(TimeSpan.Zero);

        Check.That(info1.Thread)
        .IsEqualTo(Thread.CurrentThread);
    }
示例#2
0
    public void Resume()
    {
        using var src = new EventSource <String>();
        var rec = EventRecorder.From(src.Event);

        rec.Pause();
        src.Invoke("aaa");

        Check.That(rec.IsPaused)
        .IsTrue();

        Check.That(rec.Count)
        .IsEqualTo(0);

        rec.Resume();
        src.Invoke("bbb");

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(1);

        Check.That(rec.Events)
        .ContainsExactly("bbb");
    }
示例#3
0
    public void Construction()
    {
        var rec = EventRecorder.From(new Event <String>());

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(0);

        Check.That(rec.Events)
        .IsEmpty();

        Check.That(rec.EventInfos)
        .IsEmpty();
    }
示例#4
0
    public void From_EventSource()
    {
        var src = new EventSource <String>();
        var rec = EventRecorder.From(src);

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(0);

        Check.That(rec.Events)
        .IsEmpty();

        Check.That(rec.EventInfos)
        .IsEmpty();
    }
示例#5
0
    public void Reset_ClearsEvents()
    {
        using var src = new EventSource <String>();
        var rec = EventRecorder.From(src.Event);

        src.Invoke("aaa");

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(1);

        rec.Reset();

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(0);
    }
示例#6
0
    public void EventInfos_Returns_CachedResults()
    {
        using var src = new EventSource <String>();
        var rec = EventRecorder.From(src.Event);

        src.Invoke("aaa");

        var infos1 = rec.EventInfos;
        var infos2 = rec.EventInfos;

        Check.That(infos1)
        .HasSize(1);

        Check.That(infos1)
        .IsSameReferenceAs(infos2);

        src.Invoke("bbb");

        Check.That(rec.EventInfos)
        .HasSize(2);

        Check.That(rec.EventInfos)
        .Not.IsSameReferenceAs(infos1);
    }
示例#7
0
 public void From_NullEventSource()
 {
     Check.ThatCode(() => EventRecorder.From <Int32>(null))
     .Throws <ArgumentNullException>();
 }
示例#8
0
    public void Record_MultipleEvents()
    {
        using var src = new EventSource <String>();
        var rec = EventRecorder.From(src.Event);

        src.Invoke("aaa");
        Thread.Sleep(200);
        src.Invoke("bbb");
        Thread.Sleep(200);
        src.Invoke("ccc");

        Check.That(rec.IsPaused)
        .IsFalse();

        Check.That(rec.Count)
        .IsEqualTo(3);

        Check.That(rec.Events)
        .ContainsExactly("aaa", "bbb", "ccc");

        Check.That(rec.EventInfos)
        .HasSize(3);

        var info1 = rec.EventInfos[0];
        var info2 = rec.EventInfos[1];
        var info3 = rec.EventInfos[2];

        Check.That(info1.Value)
        .IsEqualTo("aaa");

        Check.That(info1.Index)
        .IsEqualTo(0);

        Check.That(info1.Timestamp - DateTimeOffset.Now)
        .IsLessThan(TimeSpan.FromMilliseconds(500));

        Check.That(info1.TimeOffset)
        .IsEqualTo(TimeSpan.Zero);

        Check.That(info1.Thread)
        .IsEqualTo(Thread.CurrentThread);

        Check.That(info2.Value)
        .IsEqualTo("bbb");

        Check.That(info2.Index)
        .IsEqualTo(1);

        Check.That(info2.Timestamp - DateTimeOffset.Now)
        .IsLessThan(TimeSpan.FromMilliseconds(500));

        Check.That(info2.TimeOffset)
        .IsLessThan(TimeSpan.FromMilliseconds(500))
        .And.IsGreaterThan(TimeSpan.FromMilliseconds(200));

        Check.That(info2.Thread)
        .IsEqualTo(Thread.CurrentThread);

        Check.That(info3.Value)
        .IsEqualTo("ccc");

        Check.That(info3.Index)
        .IsEqualTo(2);

        Check.That(info3.Timestamp - DateTimeOffset.Now)
        .IsLessThan(TimeSpan.FromMilliseconds(500));

        Check.That(info3.TimeOffset)
        .IsLessThan(TimeSpan.FromMilliseconds(500))
        .And.IsGreaterThan(TimeSpan.FromMilliseconds(200));

        Check.That(info3.Thread)
        .IsEqualTo(Thread.CurrentThread);

        Check.That(info1.Timestamp < info2.Timestamp)
        .IsTrue();

        Check.That(info2.Timestamp < info3.Timestamp)
        .IsTrue();
    }