@@ -55,9 +55,23 @@ private static string Counters_Col
5555 public MongoDBAuthRepository ( MongoDatabase mongoDatabase )
5656 {
5757 this . mongoDatabase = mongoDatabase ;
58+
59+ if ( ! CollectionsExists ( ) )
60+ {
61+ throw new InvalidOperationException ( "One of the collections needed by MongoDBAuthRepository is missing." +
62+ "You can call CreateMissingCollections or DropAndReCreateCollections " +
63+ "to create the needed collections." ) ;
64+ }
65+ }
66+ public bool CollectionsExists ( )
67+ {
68+ return ( mongoDatabase . CollectionExists ( UserAuth_Col ) )
69+ && ( mongoDatabase . CollectionExists ( UserOAuthProvider_Col ) )
70+ && ( mongoDatabase . CollectionExists ( Counters_Col ) ) ;
71+
5872 }
5973
60- public void CreateMissingTables ( )
74+ public void CreateMissingCollections ( )
6175 {
6276 if ( ! mongoDatabase . CollectionExists ( UserAuth_Col ) )
6377 mongoDatabase . CreateCollection ( UserAuth_Col ) ;
@@ -75,7 +89,7 @@ public void CreateMissingTables()
7589 }
7690 }
7791
78- public void DropAndReCreateTables ( )
92+ public void DropAndReCreateCollections ( )
7993 {
8094 if ( mongoDatabase . CollectionExists ( UserAuth_Col ) )
8195 mongoDatabase . DropCollection ( UserAuth_Col ) ;
@@ -86,7 +100,7 @@ public void DropAndReCreateTables()
86100 if ( mongoDatabase . CollectionExists ( Counters_Col ) )
87101 mongoDatabase . DropCollection ( Counters_Col ) ;
88102
89- CreateMissingTables ( ) ;
103+ CreateMissingCollections ( ) ;
90104 }
91105
92106 private void ValidateNewUser ( UserAuth newUser , string password )
@@ -398,7 +412,7 @@ public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens to
398412
399413 public void Clear ( )
400414 {
401- DropAndReCreateTables ( ) ;
415+ DropAndReCreateCollections ( ) ;
402416 }
403417 }
404418}
0 commit comments