请查看以下代码(简单代码)
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");
}
}
测试:
[Fact]
public void ShouldBeVisibleWhenIsAtLeastOneUser()
{
//var sut = new NewEventViewModel();
var fixture = new Fixture();
var sut = fixture.Create<NewEventViewModel>();
sut.Users.Add("something");
sut.IsSendVisible.ShouldBeTrue();
}
测试失败...但是当我从ViewModel取消注释该行时,它会通过。
看起来测试忽略了对用户的更改。它在我手动创建sut时工作(new NewEventViewModel())。为什么AutoFixture以这种奇怪的方式破坏了测试?我做错了什么?
答案 0 :(得分:1)
您可以使用
fixture.Build<NewEventViewModel>().OmitAutoProperties().Create()
暂时关闭自动属性。