sharparchitecture / Sharp-Architecture

S#arp Architecture: ASP.NET MVC Best Practices with NHibernate
http://sharparchitecture.github.io/
Other
591 stars 152 forks source link

TestDatabaseSetup constructor fails under Linux #250

Closed annamaria-szentpeteri closed 2 years ago

annamaria-szentpeteri commented 2 years ago

Problem

Using the constructor TestDatabaseSetup(Assembly baseAssembly, Assembly[] mappingAssemblies) of TestDatabaseSetup class will fail under Unix-based systems, because UriBuilder can't handle paths which start with slash (\ or /). E.g.:

(CodeBaseLocator.GetAssemblyCodeBasePath uses the UriBuilder class.)

See "Implicit File Path Support" part of Uri Class documentation on why using this class on Unix-based system is problematic.

Stacktrace

---- System.UriFormatException : Invalid URI: The hostname could not be parsed.

  Stack Trace:

----- Inner Stack Trace #1 (System.UriFormatException) -----
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at System.UriBuilder..ctor(String uri)
   at SharpArch.Infrastructure.CodeBaseLocator.GetAssemblyCodeBasePath(Assembly assembly)
   at SharpArch.Testing.NHibernate.TestDatabaseSetup..ctor(Assembly baseAssembly, Assembly[] mappingAssemblies)

Used

.Net (5.0) SharpArch.Testing.Xunit.NHibernate (7.0.0) Xunit (2.4.1) Microsoft.NET.Test.Sdk (16.11.0)

Steps to reproduce

  1. Create new UnitTest project under .Net5.
  2. Install NuGet packages mentioned above.
  3. Use this test class to reproduce problem:
    using System;
    using SharpArch.Testing.NHibernate;
    using Xunit;
    
    namespace SharpArchBug
    {
        public class BugTest : TestDatabaseSetup
        {
            public BugTest() : base(typeof(BugTest).Assembly, new[] {typeof(BugTest).Assembly})
            {
            }
    
            [Fact]
            public void Will_Not_Reach_This_On_Linux()
            {
                Assert.False(false);
            }
        }
    }
    
  4. Run unittests under Unix-based system.