Question

I am trying to update a legacy application and need some advice about how to organize the data level.

Today, all the data is stored in a binary file created with the help of binary serialization. The data that is stored is a several levels deep tree structure.

The object level of the saved data:

ApplicationSettings
   CommunicationSettings
   ConfigurationSettings
      HardwareSettings
         and so forth some additional levels

All this classes have a lot of logic to do different things. They also have status information that should not be saved to the file.

The data is constantly updated during the execution of the program, and saved when updated to the binary file by the "business logic".

I try to update the program, but doing unit tests for this is a nightmare.

I want the data still be saved in a file in any way. But otherwise, I'm open to suggestions how to improve this.

Edit:

The program is quite small, and I do not want to be dependent on large, complex frameworks. The reason I need help is to try to clean up the code where virtually the entire application logic is in one huge method.

Was it helpful?

Solution

What I would do;

First, turn the settings into contracts;

public interface IApplicationSettings
{
     ICommunicationSettings CommunicationSettings{get;} 
     IConfigurationSettings ConfigurationSettings{get;}
}

Now, break up your logic into separate concerns and pass in your settings at the highest level posible; Such that if MyLogicForSomething only concerns itself with the communication settings, then only pass in the communication settings;

public class MyLogicForSomething
{       
    public MyLogicForSomething(ICommunicationSettings commSettings)
    {
    }

    public void PerformSomething(){/* ... */}
}

ICommunicationSettings is easily mockable here; with something like Rhino Mocks

You can now easily test to ensure something in your settings is called/set when you run your logic

var commSettings = MockRepository.GenerateStub<ICommunicationSettings>();
var logic = new MyLogicForSomething(commSettings );

logic.PerformSomething()

commSettings.AssertWasCalled( x => x.SaveSetting(null), o=>o.IgnoreArguments() );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top