public void Preserve_Formdata_if_FormDefinition_changed() { const string key = "name"; const string value = "John"; var fieldDefinition = new FieldDefinition { Key = key, Type = "string", Prompt = "Name" }; var initialFormDefinition = new FormDefinition { Fields = new[] { fieldDefinition } }; var formData = new FormData(new Dictionary <string, string> { { key, value } }); var sut = new NZazuView { FormDefinition = initialFormDefinition, FormData = formData }; sut.FormData.Should().Be(formData); var actual = sut.GetFieldValues(); actual.Should().Contain(formData.Values); fieldDefinition.Prompt = "Login"; var changedFormDefinition = new FormDefinition { Fields = new[] { fieldDefinition } }; // it is ugly to attach to depProperty.changed. It goes like this // https://social.msdn.microsoft.com/Forums/vstudio/en-US/262df30c-8383-4d5c-8d76-7b8e2cea51de/how-do-you-attach-a-change-event-to-a-dependency-property?forum=wpf var dpDescriptor = DependencyPropertyDescriptor.FromProperty(NZazuView.FormDefinitionProperty, typeof(NZazuView)); var formDefinitionChanged = false; EventHandler handler = (sender, args) => { formDefinitionChanged = true; }; dpDescriptor.AddValueChanged(sut, handler); try { sut.FormDefinition = changedFormDefinition; } finally { dpDescriptor.RemoveValueChanged(sut, handler); } formDefinitionChanged.Should().BeTrue(); actual = sut.GetFieldValues(); actual.Should().Contain(formData.Values); }
public void Skip_skip_fixed_fields_in_GetFieldValues() { var view = new NZazuView { FormDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = "caption", Type = "label" }, new FieldDefinition { Key = "name", Type = "string" } } } }; var expected = new Dictionary <string, string> { { "name", "John" } }; view.SetFieldValues(expected); var actual = view.GetFieldValues(); actual.Should().Contain(expected); }
public void Return_field_values_on_GetFieldValues() { const string key = "key"; const string value = "value"; var fieldDefinition = new FieldDefinition { Key = key, Type = "string" }; var formDefinition = new FormDefinition { Fields = new[] { fieldDefinition } }; var factory = Substitute.For <INZazuWpfFieldFactory>(); var field = Substitute.For <INZazuWpfField>(); field.GetValue().Returns(value); field.IsEditable.Returns(true); field.Key.Returns(key); factory.CreateField(fieldDefinition).Returns(field); var view = new NZazuView(); view.FormDefinition = formDefinition; view.FieldFactory = factory; var actual = view.GetFieldValues(); actual.Keys.Should().Contain(key); actual[key].Should().Be(value); }
public void Recurse_on_group_fields_in_GetFieldValues() { var view = new NZazuView { FormDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = "name", Type = "string" }, new FieldDefinition { Key = "group", Type = "group", Fields = new[] { new FieldDefinition { Key = "group.name", Type = "string" } } } } } }; var expected = new Dictionary <string, string> { { "name", "John" }, { "group.name", "Jim" } }; view.SetFieldValues(expected); var actual = view.GetFieldValues(); actual.Should().Contain(expected); actual.Keys.Should().Contain("__focusOn"); }
public void Set_Field_Values_If_FormData_Changes() { var view = new NZazuView(); const string key = "key"; const string value = "value"; var formDefinition = new FormDefinition { Fields = new[] { new FieldDefinition { Key = key, Type = "string" } } }; view.FormDefinition = formDefinition; view.FormData = new Dictionary <string, string> { { key, value } }; var actual = view.GetFieldValues(); actual.Keys.Should().Contain(key); actual[key].Should().Be(value); }