天道酬勤,学无止境

semantic-comparison

为什么使用 AutoFixture Freeze、SemanticComparison Likeness 和 CreateProxy 不能通过简单的测试?(Why doesn't simple test pass using AutoFixture Freeze, SemanticComparison Likeness and CreateProxy?)

问题 我试图了解如何使用一个简单类的两个实例来使用Likeness<T>()的CreateProxy()功能。 public class Band { public string Strings { get; set; } public string Brass { get; set; } } 在下面的测试中,我使用Fixture Create<T>一个带有两个字符串属性值的Band实例。 [Fact] public void Equality_Behaves_As_Expected() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var original = fixture.Create<Band>(); // Brass something like --> "Brass65756b89-d9f3-42f8-88fc-ab6de5ae65cd" // Strings something like --> "Strings7439fa1b-014d-4544-8428-baea66858940" // act var dupe = new Band {Brass = original.Brass, Strings = original

2021-08-11 04:34:41    分类:技术分享    autofixture   semantic-comparison

Why doesn't simple test pass using AutoFixture Freeze, SemanticComparison Likeness and CreateProxy?

I'm trying to understand how to use the CreateProxy() feature of Likeness<T>() using two instances of a simple class. public class Band { public string Strings { get; set; } public string Brass { get; set; } } With the following test, I use a Fixture to Create<T> a Band instance with values for the two string properties. [Fact] public void Equality_Behaves_As_Expected() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var original = fixture.Create<Band>(); // Brass something like --> "Brass65756b89-d9f3-42f8-88fc-ab6de5ae65cd" // Strings something like -

2021-07-12 07:16:37    分类:问答    autofixture   semantic-comparison

相似——抛光和包装(Likeness - polishing and packaging)

问题 我使用Ploeh.SemanticComparison的Likeness ,以此来映射过程中有效地表达预期的产出(如在PluralSight马克西曼的优秀先进单位测试过程中所描述的)。 我正在测试一些数据是否正确映射,如下所示: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name, Version = version }; expected.AsSource().OfLikeness<NewMappingsEvent>() .Without( y => y.ProgrammaticIdentifier) .ShouldEqual(result); } 但是,我不高兴:- 我想为.Without( y => y.ProgrammaticIdentifier)应用一个名称(即命名我的.Without( y => y.ProgrammaticIdentifier)自定义) 我已经失去了Assert

2021-06-10 06:37:58    分类:技术分享    c#   unit-testing   xunit   autofixture   semantic-comparison

Likeness - polishing and packaging

I'm using Ploeh.SemanticComparison's Likeness as a way to effectively express intended outputs of a mapping process (as described in Mark Seemann's excellent Advanced Unit Testing course on PluralSight). I'm testing some data has mapped correctly, which looks like this: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name, Version = version }; expected.AsSource().OfLikeness<NewMappingsEvent>() .Without( y => y

2021-05-12 04:31:57    分类:问答    c#   unit-testing   xunit   autofixture   semantic-comparison

将[AutoFixture] SemanticComparison OfLikeness应用于序列/集合/数组/ IEnumerable(Applying [AutoFixture] SemanticComparison OfLikeness to sequences / collections / arrays / IEnumerable)

问题 我们编写了一个如下所示的测试。 此测试需要,我们已经创建连接Equal -过载为CodeTableItem -class: ICollection<CodeTableItem> expectedValutaList = new List<CodeTableItem>(); expectedValutaList.Add(new CodeTableItem("DKK", "DKK")); expectedValutaList.Add(new CodeTableItem("EUR", "EUR")); RepoDac target = new RepoDac(); var actual = target.GetValutaKd(); CollectionAssert.AreEqual(expectedValutaList.ToList(),actual.ToList()); 该测试工作正常,但不幸的是,它依赖于Equality函数,这意味着如果我将CodeTableItem扩展一个字段,而忘记扩展Equals function,则单元测试仍会以绿色运行,尽管我们并未进行测试适用于所有领域。 我们希望避免这种Equality污染(请参阅“测试特定的均等”),其编写仅是为了符合测试要求。 我们尝试使用OfLikeness ,并以这种方式重写了测试: ICollection

2021-04-21 11:09:00    分类:技术分享    .net   unit-testing   collections   autofixture   semantic-comparison

Applying [AutoFixture] SemanticComparison OfLikeness to sequences / collections / arrays / IEnumerable

We have written a test which looks like the following. This test requires that we have created en Equal-overload for the CodeTableItem-class: ICollection<CodeTableItem> expectedValutaList = new List<CodeTableItem>(); expectedValutaList.Add(new CodeTableItem("DKK", "DKK")); expectedValutaList.Add(new CodeTableItem("EUR", "EUR")); RepoDac target = new RepoDac(); var actual = target.GetValutaKd(); CollectionAssert.AreEqual(expectedValutaList.ToList(),actual.ToList()); The test works fine, but has the unfortunate dependency to the Equality-function, meaning if I extend the CodeTableItem-class with

2021-04-09 05:43:19    分类:问答    .net   unit-testing   collections   autofixture   semantic-comparison