9swampy / InpcTracer

A fluent interface for unit testing INotifyPropertyChanged events

Home Page:https://www.nuget.org/packages/InpcTracer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InpcTracer

========== Inspired by Seikilos
Published on NuGet

I needed to clean up testing of INotifyPropertyChanged implementations in an application I'm working on. Seikilos' Gist inspired me, kudos. I use FakeItEasy and have altered the usage quite a bit by adopting their MustHave(Repeated) fluent syntax to be more consistent.

I'm only dabbling with Git having been an SVN user for many years. Hopefully I'm not stepping on any toes or doing anything incorrect!

Arrange
```csharp ITraceable target = A.Fake(); A.CallTo(target).Where(x => x.Method.Name == "set_Active") .Invokes(() => { target.PropertyChanged += Raise.With(new PropertyChangedEventArgs("Active")).Now; });

var tracer = new InpcTracer.InpcTracer(target);


  <h5>
    <b>Check for one event</b>
  </h5>
```csharp
Assert.IsTrue(tracer.WhileProcessing(() => target.Active = true)
                    .RecordedEvent(() => target.Active)
                    .ExactlyOnce());
// or
tracer.WhileProcessing(() => target.Active = true)
      .RecordedEvent(() => target.Active)
      .MustHaveHappened(Repeated.Exactly.Once);
Check for exact order of two events
```csharp // Check for exact order of two events tracer.WhileProcessing(() => { target.Active = false; target.Active = true; }) .FirstRecordedEvent(() => target.Active) .ThenRecordedEvent(() => target.Active); ```

About

A fluent interface for unit testing INotifyPropertyChanged events

https://www.nuget.org/packages/InpcTracer/


Languages

Language:C# 100.0%