Questions tagged [xunit]

xUnit is the collection name for unit-testing compliant frameworks following a specific architecture. Implementation differs from language to language but the framework should consist of a Test Runner, Test Case, Test Fixture (Context), Test Suite, Test Execution, Test Result Formatter and Assertions

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

Share the same test over test classes in xUnit

I am just curious if it is possible to share tests between classes in xUnit. Lets say we have the following: An interface IConfigurationProvider and ConfigurationProvider CachedConfigurationProvider ...
philipp's user avatar
  • 25
1 vote
1 answer
40 views

How to use a Mock in xunit passing a mapped entity

I'm trying to create an unit test using moq on xunit, but the test is failing, I guest is because of the mapper, when the _sut.Create is called it's thrown an exception, if I remove MockBehavior....
Milton Calderon's user avatar
0 votes
0 answers
35 views

Initializing new Entities causes FK exception

I have an integration test exhibiting some strange behavior and I think it's because I'm misunderstanding something about EF Core. The code below is just the "Arrange" portion of the test, ...
Killnine's user avatar
  • 5,782
1 vote
0 answers
31 views

EF insert not using correct id for many-to-many xref table

I am creating integration tests for a repository written around EF. During the setup of my test case, I am getting SqlExceptions about a FK being broken. Entities and entity table configuration ...
Killnine's user avatar
  • 5,782
0 votes
1 answer
17 views

Xunit: Getting Error in Amazone S3 Services Unit Test

I am trying to write a unit test of the method bellow : public class AwsSimpleStorageMediaManager : IMediaManager { private readonly IImageCache imageCache; private readonly IAmazonS3 ...
Wasif Mustahid's user avatar
0 votes
1 answer
44 views

SQLite Unit testing, same tables but different schemas can't create table

I am using EF DbContext to create SQLite Inmemory schema for my unit tests, when it creates tables it throws table already exists even though the are two different schemas like Customer.Order and ...
Praveen Golla's user avatar
0 votes
1 answer
21 views

Xunit.TestFrameworkAttribute not picking up custom XUnitTestFramework from different assembly

I want to reuse this class CustomTestFramework : XunitTestFramework across several test projects to avoid duplicating some simple setup code. The problem I ran across is that the following setup doesn'...
Xzenon's user avatar
  • 1,193
1 vote
0 answers
13 views

Unable to debug code of methods outside of xunit tests

I have some xunit tests. One of them takes list of args from a function that is, obiously, not a test itself. Problem is, breakpoints are never hit in that function, or anywhere but inside xunit tests....
PanBocian's user avatar
0 votes
0 answers
53 views

Integration test passes in local but fails in Azure DevOps

I have written a integration test to validate a Odbc connection string. the test act on opening connection to provided connection string. It passes in my local machine but fails in Azure DevOps ...
Nafisian Castle's user avatar
0 votes
1 answer
66 views

How can I mock IotHubServiceClient for testing purposes? (v2)

I have a class IotHubService that depends on the C# IoTHub SDK's IotHubServiceClient (v2 version of the SDK, currently in preview) to perform various queries on an IoTHub. I'm trying to improve the ...
ameyers-inimco's user avatar
0 votes
0 answers
21 views

Create Integration Test on call external API using API project with TestContainer and xUnit project

After much time crawling on internet for solution, so finally I post this question. public Client(IOptions<Options> options, HttpClient httpClient) { _options = options?.Value ?? ...
Pankaj Gaikwad's user avatar
0 votes
0 answers
35 views

Unit testing Mediator published expected INotification

I have a Blazor server side application that is using events to trigger updates between clients. I have decided to migrate this to instead use MediatR to trigger updates. The actual implementation is ...
dropbear's user avatar
  • 1,520
0 votes
0 answers
31 views

How to get TeamCity + XUnit + Coverlet to work?

I am posting this after 2 days of trying various solutions that didn't work for me. This is mostly for my future reference, but I hope others can benefit as well. I used this source as the basis for ...
Bitfiddler's user avatar
  • 3,942
0 votes
0 answers
13 views

In XUnit moq test The entity type 'IdentityUserLogin<string>' requires a primary key to be defined

I have got problem in unit test with mocked DB context. Error: The entity type 'IdentityUserLogin' requires a primary key to be defined Error occurs on line: _bookContext.RefreshTokens.Add(new ...
Pentium3k's user avatar
0 votes
1 answer
29 views

C# UnitTest hides "run,runall,debug,debug all"-Buttons, although test runs in console succesfully

As mentioned, I have to test some code and wanted to do it with xUnit. Then I have seen, that the buttons under the "[Fact]"-attribute are not shown, however. I use VS Code. I searched for ...
hier's user avatar
  • 1
0 votes
0 answers
22 views

How to mock a static Sitecore method?

we have a static Sitecore method which is called when we fire the test we need to mock the method result, means when its called it should return our mocked result and shouldn't enter into that method. ...
Nikhil's user avatar
  • 15
0 votes
0 answers
26 views

Need some help to create XUnit for my code

I need to write a XUnit Test for my C# code with Visual Studio 2022. I had everything framed up but problem when i created my first or "test" XUnit Project with the solution, it throws me ...
Michael Ng's user avatar
0 votes
1 answer
62 views

How to Unit Test Linq Where() which has a method call in c#

My Source code has var results = searchContext.GetQueryable<Model>().Where(GetSearchPredicate()).GetResults(); private Expression<Func<Model, bool>> GetSearchPredicate() { ...
Nandhini's user avatar
0 votes
0 answers
18 views

xUnit Jenkins Plugin "Cannot create directory"

I'm in the process of writing a declarative Jenkins pipeline as CI for a project. As part of it, I use GoogleTest and feed the generated xml file to an xunit call. It might be noteworthy that in ...
AnonA's user avatar
  • 1
0 votes
1 answer
18 views

Passing a property as an Xunit Theory

I'm trying to create a simple Xunit test that will take a property (not a property.name rather the full property) as a datatype. I've looked at the three types available so I can pass as the Inline/...
Nodoid's user avatar
  • 1,449
0 votes
0 answers
62 views

Implementing non-overlapping calls to a method

I'm developing a websocket client wrapper. The third-party server I'm connecting to manages sessions, and it doesn't tolerate concurrent sessions. If the AuthenticateAsync method is called twice in a ...
nop's user avatar
  • 4,751
0 votes
0 answers
20 views

Multiple calls to token creation in Dependency Injection causing Github Runner to timeout during parallel tests

I am injecting Microsoft.PowerPlatform.Dataverse.Client in Dependency Injection with a tokenProviderFunction sc.AddSingleton<IOrganizationServiceAsync2, ServiceClient>(provider => { var ...
Chris's user avatar
  • 1
0 votes
2 answers
65 views

How to check if an element is focused using bUnit?

Suppose I have a Blazor component <MyButton/> that is implemented like this for simplicity: <button>MyButton</button> And I unit test my component with bUnit as follows: @inherits ...
Behemoth's user avatar
  • 5,847
1 vote
0 answers
32 views

How to mock authentication in .Net core using TestServer / Specflow

I have a .net 7 api that i tried to test cover using Specflow/xUnit but i cannot seem to mock the authentication for my api. I always receive Unauthorized on my authenticated endpoints. The .net 7 api ...
Nicolas G.'s user avatar
-2 votes
1 answer
35 views

Unit Testing overloaded methods C# [closed]

I want to write a common unit test case on two overloaded methods I'll be asserting the same conditions. I want to avoid writing a unit test for each overload. What would be the best approach? ...
shaikhspear's user avatar
0 votes
1 answer
48 views

Trying to get the Content-Type header of the response causes an exception with xUnit

For some reason the last assert of this xUnit test throws an exception: System.InvalidOperationException : Misused header name, 'Content-Type'. Make sure request headers are used with ...
yinivem462's user avatar
0 votes
1 answer
24 views

Reaching the Catch Block with an in-memory approach

I have a TestController class where I'm performing unit tests on a Controller class. The Controller class creates an instance of a Service class named _service. The Controller class has a method with ...
Kyle's user avatar
  • 51
0 votes
0 answers
72 views
+500

How do I convert xUnit/dotnet test output to annotations in GitHub actions using a problem matcher?

I have a GitHub action that runs .NET xUnit tests using dotnet test: jobs: build-net: name: .NET build & test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name:...
Keith's user avatar
  • 150k
0 votes
2 answers
49 views

xUnit Theory. How clear database between tests

I write test using xUnit [Theory]. My problem is that I run first test and it pass, while 2nd test throw exception ---- Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'UNIQUE constraint ...
miuosh's user avatar
  • 836
0 votes
3 answers
106 views

How to return one of the parameters of a NSubstitute mocked method that is async. System.InvalidCastException

I have the following code that compiles. public class Test { [Fact] public async Task ThisShouldWork() { // arrange var dto = new Dto { FName = "...
baynezy's user avatar
  • 6,493
0 votes
0 answers
262 views

Failed to load extensions xunit.runner.visualstudio.dotnetcore.testadapter.dll in Visual Studio

I'm struggling to find a solution for the reason why Visual Studio is throwing me this error while running the xUnit tests locally Failed to load exceptions from .nuget\packages\xunit.runner....
Nițu's user avatar
  • 59
0 votes
1 answer
61 views

The instance of entity type cannot be tracked In Unit Test and in-memory database

I'm testing a service that update something using xUnit and an in-memory database, but I'm getting this error when run the UpdateContractPriceListGoodsItem_WhenEverythingIsOk_ShouldBeSucceeded and ...
Masoud H's user avatar
  • 196
0 votes
1 answer
64 views

How do I configure the concurrency level of XUnit through the the `dotnet test` CLI?

How do I configure the concurrency level of XUnit when run through the the dotnet test CLI ? I've followed the advice from this thread: XUnit dotnet test parallel threads amount and created a xunit....
KeyboardDrummer's user avatar
0 votes
2 answers
60 views

How to parse json object in Value of ActionResult?

I have following code to call a method of my controller. The controller return response as ActionResult in form of json object. The content of okResult.Value is { list = Count = 5, totalCount = 31 } ...
M Javad Salehi's user avatar
0 votes
0 answers
17 views

Mock IRabbitMQFactory using xunit

How to mock the constructor using xunit if I have the following service : public class MyService : IMyService { private readonly IPublisher _publisher; public MyService (...
Midlo215's user avatar
1 vote
1 answer
26 views

Testing a function without a parameter and using moq and xunit

I'm trying to write a unit test for a function: public async Task<IEnumerable<Person>> GetPerson() { var query = "SELECT * FROM Person"; using (var connection = _context....
xoreee's user avatar
  • 53
0 votes
2 answers
51 views

Wiremock XML request matching with XPath contains or RegEx

Need to implement a matching condition with XPath (or with RegEx) text contains and multiple OR values. My request body: <person_obj> <params> <name>David J</name> ...
Divya's user avatar
  • 65
0 votes
0 answers
21 views

Check isunique attribute of an entity in a .net core api

I have this Entity [Index(nameof(Name), IsUnique = true)] public class AccountType:IEntityBase { [Required] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string Id { get; ...
Manta's user avatar
  • 490
0 votes
1 answer
38 views

Architecture test using NetArchTest gives false result when trying to assert sealed class fitness rule

I'm writing Architecture Fitness Test using NetArchTest and I'm trying to Assert if all of my Request Class are sealed using the below test, [Fact] public void Should_Have_Request_To_Be_Sealed() { ...
fingers10's user avatar
  • 6,765
0 votes
0 answers
10 views

xUnit Theory with list of objects

I am trying to use xUnit Theory to complete a unit test under different scenarios I have function that returns the 1st instance of an object that meets a certain criteria. public MyObject ...
Jawahar's user avatar
  • 193
1 vote
1 answer
82 views

why my unit test project is not using proper appsettings.Test.json when appsettings.json contains placeholders?

I have a dotnet core 6 solution. In my API project I have set the appsettings.json to have some placeholders, like that: "Host": #{Logging__StdLog__QueueSettings__Host}#, "Port&...
HalfBloodPrince's user avatar
0 votes
1 answer
38 views

Unit Test Controller with Attribute

I have an attribute that is applied to my controller. The Attribute reads data from cache or adds an item to the cache if its not found. [AttributeUsage(AttributeTargets.Class | AttributeTargets....
user351479's user avatar
0 votes
1 answer
26 views

.Net Core XUnit Issues on Linux

I'm working with .Net Core 5.0.408 on Debian Linux and have a basic project setup as /UnitTest/src/UnitTest.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <...
TheLovelySausage's user avatar
0 votes
0 answers
45 views

Unit testing MassTransit consumer with IBus dependency

I'm trying to write some unit tests for testing a consumer. Consumer code: public sealed class QuotationMessageConsumer : IConsumer<SendQuotationMessage> { private readonly ILogger<...
user3075478's user avatar
0 votes
1 answer
29 views

Xunit For Attach in EF causing null reference exception

I am trying to write xUnit for my update service, but I get a null reference exception public bool Update(string Id, CreateUpdateUserDto InP) { var user = new UserDetails { ...
Upender Reddy's user avatar
0 votes
1 answer
13 views

Resharper test output is empty in visual studio 'show output from'

In Visual Studio 2022, adding some unit test, I could configure the output of each unit test, it's working well as you can see in both images [Red one]. Also, I configured the IMessageSink in a ...
cflorenciav's user avatar
0 votes
0 answers
32 views

I'm trying to use callback to return a different result (from an array of results) each time

I'm trying to mock a method to return a different result each time it's called. This mock will be used by in different tests and the number of possible results may vary. I have been using ...
Peggy W's user avatar
0 votes
0 answers
33 views

How to test internal set from foreign lib?

I have a response object from a foreign lib on which I react on: // Comes from outside public void ResultClass { public bool Succedded { get; internal set; } } Now my method uses it and reacts on ...
PassionateDeveloper's user avatar
0 votes
1 answer
37 views

How to write unit test case using Xunit and moq framework for this method

How to write unit test case using Xunit and moq framework for this method public async Task<View?> GetViewCode(string id, string code) { using var queryFactory = ...
Shailee Rawat's user avatar
0 votes
0 answers
29 views

Unable to return correct response from Query Handler in XUnit Test

I have the following controller: [HttpGet("")] [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] public async Task<IActionResult> FetchCurrentCompany() { var data = ...
Code Ratchet's user avatar
  • 5,777

1
2 3 4 5
64