3,341 questions
0
votes
1
answer
146
views
Why XUnit deadlocks if I fire and forget socket.Listen() from async void Method?
I've found a strange behavior that I cannot understand.
The code below is a reduction of the problem. The private async call method Listen() is normally a Method of an object that is called in a Test, ...
0
votes
0
answers
112
views
How can I use the FirstOrDefaultAsync method within the method?
When I run it by replacing the FirstOrDefaultAsync method with FirstOrDefault, the test works as expected. In other words, when I remove the asynchronous structure, my test runs correctly. However, ...
0
votes
1
answer
1k
views
How to mock Httpclient inside method using xunit c#
I am trying to mock Httpclient which is created inside a method with using keyword
Please see the following sample.
Public string testmethod(){
Using(Httpclient client = new Httpclient (){
Var ...
0
votes
0
answers
77
views
Call one scenario from another - Specflow
I have a gherkin and specflow script that registers a user, then in the same script I need to get into an external resource to get the verification code.... If I break it all into 2 different scripts, ...
1
vote
2
answers
437
views
Is there anyway to get the total numbers of tests in xunit?
Is there anyway to get the total numbers of tests in xunit?
I know i can run the tests and get the value that way, but I just want to run a command to get the total amount of tests in my framework for ...
0
votes
1
answer
342
views
How to set priority for InlineData() from Xunit Theory test
I have following test
[Theory(DisplayName = nameof(GenerativeAnswersResponseAsync))]
[InlineData("GenerativeAnswers1", GenerativeAnswers_InDomainTest, false, true)]
[InlineData("...
0
votes
0
answers
200
views
Sharing test data across xUnit Theory tests
I have an api with a 'listing' method that supports some filtering capability. I wanted to write an integration test in xUnit that setup the data once in the database, then run several different ...
1
vote
1
answer
250
views
List of tests in the project
I am writing a small C# project that will count the coverage of all tests individually in a project with tests C#. To do this, I need to get a list of all the tests in the project in the ...
1
vote
0
answers
233
views
Exception: System.Management.ManagementException
Unit tests fail surprisingly after no change with these exception after execution:
System.TypeInitializationException: The type initializer for 'DiffEngine.ProcessCleanup' threw an exception.
System....
0
votes
1
answer
809
views
Mocking internal class without interface
I am trying to mock internal class for unit tests, due to some circular dependency I will not be able to use interface of this class to mock it, I also added unit test assembly name (made sure I am ...
0
votes
1
answer
185
views
How to assert timer callback in c# xunit unit test
I have a OfflineHourlyDatabaseBackup BackgroundService in .NET 8 as shown below.
OfflineHourlyDatabaseBackup:
public class OfflineHourlyDatabaseBackup(
ILogger<OfflineHourlyDatabaseBackup> ...
0
votes
1
answer
585
views
Azure Devops pipeline with xUnit and SonarCloud
Does anyone know if running parallel assemblies to true for xUnit will work with SonarCloud when collecting test coverage? Our unit tests are running long, so we found in the xUnit documentation that ...
0
votes
1
answer
187
views
Faking a lazy out parameter value on a generic interface in FakeItEasy?
I have a generic C# interface that I'm trying to mock with FakeItEasy for an xUnit test like this:
#region FakeItEasyDebugging
public interface IFakeTest<T> : IDisposable where T : new()
...
0
votes
1
answer
935
views
xUnit Collection Fixtures not inherited
I have a pattern of xunit tests along these lines:
a test class matching the class being tested
subclasses for each method being tested
a fixture to support artifacts needed for the test
[Collection(...
1
vote
0
answers
195
views
xUnit Assert.Equivalent throws an System.ArgumentException when trying to test an abstract property with covariant return type
I am using xUnit 2.6.3 (latest stable) to test a .Net 8 project. I have an object that inherits from an abstract class, and the method I'm testing has a return type of the base class. The base class ...
1
vote
0
answers
26
views
Unit tests in C# with xUnit: why setting invariant culture works in base class but not in fixture? [duplicate]
I want to set invariant culture for my test cases, at a test class level.
What I did first is to create a base class for test classes, but it is instantiated for every test case, so culture is set/...
0
votes
1
answer
1k
views
Run dotnet test in ubuntu 18.04 docker container azure pipeline however the test run in ubuntu version of hosted agent
I am trying to run test project in Azure pipeline .My project use TestContainer library for Azure cosmos that only work ubuntu 18.04 although that VmImage version deprecated in Azure hosted agent. so ...
1
vote
0
answers
36
views
Is it possible to extend an Xunit "Collection" instead of having to use an IClassFixture?
I've been converting some existing tests to use Collection. I currently have a case though where I want to do something like this:
[Collection("MyCollection")]
public class SomeTests
{
...
1
vote
1
answer
961
views
How to overwrite connection strings in WebApplicationFactory?
I have an API that I would like to make integration tests for. I have a Program.cs and a custom made Startup.cs which is basically a static class containing extension methods to WebApplicationBuilder ...
0
votes
1
answer
54
views
What is the best practice for testing two methods that perform similar but inverted operations?
As a hobby project I'm building an app in .NET / C# that takes a bitmap, performs some operation, and saves the modified bitmap. Apart from the modification, this requires methods for turning the ...
1
vote
1
answer
341
views
FakeItEasy mocks stuff automatically
So i was writing xUnit tests for my Asp.net Web Api application using FakeItEasy.
Here is my Test which should return a List of MemberDto objects;
public async Task ...
0
votes
1
answer
166
views
How to initiate integration test project for httpApi Rest Api in Abp Framework
I have already Abp framework project without UI. And I am using HttpApi for create rest api
And now i want have integration test for testing this project. But i don't know how to initiate this by ...
1
vote
1
answer
116
views
KeyNotFoundException when trying to access mocked object in dictionary
My mock test is throwing a KeyNotFoundException:
[Fact]
public void MockAssembly_GetTypes_ReturnsMockedTypes()
{
var mockAssembly = new Mock<Assembly>();
mockAssembly.Setup(a => a....
0
votes
1
answer
359
views
AutoMapper with ConstructUsing to map child properties not valid in test, but works in production
I am trying to test the usage of our AutoMapper profiles in our project. I have an object Source which I map to Destination, actually it has about 30 properties, but for this example it will be fine ...
1
vote
1
answer
198
views
Testing with fake IDbContextFactory injecting data during tests
I'm using the EFCore 6.0.16 InMemory database provider to set up some tests, but I am encountering null reference issues when performing context.SaveChanges() on the scoped context after trying to add ...