24 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
-3
votes
3
answers
197
views
Async or sync functions in unit tests?
Consider this unit test of an API client with an async function Index. Index should throw an exception when an http error occurs and thats what I want to test.
public async Task TestServiceError()
{
...
2
votes
1
answer
283
views
Shouldly equivalent functionality of FluentAssertions.EquivalentTo
I have two classes:
class ClassA
{
public required string Name { get; set; }
}
class ClassB
{
public required string Name { get; set; }
}
With FluentAssertions this test succeeds:
classA....
0
votes
0
answers
35
views
Is it possible to increase the size of the assertion message buffer?
I'm writing tests to make sure the output of a thing matches an expected result. The only hitch is that the actual and expected texts are about 9KB each. When the comparison fails, Shouldly cuts off ...
1
vote
2
answers
166
views
How should I compare the values of non-nullable and nullable types using ShouldBe in Shouldly?
In the following code, o[0].AccountEnabled has type bool while graphUsers[0].AccountEnabled has type bool?.
Without the explicit cast to bool?, I get the following error:
'bool' does not contain a ...
1
vote
2
answers
238
views
Should.ThrowAsync not catching exception from HttpClient.GetAsync() request
In our project we have a test written by a former colleague that is firing a request to an end point, which should - and does - return a 500 - InternalServerError (checking for this using Shouldly) ...
2
votes
1
answer
237
views
How can I properly assert multi-sorts with Shouldly?
Let's say I have a simple data class as such.
public class SortMeClass
{
public string StringProp { get; set; }
public int IntProp { get; set; }
}
I then take a collection of SortMeClass ...
0
votes
1
answer
383
views
How to assert the date format of a string using Shouldly and c#
I would like to check that the string from a textbox is of format "dd-MMM-yyyy"
e.g. 14-Mar-2023
I have written the following code but I get an error
string date = Page.HeaderDate().Text
...
0
votes
1
answer
517
views
How to assert sending an email in unit testing
I have a method to send an email. How can I write a unit test to verify this method. I'm using MS test with shouldly
public async Task SendEmail(string Id, string exception)
{
...
4
votes
1
answer
3k
views
How to choose between Shouldly and FluentAssertions? [closed]
What are the differences (if any) between Shouldly and FluentAssertions?
Can either do anything that the other one can't? Or are they functionally the same with just a different syntax?
The only other ...
1
vote
1
answer
1k
views
Dictionary<string, string[]> ShouldContainKeyAndValue fails unit test despite finding the expected value
I wrote this unit test using XUnit and Shouldly. Please note that I replaced parts of the namespace, variable names, properties etc, as the customer is a large public organization.
[Fact]
public async ...
10
votes
1
answer
3k
views
How can I have custom asserts with Shouldly and maintain the call-site-specific assertion messages?
I'm using the excellent Shouldly library in my xUnit tests and I'm finding myself using the set sequence of assertions in different tests, so I'm combining them into new assertion extension methods - ...
1
vote
2
answers
1k
views
Assert duplicate element in unit testing
How can I to make a unit test check that a list of object not contains a duplicate element based on some properties.
Here is what I tried to do:
[Fact]
public void ...
1
vote
1
answer
697
views
Visual Studio - disable stepping into source code of module (Shouldly)
I am using a an assertion framework called Shouldly for C#.
The code looks like this:
[Fact]
public void SimpleTest()
{
false.ShouldBe(true);
}
This is the same as:
[Fact]
public void ...
0
votes
1
answer
256
views
Is there a Resharper pattern for sequential Shouldly asserts?
I'm trying to come up with a Resharper pattern to apply to sequential Shouldly asserts.
For instance, I have these checks:
field1.ShouldNotBeNull();
field2.ShouldBe(expectedField2Value);
And ...
2
votes
3
answers
3k
views
Test two conditions with shouldly
I have a property in a class
public class User {
public string FiscalCode {get; set;}
}
And i want test the property fiscal code with two condition.
The test is ok if fiscalcode is null or ...