0

Look at the following codes (simple ones)

public class NewEventViewModel : ReactiveObject
{
    readonly ObservableAsPropertyHelper<bool> isSendVisible;
    public bool IsSendVisible
    {
        get { return isSendVisible.Value; }
    }

    private ReactiveList<string> users;

    public ReactiveList<string> Users
    {
        get { return this.users; }
        set { this.RaiseAndSetIfChanged(ref users, value); }
    }

    public NewEventViewModel()
    {

        Users = new ReactiveList<string>(new List<string>())
        {
            ChangeTrackingEnabled = true
        };

        Users.CountChanged
            .Select(x => x > 0)
            .ToProperty(this, x => x.IsSendVisible, out isSendVisible);
        //Users.Add("commented");
    }
}

And the test:

    [Fact]
    public void ShouldBeVisibleWhenIsAtLeastOneUser()
    {
        //var sut = new NewEventViewModel();
        var fixture = new Fixture();
        var sut = fixture.Create<NewEventViewModel>();
        sut.Users.Add("something");
        sut.IsSendVisible.ShouldBeTrue();
    }

The test fails... but when I uncomment the line from ViewModel, it passes.

Looks like the test is ignoring changes to Users. It works when I create the sut manually (new NewEventViewModel()). Why is AutoFixture breaking the test in such a strange way? What am I doing wrong?

user963935
  • 493
  • 4
  • 20
  • When you use `fixture.Create`, by default AutoFixture assigns values to all writable public properties and fields. This included inherited members. Is there a member on the base class that could turn off the event flow? – Mark Seemann Oct 11 '16 at 05:22
  • No, there are only getters and public events. Does AutoFixture work on other thread? – user963935 Oct 11 '16 at 07:02
  • 1
    No, it doesn't. What happens if you create `sut` with `fixture.Build().OmitAutoProperties().Create()`? – Mark Seemann Oct 11 '16 at 08:49
  • Thanks it works! You can respond so others will find the answer easily. – user963935 Oct 11 '16 at 13:25

1 Answers1

1

You can use

fixture.Build<NewEventViewModel>().OmitAutoProperties().Create()

to temporarily turn off auto-properties.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736