public void Handle_Add_Button()
        {
            var serializer = new NZazuTableDataXmlSerializer();
            var sut        = new NZazuDataTableField(new FieldDefinition
            {
                Key    = "key",
                Type   = "table01",
                Fields = new[]
                {
                    new FieldDefinition
                    {
                        Key  = "table01_field01",
                        Type = "string"
                    }
                }
            }, ServiceLocator);

            var data = new Dictionary <string, string>
            {
                { "table01_field01__1", "hello" }, { "table01_field01__2", "world" }
            };
            var dataSerialized = serializer.Serialize(data);

            sut.SetValue(dataSerialized);

            var ctrl      = (DynamicDataTable)sut.ValueControl;
            var lastadded = ctrl.LayoutGrid.Children[2];

            lastadded.Should().NotBeNull();

            // lets see if it adds a row
            ctrl.LayoutGrid.RowDefinitions.Count.Should().Be(3);
            sut.AddRowAbove(lastadded);
            ctrl.LayoutGrid.RowDefinitions.Count.Should().Be(4);
        }
        public void Deserialize_Empty_Data(string data)
        {
            object Fct(Type t)
            {
                if (t == typeof(INZazuTableDataSerializer))
                {
                    return(new NZazuTableDataXmlSerializer());
                }
                if (t == typeof(INZazuWpfFieldFactory))
                {
                    return(new NZazuFieldFactory());
                }
                return(null);
            }

            // ReSharper disable once UseObjectOrCollectionInitializer
            var sut = new NZazuDataTableField(new FieldDefinition
            {
                Key    = "table01",
                Fields = new[]
                {
                    new FieldDefinition {
                        Key = "table01_field01", Type = "string"
                    }
                }
            }, ServiceLocator);

            sut.SetValue(data);
            var actual =
                ((INZazuTableDataSerializer)Fct(typeof(INZazuTableDataSerializer))).Deserialize(sut.GetValue());

            actual.Should().NotBeNull();

            ((DynamicDataTable)sut.ValueControl).LayoutGrid.RowDefinitions.Count.Should().Be(2);
        }
        public void Serialize_And_Deserialize_Null_Rows_To_Null()
        {
            var serializer = new NZazuTableDataXmlSerializer();
            var data       = new Dictionary <string, string> {
                { "table01_field01__1", null }, { "table01_field01__2", null }
            };
            var dataSerialized = serializer.Serialize(data);

            // ReSharper disable once UseObjectOrCollectionInitializer
            var sut = new NZazuDataTableField(new FieldDefinition
            {
                Key    = "table01",
                Fields = new[]
                {
                    new FieldDefinition {
                        Key = "table01_field01", Type = "string"
                    }
                }
            }, ServiceLocator);

            sut.SetValue(dataSerialized);

            // test the returned data
            var actual = serializer.Deserialize(sut.GetValue());

            actual.Count.Should().Be(0);

            sut.Validate().IsValid.Should().BeTrue();
            ((DynamicDataTable)sut.ValueControl).LayoutGrid.RowDefinitions.Count.Should().Be(2);
        }
        public void Validate()
        {
            var s    = new NZazuTableDataXmlSerializer();
            var data = new Dictionary <string, string> {
                { "table01_field01__1", "" }, { "table01_field01__2", "world" }
            };
            var dataSerialized = s.Serialize(data);

            // ReSharper disable once UseObjectOrCollectionInitializer
            var sut = new NZazuDataTableField(new FieldDefinition
            {
                Key    = "table01",
                Fields = new[]
                {
                    new FieldDefinition
                    {
                        Key    = "table01_field01", Type = "string",
                        Checks = new[] { new CheckDefinition {
                                             Type = "required"
                                         } }
                    }
                }
            }, ServiceLocator);

            // ReSharper disable once UnusedVariable
            var justToMakeTheCall = sut.ValueControl;

            sut.SetValue(dataSerialized);
            sut.Validate().IsValid.Should().BeFalse();

            // now change the data
            data = new Dictionary <string, string> {
                { "table01_field01__1", "hello" }, { "table01_field01__2", "world" }
            };
            dataSerialized = s.Serialize(data);
            sut.SetValue(dataSerialized);
            sut.Validate().IsValid.Should().BeTrue();
        }
        public void Ignore_Exception_On_Deserialize_Invalid_Data(string data)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var sut = new NZazuDataTableField(new FieldDefinition
            {
                Key    = "table01",
                Fields = new[]
                {
                    new FieldDefinition {
                        Key = "table01_field01", Type = "string"
                    }
                }
            }, ServiceLocator);

            Action act = () => { sut.SetValue(data); };

            act.Should().NotThrow <Exception>();

            ((DynamicDataTable)sut.ValueControl).LayoutGrid.RowDefinitions.Count.Should().Be(2);
        }