FluentAssertions System.FormatException(可能的错误)

时间:2017-08-03 21:03:10

标签: c# guid fluent-assertions

我最近在使用FluentAssertions方面遇到了一些麻烦,在稍微讨论一下之后,似乎存在某种与Guid s有关的错误。这是抛出错误的代码:

    class Dto
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
    }



    [TestMethod]
    public void TestTest()
    {
        var dto1 =
            new List<Dto>
            {
                new Dto { Id = Guid.NewGuid(), Name = "Name" }
            };
        var dto2 =
            new List<Dto>
            {
                new Dto { Id = Guid.NewGuid(), Name = "Name" }
            };
        var list1 = new List<List<Dto>> { dto1, dto2 };
        var list2 = new List<List<Dto>> { dto2, dto1 };
        list1.ShouldAllBeEquivalentTo(list2);
    }

请注意list1list2中的反转顺序,这对于重现错误至关重要:

  

System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---&GT; System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---&GT; System.FormatException:索引(从零开始)必须大于或等于零且小于参数列表的大小。   结果StackTrace:
  在System.Text.StringBuilder.AppendFormatHelper(IFormatProvider提供程序,String格式,ParamsArray args)      在System.String.FormatHelper(IFormatProvider提供程序,String格式,ParamsArray args)      在System.String.Format(String format,Object [] args)      在FluentAssertions.Execution.MessageBuilder.FormatArgumentPlaceholders(String failureMessage,Object [] failureArgs)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Execution \ MessageBuilder.cs:第66行      在FluentAssertions.Execution.MessageBuilder.Build(String message,Object [] messageArgs,String reason,ContextDataItems contextData)in C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Execution \ MessageBuilder.cs:第39行      在FluentAssertions.Execution.AssertionScope.FailWith(String message,Object [] args)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Execution \ AssertionScope.cs:第190行      在FluentAssertions.Equivalency.EnumerableEquivalencyValidator.LooselyMatchAgainst [T](IList`1 subject,Object expectation,Int32 expectationIndex)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:line 123      在FluentAssertions.Equivalency.EnumerableEquivalencyValidator.AssertElementGraphEquivalency [T](T [] subject,Object []期望)在C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第79行      at FluentAssertions.Equivalency.EnumerableEquivalencyValidator.Execute [T](T [] subject,Object [] expectation)在C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第39行      在lambda_method(关闭)    ---内部异常堆栈跟踪结束---       at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)      at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object [] parameters,Object [] arguments)      在System.Delegate.DynamicInvokeImpl(Object [] args)      在FluentAssertions.Equivalency.GenericEnumerableEquivalencyStep.Handle(IEquivalencyValidationContext context,IEquivalencyValidator parent,IEquivalencyAssertionOptions config)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ GenericEnumerableEquivalencyStep.cs:第61行      在FluentAssertions.Equivalency.EquivalencyValidator.AssertEqualityUsing(IEquivalencyValidationContext context)C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EquivalencyValidator.cs:第63行      在FluentAssertions.Equivalency.EnumerableEquivalencyValidator.TryToMatch [T](T subject,Object expectation,Int32 expectationIndex)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第133行      在FluentAssertions.Equivalency.EnumerableEquivalencyValidator.LooselyMatchAgainst [T](IList`1 subject,Object expectation,Int32 expectationIndex)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第106行      在FluentAssertions.Equivalency.EnumerableEquivalencyValidator.AssertElementGraphEquivalency [T](T [] subject,Object []期望)在C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第79行      at FluentAssertions.Equivalency.EnumerableEquivalencyValidator.Execute [T](T [] subject,Object [] expectation)在C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EnumerableEquivalencyValidator.cs:第39行      在lambda_method(关闭)    ---内部异常堆栈跟踪结束---       at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)      at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object [] parameters,Object [] arguments)      在System.Delegate.DynamicInvokeImpl(Object [] args)      在FluentAssertions.Equivalency.GenericEnumerableEquivalencyStep.Handle(IEquivalencyValidationContext context,IEquivalencyValidator parent,IEquivalencyAssertionOptions config)中的C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ GenericEnumerableEquivalencyStep.cs:第61行      在FluentAssertions.Equivalency.EquivalencyValidator.AssertEqualityUsing(IEquivalencyValidationContext context)C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EquivalencyValidator.cs:第63行      在FluentAssertions.Equivalency.EquivalencyValidator.AssertEquality(EquivalencyValidationContext context)C:\ projects \ fluentassertions-vf06b \ Src \ Core \ Equivalency \ EquivalencyValidator.cs:第35行      在FluentAssertions.AssertionExtensions.ShouldAllBeEquivalentTo [T](IEnumerable`1 subject,IEnumerable expectation,Func`2 config,String because,Object [] becauseArgs)C:\ projects \ fluentassertions-vf06b \ Src \ Shared \ AssertionExtensions.cs:line 680      在FluentAssertions.AssertionExtensions.ShouldAllBeEquivalentTo [T](IEnumerable`1 subject,IEnumerable expectation,String because,Object [] becauseArgs)C:\ projects \ fluentassertions-vf06b \ Src \ Shared \ AssertionExtensions.cs:line 637      at(我的代码在哪里)

对于长堆栈跟踪感到抱歉,但我希望包含任何可能相关的内容。

这里发生了什么?有什么我想念的吗?

0 个答案:

没有答案