21
21
using Umbraco . Cms . Web . BackOffice . Controllers ;
22
22
using Umbraco . Cms . Web . BackOffice . Install ;
23
23
using Umbraco . Cms . Web . BackOffice . Routing ;
24
+ using Umbraco . Cms . Web . Common . AspNetCore ;
24
25
using Umbraco . Cms . Web . Common . Security ;
25
26
26
27
namespace Umbraco . Cms . Tests . UnitTests . AutoFixture
27
28
{
29
+
28
30
[ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Constructor ) ]
29
31
public class AutoMoqDataAttribute : AutoDataAttribute
30
32
{
@@ -40,6 +42,7 @@ public AutoMoqDataAttribute()
40
42
41
43
internal static class AutoMockCustomizations
42
44
{
45
+
43
46
public static IFixture Default => new Fixture ( ) . Customize ( new UmbracoCustomization ( ) ) ;
44
47
45
48
private class UmbracoCustomization : ICustomization
@@ -58,7 +61,7 @@ public void Customize(IFixture fixture)
58
61
. Customize ( new ConstructorCustomization ( typeof ( BackOfficeUserManager ) , new GreedyConstructorQuery ( ) ) )
59
62
. Customize ( new ConstructorCustomization ( typeof ( MemberManager ) , new GreedyConstructorQuery ( ) ) ) ;
60
63
61
- fixture . Customize ( new AutoMoqCustomization ( ) ) ;
64
+ fixture . Customize ( new AutoMoqCustomization ( ) { ConfigureMembers = true } ) ;
62
65
63
66
// When requesting an IUserStore ensure we actually uses a IUserLockoutStore
64
67
fixture . Customize < IUserStore < BackOfficeIdentityUser > > ( cc => cc . FromFactory ( ( ) => Mock . Of < IUserLockoutStore < BackOfficeIdentityUser > > ( ) ) ) ;
@@ -71,6 +74,8 @@ public void Customize(IFixture fixture)
71
74
u => u . FromFactory (
72
75
( ) => new UmbracoVersion ( ) ) ) ;
73
76
77
+ fixture . Customize < HostingSettings > ( x =>
78
+ x . With ( settings => settings . ApplicationVirtualPath , string . Empty ) ) ;
74
79
fixture . Customize < BackOfficeAreaRoutes > ( u => u . FromFactory (
75
80
( ) => new BackOfficeAreaRoutes (
76
81
Options . Create ( new GlobalSettings ( ) ) ,
@@ -84,12 +89,18 @@ public void Customize(IFixture fixture)
84
89
Mock . Of < IHostingEnvironment > ( x => x . ToAbsolute ( It . IsAny < string > ( ) ) == "/umbraco" && x . ApplicationVirtualPath == string . Empty ) ,
85
90
Mock . Of < IRuntimeState > ( x => x . Level == RuntimeLevel . Run ) ) ) ) ;
86
91
87
- var connectionStrings = new ConnectionStrings ( ) ;
88
- fixture . Customize < ConnectionStrings > ( x => x . FromFactory ( ( ) => connectionStrings ) ) ;
92
+ var configConnectionString = new ConfigConnectionString ( "ss" ,
93
+ "Data Source=(localdb)\\ MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\ Umbraco.mdf;Integrated Security=True" ) ;
94
+ fixture . Customize < ConfigConnectionString > ( x => x . FromFactory ( ( ) => configConnectionString ) ) ;
95
+
89
96
90
97
var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext ( ) } ;
91
98
fixture . Customize < HttpContext > ( x => x . FromFactory ( ( ) => httpContextAccessor . HttpContext ) ) ;
92
99
fixture . Customize < IHttpContextAccessor > ( x => x . FromFactory ( ( ) => httpContextAccessor ) ) ;
100
+
101
+ fixture . Customize < WebRoutingSettings > ( x => x . With ( settings => settings . UmbracoApplicationUrl , "http://localhost:5000" ) ) ;
102
+
103
+ fixture . Behaviors . Add ( new OmitOnRecursionBehavior ( ) ) ;
93
104
}
94
105
}
95
106
}
0 commit comments