public async Task SnapshotStore_SaveAsyncInvokesSerializeOnIAggregateSerializer()
        {
            var options = SetupContext();

            using (var context = new InfrastructureContext(options))
            {
                var mockSerializer = new Mock <IAggregateSerializer>();
                mockSerializer.Setup(s => s.Serialize(It.IsAny <FakeAggregate>()))
                .Returns <FakeAggregate>(aggr =>
                {
                    var payload = JsonConvert.SerializeObject(
                        aggr,
                        new JsonSerializerSettings
                    {
                        ConstructorHandling            = ConstructorHandling.AllowNonPublicDefaultConstructor,
                        TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full,
                        TypeNameHandling = TypeNameHandling.All,
                        ContractResolver = new Serialization.NonPublicPropertiesContractResolver()
                    });


                    return(Encoding.UTF8.GetBytes(payload));
                });

                var sut       = new SnapshotStore(mockSerializer.Object, context);
                var aggregate = new FakeAggregate(Guid.Empty);

                await sut.SaveAsync(aggregate);

                mockSerializer.Setup(s => s.Serialize(It.IsAny <FakeAggregate>()));
            }
        }
        public async Task SnapshotStore_SaveAsyncPersistChangesToContext()
        {
            var options = SetupContext();

            using (var context = new InfrastructureContext(options))
            {
                var mockSerializer = new Mock <IAggregateSerializer>();
                mockSerializer.Setup(s => s.Serialize(It.IsAny <FakeAggregate>()))
                .Returns <FakeAggregate>(aggr =>
                {
                    var payload = JsonConvert.SerializeObject(
                        aggr,
                        new JsonSerializerSettings
                    {
                        ConstructorHandling            = ConstructorHandling.AllowNonPublicDefaultConstructor,
                        TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full,
                        TypeNameHandling = TypeNameHandling.All,
                        ContractResolver = new Serialization.NonPublicPropertiesContractResolver()
                    });


                    return(Encoding.UTF8.GetBytes(payload));
                });

                var sut       = new SnapshotStore(mockSerializer.Object, context);
                var aggregate = new FakeAggregate(Guid.Empty, 50L);

                await sut.SaveAsync(aggregate);
            }

            using (var context = new InfrastructureContext(options))
            {
                var entity = await context.Snapshots.FindAsync(typeof(FakeAggregate).FullName, Guid.Empty, 50L);

                Assert.NotNull(entity);
                Assert.Equal(Guid.Empty, entity.AggregateId);
                Assert.Equal(50, entity.Version);
            }
        }