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

Json serializer does not create a journal file that can be read (NotSupportedException) #53

Closed
goblinfactory opened this issue Mar 6, 2018 · 0 comments
Assignees

Comments

@goblinfactory
Copy link
Collaborator

When using JsonSerializerAdapter and default settings, the resulting generated journal file cannot be read.

The test below fails with;

System.NotSupportedException : Specified method is not supported.
   at Memstate.JsonNet.SurrogateConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\src\git-alan-public\memstate-fork-alan\Memstate.JsonNet\SurrogateConverter.cs:line 43

Steps to reproduce the error, run this test

        [Test]
        public async Task Json_file_created_should_be_able_to_be_deserialized()
        {
            Print("Given a journal file");
            var settings = new MemstateSettings { StreamName = "json-example2" };
            settings.Serializers.Register("a-unique-key", _ => new JsonSerializerAdapter(settings));
            settings.Serializer = "a-unique-key";
            var model1 = await new EngineBuilder(settings).BuildAsync<LedgerDB>();

            await model1.ExecuteAsync(new InitAccount(accountNumber: 1, openingBalance: 100.11M, currency: '£'));
            await model1.ExecuteAsync(new InitAccount(accountNumber: 2, openingBalance: 200.22M, currency: '£'));
            await model1.ExecuteAsync(new Transfer(fromAccount: 1, toAccount: 2, amount: 0.01M, currency: '£'));
            var accounts1 = await model1.ExecuteAsync(new GetAccounts());
            await model1.DisposeAsync();
            Assert.True(File.Exists("json-example2.journal"));

            Print("When I create an new LedgerDB that will read the recently created ledger file");
            var model2 = await new EngineBuilder(settings).BuildAsync<LedgerDB>();

            Print("then the journal entries should have been read in");
            var accounts2 = await model2.ExecuteAsync(new GetAccounts());
            Assert.AreEqual(2, accounts2.Count);

            Print("And the in memory object database should be back to the latest state");
            CollectionAssert.AreEqual(accounts1, accounts2);

        }

You can use any Engine<T> with any commands. The important point is the serializer settings.

@goblinfactory goblinfactory changed the title Json serializer does not create a journal file that can be read Json serializer does not create a journal file that can be read (NotSupportedException) Mar 6, 2018
@rofr rofr closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants