public async Task CanSaveAndRetriveCollectionWithTypeAsync() { var configId = new ConfigurationIdentity(new ConfigurationClient("3E37AC18-A00F-47A5-B84E-C79E0823F6D4"), new Version(1, 0)); const int testValue = 23; const int testValue2 = 24; var values = new[] { new SimpleConfig { IntProperty = testValue }, new SimpleConfig { IntProperty = testValue2 } }; var config = new ConfigCollectionInstance <SimpleConfig>(values, configId); await target.UpdateConfigAsync(config); var result = (IEnumerable <SimpleConfig>)(await target.GetCollectionAsync(typeof(SimpleConfig), configId)); Assert.Equal(2, result.Count()); Assert.Contains(result, a => a.IntProperty == testValue); Assert.Contains(result, a => a.IntProperty == testValue2); }
public async Task CanSaveAndRetriveCollectionAsync() { var configId = new ConfigurationIdentity("3E37AC18-A00F-47A5-B84E-C79E0823F6D4"); const int testValue = 23; const int testValue2 = 24; var values = new[] { new SimpleConfig { IntProperty = testValue }, new SimpleConfig { IntProperty = testValue2 } }; var config = new ConfigCollectionInstance <SimpleConfig>(values, configId.ClientId); await target.UpdateConfigAsync(config); var result = await target.GetCollectionAsync <SimpleConfig>(configId); Assert.Equal(2, result.Count()); Assert.True(result.Any(a => a.IntProperty == testValue)); Assert.True(result.Any(a => a.IntProperty == testValue2)); }
private object UpdateObject(ConfigCollectionInstance target, JArray source, ConfigurationOptionModel optionModel, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets) { var collectionBuilder = target.CreateCollectionBuilder(); foreach (var item in source) { var obj = optionModel.NewItemInstance(); var itemToAdd = UpdateObject(obj, (JObject)item, optionModel.ConfigurationProperties, configIdentity, requiredConfigurationSets); collectionBuilder.Add(itemToAdd); } return(collectionBuilder.Collection); }
public async Task CallsUpdateWithCollectionConfig() { var config = new List <Option> { new Option { Id = 1, Description = "One" } }; var existingInstance = new ConfigCollectionInstance <Option>(expectedIdentity); var input = new UpdateConfigurationFromJsonUploadCommand(expectedIdentity, typeof(Option), JsonConvert.SerializeObject(config)); var result = await target.Handle(input); Assert.True(result.IsSuccessful); configRepository.Verify(repo => repo.UpdateConfigAsync(It.Is <ConfigInstance>(c => c.ConfigurationIdentity == existingInstance.ConfigurationIdentity && config.Count == ((ConfigCollectionInstance <Option>)c).Configuration.Count))); }
public async Task Get_SnapshotObjectCollection_WithInfo() { var expectedInstance = new ConfigCollectionInstance <SimpleConfig>(new[] { new SimpleConfig { IntProperty = 23 } }, defaultIdentity); var jsonPayload = JsonConvert.SerializeObject(BuildStorageObject(expectedInstance)); registry.Setup(r => r.GetConfigurationRegistrations(true)) .Returns(() => new[] { new ConfigurationRegistration(typeof(SimpleConfig), typeof(SimpleConfig).Name, true) }); connector.Setup(c => c.GetSnapshotEntries(defaultEntry.Id)) .ReturnsAsync(new SnapshotTextEntry[] { new SnapshotTextEntry { ConfigurationName = typeof(SimpleConfig).Name, ConfigurationJson = jsonPayload } }); var result = await target.GetSnapshot(defaultEntry.Id, defaultIdentity); Assert.Equal(defaultEntry, result.Info, new SnapShotEqualityComparer()); }
public async Task Get_SnapshotObjectCollection() { var expectedInstance = new ConfigCollectionInstance <SimpleConfig>(new[] { new SimpleConfig { IntProperty = 23 } }, defaultIdentity); var jsonPayload = JsonConvert.SerializeObject(BuildStorageObject(expectedInstance)); registry.Setup(r => r.GetConfigurationRegistrations(true)) .Returns(() => new[] { new ConfigurationRegistration(typeof(SimpleConfig), typeof(SimpleConfig).Name, true) }); connector.Setup(c => c.GetSnapshotEntries(defaultEntry.Id)) .ReturnsAsync(new SnapshotTextEntry[] { new SnapshotTextEntry { ConfigurationName = typeof(SimpleConfig).Name, ConfigurationJson = jsonPayload } }); var result = await target.GetSnapshot(defaultEntry.Id, defaultIdentity); Assert.Equal(1, result.Configurations.Count); var configuration = result.Configurations.Single().GetConfiguration() as IEnumerable <SimpleConfig>; Assert.NotNull(configuration); var configurationAsList = configuration.ToList(); Assert.Single(configurationAsList); Assert.Equal(23, configurationAsList[0].IntProperty); }