此问题涉及AutoFixture的CopyAndUpdateAssertion的使用,可在其习语nuget中找到。CopyAndUpdateAssertion - I/O不匹配
假设一个具有类似于这一个类:
public class Foo
{
public static readonly Foo Empty = new Foo(
new Bar1[0],
new Bar2[0]);
private readonly Bar1[] _bars1;
private readonly Bar2[] _bars2;
public Foo(
Bar1[] bars1,
Bar2[] bars2)
{
if (bars1 == null)
throw new ArgumentNullException("bars1");
if (bars2 == null)
throw new ArgumentNullException("bars2");
_bars1 = bars1;
_bars2 = bars2;
}
public Bar1[] Bars1
{
get { return _bars1; }
}
public Bar2[] Bars2
{
get { return _bars2; }
}
public Foo Append(Bar1 value)
{
if (value == null) throw new ArgumentNullException("value");
return new Foo(
_bars1.Concat(new[] {value}).ToArray(),
_bars2);
}
public Foo Append(Bar2 value)
{
if (value == null) throw new ArgumentNullException("value");
return new Foo(
_bars1,
_bars2.Concat(new[] { value }).ToArray());
}
public bool Equals(Foo other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _bars1.SequenceEqual(other._bars1) &&
_bars2.SequenceEqual(other._bars2);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((Foo)obj);
}
public override int GetHashCode()
{
return _bars1.Aggregate(0, (current, next) => current^next.GetHashCode())^
_bars2.Aggregate(0, (current, next) => current^next.GetHashCode());
}
}
是否有可能测试使用CopyAndUpdateAssertion,因为输入是单值的追加方法(例如在“值”)和产出的属性是多值的(例如'Bars1'属性)?如果是,应该更换哪些缺省管道,并且可以提供关于我应该从哪里开始寻找的指示?
是否有可能使'Foo'成为'IBar'的迭代器?然后Concat(以及Append)将成为OOTB,成为一流的公民。 –
在特殊情况下,我正在处理IBar等界面上的螺栓连接,以便在另一边(或访问者)进行铸造。无论如何,Bar1和Bar2之间几乎没有相似之处。在他们上调用的行为是不同的。我确实考虑过这个问题,但它在计算的这一方面会带来的好处让它在另一方面变得更加困难。 –