public async Task CryptoKeyStore_AddAsync() { var bytes = Guid.NewGuid().ToByteArray(); byte[] bytesToReturn = null; var key = Guid.NewGuid().ToString(); var config = new Mock <IConfigurationProvider>(); config.Setup(x => x.GetGlobalConfigurationAsStringAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync("test_bucket"); var fileStore = new Mock <IFileStore>(); fileStore.Setup(x => x.AddAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <byte[]>())) .Callback <string, string, byte[]>((k, p, v) => bytesToReturn = v).Returns(Task.CompletedTask); fileStore.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(bytesToReturn); var fileStoreFactory = new Mock <IFileStoreFactory>(); fileStoreFactory.Setup(x => x.GetGlobalClientAsync()).ReturnsAsync(fileStore.Object); var cryptoKeyStore = new CryptoKeyStore(config.Object, fileStoreFactory.Object); await cryptoKeyStore.AddAsync(_application, _tenant, key, bytes); var value = cryptoKeyStore.GetAsync(_application, _tenant, key); Assert.NotNull(value); }
public async Task CryptoKeyStore_GetAsync_NoDataInStore_ShouldReturn_Null() { var key = Guid.NewGuid().ToString(); var config = new Mock <IConfigurationProvider>(); config.Setup(x => x.GetGlobalConfigurationAsStringAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync("test_bucket"); var fileStore = new Mock <IFileStore>(); fileStore.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(null); var fileStoreFactory = new Mock <IFileStoreFactory>(); fileStoreFactory.Setup(x => x.GetGlobalClientAsync()).ReturnsAsync(fileStore.Object); var cryptoKeyStore = new CryptoKeyStore(config.Object, fileStoreFactory.Object); var value = await cryptoKeyStore.GetAsync(_application, _tenant, key); Assert.Null(value); }