此問題涉及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之間幾乎沒有相似之處。在他們上調用的行爲是不同的。我確實考慮過這個問題,但它在計算的這一方面會帶來的好處讓它在另一方面變得更加困難。 –