开发者

Unit test scenario - how to test it?

I wrote my own settings manager, serialization is provided by BinaryFormatter. It is cool becouse, it can load and save class with missing/added property and I can define default value in missing property. But I have problem to test it with unit test.

I am doing this by myself. How to do this scenario automatically?

  1. Write class with 1 property.
  2. Serialize this class by my settings manager.

Before run new test:

  1. Manualy edit class and add new property, so we have two properties. New one开发者_C百科 with setted default value in [OnDeserialized] method.
  2. Run completely new test after rebuild new class.
  3. Class is deserialized from binary file.
  4. New property has default value.

It works like a charm, but I dont want to do this by myself. I need some automatic test.

Please, dont question my architecture, focus on my problem.

Posible way: Reclection? Other class? What about namespaces?


You can make two classes one for serialization and one for de-serialization and use SerializationBinder while de-serializing to the other class.


If your classes are simple, you really can compile them on the fly, load the assembly, do your serialization, unload the assembly. Compile the "updated" class, reload the assembly and test deserialization.

Maybe this link gets you started!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜