Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Microsoft.AspNetCore.Mvc.Testing and finding documentation
Argamon
#1 Posted : Thursday, April 21, 2022 3:44:05 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2018(UTC)
Posts: 12
Location: Germany

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
I want to write some integration tests for an AspNetCore web api.

In the startup code (Program.cs) there is some code setting up swagger with documentation.

Code:
builder.Services
      .AddSwaggerGen(option =>  option.IncludeXmlComments(filePath));

So how to get this filePath?

If you look up in the net you find something like this:
Code:
var filePath = Path.Combine(AppContext.BaseDirectory, CommentFile);


As long time NCrunch user I am used to rewrite code like this to get the assembly of a type in the project and look for the xml file in the assembly´s directory.

Sadly this does not work here as the NuGet package Microsoft.AspNetCore.Mvc.Testing has a targets file which makes NCrunch copy the assembly (but not the documentation file) to the directory.

So building the solution leads to an output like this:

Code:
bin
  Debug
    api.dll
    api.xml
    api.test.dll


NCrunch creates a structure like this:

Code:
1234
   1
      bin
        Debug
          api.dll
          api.xml
   2
      bin
        Debug
          api.test.dll



Once I add the NuGet package Micrsoft.AspNetCore.Mvc.Testing to my test project the result changes to:

Code:
1234
   1
      bin
        Debug
          api.dll
          api.xml
   2
      bin
        Debug
          api.dll
          api.test.dll


Of course now all my tests fail, cause the file api.xml is not found.

Is there any solution to this?
Argamon
#2 Posted : Thursday, April 21, 2022 9:55:28 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2018(UTC)
Posts: 12
Location: Germany

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Omg, I am sorry for opening this up here in the forums.

After trying to figure out how this works and why everything but the xml file is copied now for hours, I found out that a few levels higher in the repo someone had placed a Directory.build.props with AllowedReferenceRelatedFileExtensions, which effectively blocked copying the xml file.

By adding my own version of the Directory.build.props also including .xml everything works as a charm ;)
1 user thanked Argamon for this useful post.
Remco on 4/22/2022(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.019 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download