gui-cs / TerminalGuiDesigner

Forms Designer for Terminal.Gui (aka gui.cs)
MIT License
423 stars 28 forks source link

EditDialog.GetNewValue is getting too big #275

Open tznind opened 8 months ago

tznind commented 8 months ago

We have logic that answers the following question:

This is that method:

internal static bool GetNewValue(Design design, Property property, object? oldValue, out object? newValue)

There are really 2 possibilities that this method decides:

This is hard to test and getting too big.

Possible Solutions

Add a shared interface for all editors INewValueGetter (PosEditor, SizeEditor etc)

Create a new class PropertyValueFactory with function Create that takes a Design, Property and oldValue then returns an INewValueGetter.

This will allow for unit testing that the correct decisions about what editor should be shown to be written and move the logic of this tree into its own class.

Advantages

In #271 I have started down the route of a more complex ArrayEditor. Having this logic in its own class would make it possible to centralize 'new value' logic.

Testability

Automation style of tests e.g. mocking INewValueGetter with test implementations that simulate the user driving editor to create a given value.

tznind commented 8 months ago

I have started work on this in #271 with new ValueFactory class