public LockingNonceStoreTests() { FakeFactory.Create(out _decorated, out _lockFactory); _lock = new AsyncReaderWriterLock(); A.CallTo(() => _lockFactory.CreateLock()) .Returns(_lock); _sut = new LockingNonceStore(_decorated, _lockFactory); }
/// <summary>Configures HTTP message signature verification to use a file system-backed <see cref="INonceStore"/>.</summary> /// <param name="builder">The <see cref="IHttpMessageSigningVerificationBuilder" /> that is used to configure verification.</param> /// <param name="nonceStoreSettingsFactory">The factory that creates the settings for the file.</param> /// <returns>The <see cref="IHttpMessageSigningVerificationBuilder" /> that can be used to continue configuring the verification settings.</returns> public static IHttpMessageSigningVerificationBuilder UseFileSystemNonceStore( this IHttpMessageSigningVerificationBuilder builder, Func <IServiceProvider, FileSystemNonceStoreSettings> nonceStoreSettingsFactory) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (nonceStoreSettingsFactory == null) { throw new ArgumentNullException(nameof(nonceStoreSettingsFactory)); } builder.Services .AddMemoryCache() .AddSingleton <IFileReader, FileReader>() .AddSingleton <IFileWriter, FileWriter>() .AddSingleton <INonceDataRecordSerializer, NonceDataRecordSerializer>() .AddSingleton <ILockFactory, LockFactory>() .AddSingleton(prov => { var settings = nonceStoreSettingsFactory(prov); if (settings == null) { throw new ValidationException($"Invalid {nameof(FileSystemNonceStoreSettings)} were specified."); } settings.Validate(); return(settings); }) .AddSingleton(prov => { var settings = prov.GetRequiredService <FileSystemNonceStoreSettings>(); var decorator = prov.GetRequiredService <ICachingNonceStoreDecorator>(); var store = new LockingNonceStore( new FileSystemNonceStore( new NoncesFileManager( prov.GetRequiredService <IFileReader>(), prov.GetRequiredService <IFileWriter>(), settings.FilePath, prov.GetRequiredService <INonceDataRecordSerializer>()), prov.GetRequiredService <ISystemClock>()), prov.GetRequiredService <ILockFactory>()); return(decorator.DecorateWithCaching(store)); }); return(builder); }