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

xUnit has been implemented for most languages, examples include JUnit, NUnit, CUnit, CppUnit, xUnit.net and more. The first implementation was made for Smalltalk by Kent Beck and is called SUnit.

3147 questions
1
vote
2 answers

Run integration test in build pipeline with transformed appsettings

I added an integration test project in my Solution, using .NET Core 3.1 and xUnit. In this test project I also added an appsettings.json with a connectionstring that should be used locally. "ConnectionStrings": { "DefaultConnection": "Data…
Jan V
  • 127
  • 8
1
vote
1 answer

How do you unit test LoggerMessage.Define() in .NET Core 3.1 with Moq?

I'm trying to unit test some usages of LoggerMessage.Define() using the Moq library in xUnit but can't figure it out. The below is an example of a logging function I've created and below that is a sample unit test that failed to check it was…
Benjamin
  • 353
  • 1
  • 4
  • 17
1
vote
1 answer

How to test method in XUnit that needs UserManager, but uses in-memory database

I'm using ASP.NET Core 3.1 and XUnit for my unit tests. I built a database context factory class that instantiates an in-memory version of my database: public static class DbContextFactory { public static ApplicationDbContext CreateDbContext() …
MMilanov
  • 144
  • 1
  • 12
1
vote
1 answer

Net Framework Xunit With Moq Unit Testing Keep Calling The Original Function

I have a problem with mocking cause it keep calling the original function. This is my demo code First file is interface that contains the function that I want to mock. public interface IDemoReplace { int FunctionToBeReplaced(); } Second file is…
Irvan
  • 165
  • 1
  • 13
1
vote
1 answer

Mock handler with parameter Mediatr and Moq

I'm trying to mock a handler with Moq. This handler takes a parameter of type bool to filter out active customers and non active customers. The handler is used in my service: public async Task> GetCustomers(bool…
1
vote
1 answer

Modify on the fly value of long running process for Mocking purposes in Unit test

I have the following method: public async Task ScrapeObjects(int page) { try { while (!isObjectSearchCompleted) { UriBuilder builder = new UriBuilder(_apiSettings.Value.FundaUrl) { …
Tarta
  • 1,729
  • 1
  • 29
  • 63
1
vote
0 answers

Test-case objects missing for the following elements

I'm working on an existing multi project solution with xUnit, dotnet core and netstandard projects but re-sharper tests don't seem to find any tests nor be able to run any independently. I have to do it with the Visual Studio test explorer. The…
diegosasw
  • 13,734
  • 16
  • 95
  • 159
1
vote
1 answer

Test all endpoints for authentication, .Net core 3.0

I want to build integration tests to make sure all of our endpoints are locked behind authentication. I will then fetch all of our endpoints from our swagger. How can i await this call and then use this data as memberData or classData? Since it's…
LittleMygler
  • 632
  • 10
  • 24
1
vote
0 answers

Unit-Test System.IO.Pipelines using MemoryStream

I am trying to test my basic System.IO.Pipelines setup where the memory from the writer will be filled from a TcpClient's stream (ReadAsync-method) similar to this code. Memory memory = writer.GetMemory(minimumBufferSize); int read = await…
0xDECAFBAD
  • 627
  • 1
  • 8
  • 21
1
vote
1 answer

Mocking custom Configuration class

I have a custom class for reading Configuration values in my Azure Function App v2: public class Config { public string Key1 { get; set; } public string Key2 { get; set; } public Config() { this.Key1 =…
The Inquisitive Coder
  • 1,085
  • 3
  • 20
  • 43
1
vote
1 answer

Unable to assert ActionResult which returns jsonresult in Xunit

I'm trying to assert an IActionResult which returns a JsonResult. I'm unable to access the IActionResult Values. How can I do that? UPDATE This is the code. [Fact] public async void AppendEmailTemplateUrl_ReturnOk() { // Arrange …
Csibi Norbert
  • 780
  • 1
  • 11
  • 35
1
vote
3 answers

How to mock a web api for testing

I have a class library which is included some DelegationHandlers, It is simple, get the request, add some headers based on request content and pass the request down. So what I needed is write unit tests for my library. I'm using .NET Core 2.1 and…
Saeid
  • 13,224
  • 32
  • 107
  • 173
1
vote
0 answers

How to pass a preprocessor condition in .NET Core

I have some testing code using condition compilation like below: public class MyFixture : IDisposable { public MyFixture() { #if UseMySqlForTesting ... do A #else ... do B #endif } and…
itminus
  • 23,772
  • 2
  • 53
  • 88
1
vote
1 answer

Moq and multiple method setup

I am trying to learn MOQ as well as unit testing with xUnit at the same time. I have an Authentication logic class with a few methods. They all make use of an AuthenticationDataAccessor. I am trying to mock out that accessor to retain unit test…
Craig
  • 18,074
  • 38
  • 147
  • 248
1
vote
0 answers

How do I Mock User.Identity with MOQ?

I am new to unit testing, and I need to mock the user Identity in my controller. My Test fails at User.Identity.IsAuthenticated. I get a nullReferenceException. I mean this is expected. I believe I just do not know how to use Moq with Identity. …
Alajay Varona
  • 179
  • 1
  • 4