2
2
// See LICENSE for more details.
3
3
4
4
using System ;
5
- using System . Linq ;
6
- using AutoFixture ;
7
- using AutoFixture . AutoMoq ;
8
- using AutoFixture . Kernel ;
9
5
using AutoFixture . NUnit3 ;
10
- using Microsoft . AspNetCore . Http ;
11
- using Microsoft . AspNetCore . Identity ;
12
- using Microsoft . Extensions . Options ;
13
- using Moq ;
14
- using Umbraco . Cms . Core ;
15
- using Umbraco . Cms . Core . Composing ;
16
- using Umbraco . Cms . Core . Configuration ;
17
- using Umbraco . Cms . Core . Configuration . Models ;
18
- using Umbraco . Cms . Core . Hosting ;
19
- using Umbraco . Cms . Core . Security ;
20
- using Umbraco . Cms . Core . Services ;
21
- using Umbraco . Cms . Web . BackOffice . Controllers ;
22
- using Umbraco . Cms . Web . BackOffice . Install ;
23
- using Umbraco . Cms . Web . BackOffice . Routing ;
24
- using Umbraco . Cms . Web . Common . AspNetCore ;
25
- using Umbraco . Cms . Web . Common . Security ;
26
6
27
7
namespace Umbraco . Cms . Tests . UnitTests . AutoFixture
28
8
{
29
-
30
9
[ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Constructor ) ]
31
10
public class AutoMoqDataAttribute : AutoDataAttribute
32
11
{
@@ -36,73 +15,8 @@ public class AutoMoqDataAttribute : AutoDataAttribute
36
15
/// [Frozen] can be used to ensure the same variable is injected and available as parameter for the test
37
16
/// </summary>
38
17
public AutoMoqDataAttribute ( )
39
- : base ( ( ) => AutoMockCustomizations . Default )
18
+ : base ( UmbracoAutoMoqFixtureFactory . CreateDefaultFixture )
40
19
{
41
20
}
42
-
43
- internal static class AutoMockCustomizations
44
- {
45
-
46
- public static IFixture Default => new Fixture ( ) . Customize ( new UmbracoCustomization ( ) ) ;
47
-
48
- private class UmbracoCustomization : ICustomization
49
- {
50
- public void Customize ( IFixture fixture )
51
- {
52
- fixture . Customize < BackOfficeIdentityUser > (
53
- u => u . FromFactory < string , string , string > (
54
- ( a , b , c ) => BackOfficeIdentityUser . CreateNew ( new GlobalSettings ( ) , a , b , c ) ) ) ;
55
- fixture
56
- . Customize ( new ConstructorCustomization ( typeof ( UsersController ) , new GreedyConstructorQuery ( ) ) )
57
- . Customize ( new ConstructorCustomization ( typeof ( InstallController ) , new GreedyConstructorQuery ( ) ) )
58
- . Customize ( new ConstructorCustomization ( typeof ( PreviewController ) , new GreedyConstructorQuery ( ) ) )
59
- . Customize ( new ConstructorCustomization ( typeof ( MemberController ) , new GreedyConstructorQuery ( ) ) )
60
- . Customize ( new ConstructorCustomization ( typeof ( BackOfficeController ) , new GreedyConstructorQuery ( ) ) )
61
- . Customize ( new ConstructorCustomization ( typeof ( BackOfficeUserManager ) , new GreedyConstructorQuery ( ) ) )
62
- . Customize ( new ConstructorCustomization ( typeof ( MemberManager ) , new GreedyConstructorQuery ( ) ) ) ;
63
-
64
- fixture . Customize ( new AutoMoqCustomization ( ) { ConfigureMembers = true } ) ;
65
-
66
- // When requesting an IUserStore ensure we actually uses a IUserLockoutStore
67
- fixture . Customize < IUserStore < BackOfficeIdentityUser > > ( cc => cc . FromFactory ( ( ) => Mock . Of < IUserLockoutStore < BackOfficeIdentityUser > > ( ) ) ) ;
68
-
69
- fixture . Customize < ConfigConnectionString > (
70
- u => u . FromFactory < string , string , string > (
71
- ( a , b , c ) => new ConfigConnectionString ( a , b , c ) ) ) ;
72
-
73
- fixture . Customize < IUmbracoVersion > (
74
- u => u . FromFactory (
75
- ( ) => new UmbracoVersion ( ) ) ) ;
76
-
77
- fixture . Customize < HostingSettings > ( x =>
78
- x . With ( settings => settings . ApplicationVirtualPath , string . Empty ) ) ;
79
- fixture . Customize < BackOfficeAreaRoutes > ( u => u . FromFactory (
80
- ( ) => new BackOfficeAreaRoutes (
81
- Options . Create ( new GlobalSettings ( ) ) ,
82
- Mock . Of < IHostingEnvironment > ( x => x . ToAbsolute ( It . IsAny < string > ( ) ) == "/umbraco" && x . ApplicationVirtualPath == string . Empty ) ,
83
- Mock . Of < IRuntimeState > ( x => x . Level == RuntimeLevel . Run ) ,
84
- new UmbracoApiControllerTypeCollection ( ( ) => Enumerable . Empty < Type > ( ) ) ) ) ) ;
85
-
86
- fixture . Customize < PreviewRoutes > ( u => u . FromFactory (
87
- ( ) => new PreviewRoutes (
88
- Options . Create ( new GlobalSettings ( ) ) ,
89
- Mock . Of < IHostingEnvironment > ( x => x . ToAbsolute ( It . IsAny < string > ( ) ) == "/umbraco" && x . ApplicationVirtualPath == string . Empty ) ,
90
- Mock . Of < IRuntimeState > ( x => x . Level == RuntimeLevel . Run ) ) ) ) ;
91
-
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
-
96
-
97
- var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext ( ) } ;
98
- fixture . Customize < HttpContext > ( x => x . FromFactory ( ( ) => httpContextAccessor . HttpContext ) ) ;
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 ( ) ) ;
104
- }
105
- }
106
- }
107
21
}
108
22
}
0 commit comments