@@ -95,4 +95,142 @@ public void AddFido2_WithSetupAction_RegistersServices()
9595 // var mds = serviceProvider.GetService<IMetadataService>();
9696 // Assert.Null(mds);
9797 }
98+
99+ [ Fact ]
100+ public void AddMetadataService_RegistersCustomMetadataService ( )
101+ {
102+ // Arrange
103+ var services = new ServiceCollection ( ) ;
104+ var builder = services . AddFido2 ( config => { } ) ;
105+
106+ // Act
107+ builder . AddMetadataService < TestMetadataService > ( ) ;
108+
109+ // Assert
110+ var serviceProvider = services . BuildServiceProvider ( ) ;
111+ var metadataService = serviceProvider . GetService < IMetadataService > ( ) ;
112+ Assert . NotNull ( metadataService ) ;
113+ Assert . IsType < TestMetadataService > ( metadataService ) ;
114+ }
115+
116+ [ Fact ]
117+ public void AddCachedMetadataService_RegistersCachedService ( )
118+ {
119+ // Arrange
120+ var services = new ServiceCollection ( ) ;
121+ services . AddLogging ( ) ;
122+ services . AddMemoryCache ( ) ;
123+ services . AddSingleton < IDistributedCache , MemoryDistributedCache > ( ) ;
124+ var builder = services . AddFido2 ( config => { } ) ;
125+
126+ // Act
127+ builder . AddCachedMetadataService ( ) ;
128+
129+ // Assert
130+ var serviceProvider = services . BuildServiceProvider ( ) ;
131+ var metadataService = serviceProvider . GetService < IMetadataService > ( ) ;
132+ Assert . NotNull ( metadataService ) ;
133+ Assert . IsType < DistributedCacheMetadataService > ( metadataService ) ;
134+ }
135+
136+ [ Fact ]
137+ public void AddMetadataRepository_RegistersCustomMetadataRepository ( )
138+ {
139+ // Arrange
140+ var services = new ServiceCollection ( ) ;
141+ var builder = services . AddFido2 ( config => { } ) ;
142+
143+ // Act
144+ builder . AddMetadataRepository < TestMetadataRepository > ( ) ;
145+
146+ // Assert
147+ var serviceProvider = services . BuildServiceProvider ( ) ;
148+ var metadataRepository = serviceProvider . GetService < IMetadataRepository > ( ) ;
149+ Assert . NotNull ( metadataRepository ) ;
150+ Assert . IsType < TestMetadataRepository > ( metadataRepository ) ;
151+ }
152+
153+ [ Fact ]
154+ public void AddFileSystemMetadataRepository_RegistersFileSystemRepository ( )
155+ {
156+ // Arrange
157+ var services = new ServiceCollection ( ) ;
158+ var builder = services . AddFido2 ( config => { } ) ;
159+ var testPath = "/tmp/test" ;
160+
161+ // Act
162+ builder . AddFileSystemMetadataRepository ( testPath ) ;
163+
164+ // Assert
165+ var serviceProvider = services . BuildServiceProvider ( ) ;
166+ var metadataRepository = serviceProvider . GetService < IMetadataRepository > ( ) ;
167+ Assert . NotNull ( metadataRepository ) ;
168+ Assert . IsType < FileSystemMetadataRepository > ( metadataRepository ) ;
169+ }
170+
171+ [ Fact ]
172+ public void AddConformanceMetadataRepository_RegistersConformanceRepository ( )
173+ {
174+ // Arrange
175+ var services = new ServiceCollection ( ) ;
176+ var builder = services . AddFido2 ( config => { } ) ;
177+
178+ // Act
179+ builder . AddConformanceMetadataRepository ( ) ;
180+
181+ // Assert
182+ var serviceProvider = services . BuildServiceProvider ( ) ;
183+ var metadataRepository = serviceProvider . GetService < IMetadataRepository > ( ) ;
184+ Assert . NotNull ( metadataRepository ) ;
185+ Assert . IsType < ConformanceMetadataRepository > ( metadataRepository ) ;
186+ }
187+
188+ [ Fact ]
189+ public void AddFidoMetadataRepository_RegistersFidoRepository ( )
190+ {
191+ // Arrange
192+ var services = new ServiceCollection ( ) ;
193+ var builder = services . AddFido2 ( config => { } ) ;
194+
195+ // Act
196+ builder . AddFidoMetadataRepository ( ) ;
197+
198+ // Assert
199+ var serviceProvider = services . BuildServiceProvider ( ) ;
200+ var metadataRepository = serviceProvider . GetService < IMetadataRepository > ( ) ;
201+ Assert . NotNull ( metadataRepository ) ;
202+ Assert . IsType < Fido2MetadataServiceRepository > ( metadataRepository ) ;
203+ }
204+
205+ [ Fact ]
206+ public void Fido2NetLibBuilder_Constructor_ThrowsWhenServicesNull ( )
207+ {
208+ // Act & Assert
209+ Assert . Throws < ArgumentNullException > ( ( ) => new Fido2NetLibBuilder ( null ) ) ;
210+ }
211+
212+ [ Fact ]
213+ public void Fido2NetLibBuilder_ServicesProperty_ReturnsServices ( )
214+ {
215+ // Arrange
216+ var services = new ServiceCollection ( ) ;
217+
218+ // Act
219+ var builder = new Fido2NetLibBuilder ( services ) ;
220+
221+ // Assert
222+ Assert . Same ( services , builder . Services ) ;
223+ }
224+ }
225+
226+ public class TestMetadataService : IMetadataService
227+ {
228+ public bool ConformanceTesting ( ) => false ;
229+ public Task < MetadataBLOBPayloadEntry > GetEntryAsync ( Guid aaguid , CancellationToken cancellationToken = default ) => Task . FromResult < MetadataBLOBPayloadEntry > ( null ) ;
230+ }
231+
232+ public class TestMetadataRepository : IMetadataRepository
233+ {
234+ public Task < MetadataBLOBPayload > GetBLOBAsync ( CancellationToken cancellationToken = default ) => Task . FromResult < MetadataBLOBPayload > ( null ) ;
235+ public Task < MetadataStatement > GetMetadataStatementAsync ( MetadataBLOBPayload blob , MetadataBLOBPayloadEntry entry , CancellationToken cancellationToken = default ) => Task . FromResult < MetadataStatement > ( null ) ;
98236}
0 commit comments