Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing serialization #445

Open
Vraiment opened this issue Oct 27, 2019 · 1 comment
Open

Testing serialization #445

Vraiment opened this issue Oct 27, 2019 · 1 comment
Labels

Comments

@Vraiment
Copy link

Hi

I want to write some tests for serialization, my first naive approach is similar to the following code:

[Test]
public void Test_Deserialization()
{
    MyClass instance = BuildTestInstance();
    ISerializer serializer = BuildSerializer();

    String output = serializer.Serialize(instance);
    String expected = File.ReadAllText("expected.yaml");

    output.Should().Be(expected);
}

But I found this to be extremely flaky: whitespaces are a little problematic, some some integer values in expected.yaml are written in hexadecimal and some other in decimal and the serializer outputs everything to decimal, etc.

Is there any recommended way to get the in memory representation of expected.yaml and the output of serialization, so I compare that instead of comparing the text?

@aaubry
Copy link
Owner

aaubry commented Oct 27, 2019

I would suggest that you create an implementation of IEmitter that stores all the emitted events into a list and then serialize to an instance of that emitter. You will be able to make assertions against the event stream instead of having to compare text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants