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?
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
add a comment |
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
Debugger.Break
?
– shahkalpesh
2 days ago
@shahkalpesh: No, you cannot use Debugger.Break in an expression.
– Karel Kral
2 days ago
add a comment |
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
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
c# unit-testing fluent-assertions
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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;
Thanks, I was trapped into "Expressions mystery" and missed so simple solution!
– Karel Kral
2 days ago
add a comment |
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.
add a comment |
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)
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
Thanks, I was trapped into "Expressions mystery" and missed so simple solution!
– Karel Kral
2 days ago
add a comment |
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;
Thanks, I was trapped into "Expressions mystery" and missed so simple solution!
– Karel Kral
2 days ago
add a comment |
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;
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;
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 days ago
Dennis DoomenDennis Doomen
5,0291837
5,0291837
add a comment |
add a comment |
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Debugger.Break
?– shahkalpesh
2 days ago
@shahkalpesh: No, you cannot use Debugger.Break in an expression.
– Karel Kral
2 days ago