FluentAssertions: how to set breakpoint inside lambda2019 Community Moderator ElectionHow do I calculate someone's age in C#?How do I test a private function or a class that has private methods, fields or inner classes?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Distinct() with lambda?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How do I generate a random int number?What is a NullReferenceException, and how do I fix it?

Should I apply for my boss's promotion?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

Was this cameo in Captain Marvel computer generated?

Can I negotiate a patent idea for a raise, under French law?

How to make sure I'm assertive enough in contact with subordinates?

PTIJ: Sport in the Torah

Generating a list with duplicate entries

Was it really inappropriate to write a pull request for the company I interviewed with?

How do you make a gun that shoots melee weapons and/or swords?

How do you use environments that have the same name within a single latex document?

Ultrafilters as a double dual

Did Amazon pay $0 in taxes last year?

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

What exactly is the meaning of "fine wine"?

What is Tony Stark injecting into himself in Iron Man 3?

Too soon for a plot twist?

If nine coins are tossed, what is the probability that the number of heads is even?

Why restrict private health insurance?

Why aren't there more Gauls like Obelix?

Should we avoid writing fiction about historical events without extensive research?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Use Mercury as quenching liquid for swords?

Inorganic chemistry handbook with reaction lists

Is there a math expression equivalent to the conditional ternary operator?



FluentAssertions: how to set breakpoint inside lambda



2019 Community Moderator ElectionHow do I calculate someone's age in C#?How do I test a private function or a class that has private methods, fields or inner classes?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Distinct() with lambda?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?How do I generate a random int number?What is a NullReferenceException, and how do I fix it?










1















FluentAssertions is a great library but often I am very frustrated when some code in lambda is not working as expected and I cannot debug it. Especially when lambda is complicated.



payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) &&
rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId));


In this case, I would like to set a breakpoint into inside OnlyContain(...) lambda and debug it. But this is not possible - breakpoint is set always at the whole statement. I suppose that the reason is that lambdas in FluentAssertions are expressions.



Is there any way how to achieve this?



Edit: Extracting lambda as local variable does not help. Behavior is the same.



System.Linq.Expressions.Expression<Func<ResourceRelation, bool>> predicate = rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) && rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId);

payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(predicate);


Edit2: Here is really simple and verifiable example. You cannot put a breakpoint into num == 1, nor extract it as local function, nor display it at watch.



[Fact]
public void SimpleLambdaTest()

int[] nums = Enumerable.Range(1, 10).ToArray();
nums.Should().OnlyContain(num => num == 1);










share|improve this question
























  • Debugger.Break?

    – shahkalpesh
    2 days ago











  • @shahkalpesh: No, you cannot use Debugger.Break in an expression.

    – Karel Kral
    2 days ago















1















FluentAssertions is a great library but often I am very frustrated when some code in lambda is not working as expected and I cannot debug it. Especially when lambda is complicated.



payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) &&
rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId));


In this case, I would like to set a breakpoint into inside OnlyContain(...) lambda and debug it. But this is not possible - breakpoint is set always at the whole statement. I suppose that the reason is that lambdas in FluentAssertions are expressions.



Is there any way how to achieve this?



Edit: Extracting lambda as local variable does not help. Behavior is the same.



System.Linq.Expressions.Expression<Func<ResourceRelation, bool>> predicate = rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) && rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId);

payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(predicate);


Edit2: Here is really simple and verifiable example. You cannot put a breakpoint into num == 1, nor extract it as local function, nor display it at watch.



[Fact]
public void SimpleLambdaTest()

int[] nums = Enumerable.Range(1, 10).ToArray();
nums.Should().OnlyContain(num => num == 1);










share|improve this question
























  • Debugger.Break?

    – shahkalpesh
    2 days ago











  • @shahkalpesh: No, you cannot use Debugger.Break in an expression.

    – Karel Kral
    2 days ago













1












1








1


0






FluentAssertions is a great library but often I am very frustrated when some code in lambda is not working as expected and I cannot debug it. Especially when lambda is complicated.



payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) &&
rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId));


In this case, I would like to set a breakpoint into inside OnlyContain(...) lambda and debug it. But this is not possible - breakpoint is set always at the whole statement. I suppose that the reason is that lambdas in FluentAssertions are expressions.



Is there any way how to achieve this?



Edit: Extracting lambda as local variable does not help. Behavior is the same.



System.Linq.Expressions.Expression<Func<ResourceRelation, bool>> predicate = rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) && rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId);

payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(predicate);


Edit2: Here is really simple and verifiable example. You cannot put a breakpoint into num == 1, nor extract it as local function, nor display it at watch.



[Fact]
public void SimpleLambdaTest()

int[] nums = Enumerable.Range(1, 10).ToArray();
nums.Should().OnlyContain(num => num == 1);










share|improve this question
















FluentAssertions is a great library but often I am very frustrated when some code in lambda is not working as expected and I cannot debug it. Especially when lambda is complicated.



payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) &&
rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId));


In this case, I would like to set a breakpoint into inside OnlyContain(...) lambda and debug it. But this is not possible - breakpoint is set always at the whole statement. I suppose that the reason is that lambdas in FluentAssertions are expressions.



Is there any way how to achieve this?



Edit: Extracting lambda as local variable does not help. Behavior is the same.



System.Linq.Expressions.Expression<Func<ResourceRelation, bool>> predicate = rel =>
rel.RelationType.MatchTo(RelationType.ArtifactLink) && rel.Href.AbsoluteUri.StartsWith(VsTfsSchema.GitPullRequestId);

payload.Resource.Relations.Removed.Should().NotBeNull()
.And.HaveCount(2)
.And.AllBeOfType<ResourceRelation>()
.And.OnlyContain(predicate);


Edit2: Here is really simple and verifiable example. You cannot put a breakpoint into num == 1, nor extract it as local function, nor display it at watch.



[Fact]
public void SimpleLambdaTest()

int[] nums = Enumerable.Range(1, 10).ToArray();
nums.Should().OnlyContain(num => num == 1);







c# unit-testing fluent-assertions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Karel Kral

















asked 2 days ago









Karel KralKarel Kral

3,02842631




3,02842631












  • Debugger.Break?

    – shahkalpesh
    2 days ago











  • @shahkalpesh: No, you cannot use Debugger.Break in an expression.

    – Karel Kral
    2 days ago

















  • Debugger.Break?

    – shahkalpesh
    2 days ago











  • @shahkalpesh: No, you cannot use Debugger.Break in an expression.

    – Karel Kral
    2 days ago
















Debugger.Break?

– shahkalpesh
2 days ago





Debugger.Break?

– shahkalpesh
2 days ago













@shahkalpesh: No, you cannot use Debugger.Break in an expression.

– Karel Kral
2 days ago





@shahkalpesh: No, you cannot use Debugger.Break in an expression.

– Karel Kral
2 days ago












3 Answers
3






active

oldest

votes


















2














You can extract the expression body into a static function, in which you can set a breakpoint.



Note that EqualsOne cannot be a local function and cannot be passed as a method group.



[Fact]
public void SimpleLambdaTest()

int[] nums = Enumerable.Range(1, 10).ToArray();
nums.Should().OnlyContain(num => EqualsOne(num));


private static bool EqualsOne(int num)

// You can put a break point here
return num == 1;






share|improve this answer

























  • Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

    – Karel Kral
    2 days ago


















1














Although this has nothing to do with FluentAssertions, I do this quite often with Jetbrains Rider. When you try to set a breakpoint, it'll ask you where you want to have it; on the entire line, on an individual lambda, etc. I haven't debugged with Visual Studio for almost two years now, so I don't know if it can handle.






share|improve this answer






























    0














    Even if so, if you hit F11 on the breaked line debug should take you to the lambda expression. If not, you can still use Add Watch or Quick Watch facility (Select the lambda expression -> right click and select Quick Watch)






    share|improve this answer























    • No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

      – Karel Kral
      2 days ago











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022321%2ffluentassertions-how-to-set-breakpoint-inside-lambda%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can extract the expression body into a static function, in which you can set a breakpoint.



    Note that EqualsOne cannot be a local function and cannot be passed as a method group.



    [Fact]
    public void SimpleLambdaTest()

    int[] nums = Enumerable.Range(1, 10).ToArray();
    nums.Should().OnlyContain(num => EqualsOne(num));


    private static bool EqualsOne(int num)

    // You can put a break point here
    return num == 1;






    share|improve this answer

























    • Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

      – Karel Kral
      2 days ago















    2














    You can extract the expression body into a static function, in which you can set a breakpoint.



    Note that EqualsOne cannot be a local function and cannot be passed as a method group.



    [Fact]
    public void SimpleLambdaTest()

    int[] nums = Enumerable.Range(1, 10).ToArray();
    nums.Should().OnlyContain(num => EqualsOne(num));


    private static bool EqualsOne(int num)

    // You can put a break point here
    return num == 1;






    share|improve this answer

























    • Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

      – Karel Kral
      2 days ago













    2












    2








    2







    You can extract the expression body into a static function, in which you can set a breakpoint.



    Note that EqualsOne cannot be a local function and cannot be passed as a method group.



    [Fact]
    public void SimpleLambdaTest()

    int[] nums = Enumerable.Range(1, 10).ToArray();
    nums.Should().OnlyContain(num => EqualsOne(num));


    private static bool EqualsOne(int num)

    // You can put a break point here
    return num == 1;






    share|improve this answer















    You can extract the expression body into a static function, in which you can set a breakpoint.



    Note that EqualsOne cannot be a local function and cannot be passed as a method group.



    [Fact]
    public void SimpleLambdaTest()

    int[] nums = Enumerable.Range(1, 10).ToArray();
    nums.Should().OnlyContain(num => EqualsOne(num));


    private static bool EqualsOne(int num)

    // You can put a break point here
    return num == 1;







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    Jonas NyrupJonas Nyrup

    640410




    640410












    • Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

      – Karel Kral
      2 days ago

















    • Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

      – Karel Kral
      2 days ago
















    Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

    – Karel Kral
    2 days ago





    Thanks, I was trapped into "Expressions mystery" and missed so simple solution!

    – Karel Kral
    2 days ago













    1














    Although this has nothing to do with FluentAssertions, I do this quite often with Jetbrains Rider. When you try to set a breakpoint, it'll ask you where you want to have it; on the entire line, on an individual lambda, etc. I haven't debugged with Visual Studio for almost two years now, so I don't know if it can handle.






    share|improve this answer



























      1














      Although this has nothing to do with FluentAssertions, I do this quite often with Jetbrains Rider. When you try to set a breakpoint, it'll ask you where you want to have it; on the entire line, on an individual lambda, etc. I haven't debugged with Visual Studio for almost two years now, so I don't know if it can handle.






      share|improve this answer

























        1












        1








        1







        Although this has nothing to do with FluentAssertions, I do this quite often with Jetbrains Rider. When you try to set a breakpoint, it'll ask you where you want to have it; on the entire line, on an individual lambda, etc. I haven't debugged with Visual Studio for almost two years now, so I don't know if it can handle.






        share|improve this answer













        Although this has nothing to do with FluentAssertions, I do this quite often with Jetbrains Rider. When you try to set a breakpoint, it'll ask you where you want to have it; on the entire line, on an individual lambda, etc. I haven't debugged with Visual Studio for almost two years now, so I don't know if it can handle.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Dennis DoomenDennis Doomen

        5,0291837




        5,0291837





















            0














            Even if so, if you hit F11 on the breaked line debug should take you to the lambda expression. If not, you can still use Add Watch or Quick Watch facility (Select the lambda expression -> right click and select Quick Watch)






            share|improve this answer























            • No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

              – Karel Kral
              2 days ago
















            0














            Even if so, if you hit F11 on the breaked line debug should take you to the lambda expression. If not, you can still use Add Watch or Quick Watch facility (Select the lambda expression -> right click and select Quick Watch)






            share|improve this answer























            • No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

              – Karel Kral
              2 days ago














            0












            0








            0







            Even if so, if you hit F11 on the breaked line debug should take you to the lambda expression. If not, you can still use Add Watch or Quick Watch facility (Select the lambda expression -> right click and select Quick Watch)






            share|improve this answer













            Even if so, if you hit F11 on the breaked line debug should take you to the lambda expression. If not, you can still use Add Watch or Quick Watch facility (Select the lambda expression -> right click and select Quick Watch)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            RahulRahul

            62.8k124483




            62.8k124483












            • No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

              – Karel Kral
              2 days ago


















            • No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

              – Karel Kral
              2 days ago

















            No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

            – Karel Kral
            2 days ago






            No, this does not work also. I can display predicate in a debugger, but it is expression also. Also, what value could be displayed, if the breakpoint is not inside the lambda? This is what I see in Watch: + predicate rel => (rel.RelationType.MatchTo("ArtifactLink") AndAlso rel.Href.AbsoluteUri.StartsWith("vstfs:///Git/PullRequestId")) System.Linq.Expressions.Expression<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>> System.Linq.Expressions.Expression1<System.Func<Scia.Cid.AppServer.Tfs.Api.Payloads.ResourceRelation, bool>>

            – Karel Kral
            2 days ago


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022321%2ffluentassertions-how-to-set-breakpoint-inside-lambda%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко