public Task GetLoadMetricsSingleItem() { return(this.RunDataSizeUnitsPermutationAsync(async config => { Uri collectionName = new Uri("test://dictionary"); int key = 1; string value = "Homer"; BinaryValueConverter converter = new BinaryValueConverter(collectionName, new JsonReliableStateSerializerResolver()); double size = converter.Serialize <int>(key).Buffer.Length + converter.Serialize <string>(value).Buffer.Length; double expectedMemory = size / (double)config.MemoryMetricUnits; double expectedDisk = size / (double)config.DiskMetricUnits; MockReliableDictionary <BinaryValue, BinaryValue> store = new MockReliableDictionary <BinaryValue, BinaryValue>(collectionName); MetricReliableDictionary <int, string> target = new MetricReliableDictionary <int, string>(store, converter, config); using (ITransaction tx = new MockTransaction()) { await target.SetAsync(tx, key, value); await tx.CommitAsync(); } using (ITransaction tx = new MockTransaction()) { IEnumerable <DecimalLoadMetric> result = await target.GetLoadMetricsAsync(tx, CancellationToken.None); Assert.AreEqual <int>(1, result.Count(x => x.Name == config.MemoryMetricName && x.Value == expectedMemory)); Assert.AreEqual <int>(1, result.Count(x => x.Name == config.DiskMetricName && x.Value == expectedDisk)); } })); }
public async void ShouldNotGetNonExistantKvpConfig() { var dict = await _service.StateManager.GetOrAddAsync <IReliableDictionary <ConfigKey, KvpConfig> >(CoreService.KvpDictionaryName); KvpConfig config = null; using (var tx = new MockTransaction()) { config = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; var key = new ConfigKey(config); await dict.TryAddAsync(tx, key, config); await tx.CommitAsync(); } if (await dict.GetCountAsync(new MockTransaction()) != 1) { Assert.False(true, "The config key was not saved. The test will not proceed"); } var val = await _service.GetConfigSetting(new ConfigKey("NotAKey", "1.0.0")); Assert.True(val == null, "The service returned a response.... That ain't right"); }
public async void ShouldThrowInvalidOpEx_WhenConfigAlreadyExists() { var dict = await _service.StateManager.GetOrAddAsync <IReliableDictionary <ConfigKey, KvpConfig> >(CoreService.KvpDictionaryName); KvpConfig config = null; using (var tx = new MockTransaction()) { config = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; var key = new ConfigKey(config); await dict.TryAddAsync(tx, key, config); await tx.CommitAsync(); } KvpConfig newconfig = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; await Assert.ThrowsAnyAsync <InvalidOperationException>(() => _service.AddConfigSetting(newconfig)); }
public async void ShouldGetLatestKvpConfigByName() { var dict = await _service.StateManager.GetOrAddAsync <IReliableDictionary <ConfigKey, KvpConfig> >(CoreService.KvpDictionaryName); KvpConfig config = null; using (var tx = new MockTransaction()) { config = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.1.0" }; var key = new ConfigKey(config); await dict.TryAddAsync(tx, key, config); var config2 = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; var key2 = new ConfigKey(config2); await dict.TryAddAsync(tx, key2, config2); await tx.CommitAsync(); } if (await dict.GetCountAsync(new MockTransaction()) != 2) { Assert.False(true, "The config key was not saved. The test will not proceed"); } var val = await _service.GetLatestConfigSetting("Test"); Assert.True(val != null, "The srevice returned a null response. That ain't right"); Assert.True(val.Equals(config), "The service returned a value but it did not equal the stored config"); }
public async void ShouldSaveConfig() { var dict = new MockReliableDictionary <ConfigKey, KvpConfig>(); using (var tx = new MockTransaction()) { var config = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; var key = new ConfigKey(config); await dict.TryAddAsync(tx, key, config); await tx.CommitAsync(); } using (var tx = new MockTransaction()) { var config = new KvpConfig() { Value = "Test", Name = "Test", Type = "String", Version = "1.0.0" }; var key = new ConfigKey(config); var val = await dict.TryGetValueAsync(tx, key); Assert.True(val.HasValue); Assert.Equal(val.Value.Name, config.Name); Assert.Equal(val.Value.Type, config.Type); Assert.Equal(val.Value.Version, config.Version); Assert.Equal(val.Value.Value, config.Value); } }