public void JsonSerializerAndDeserializer_Test() { //Arrange var product = new Product ( 1L, "banana", true, new List <long>() { 1L, 2L, 3L }, new List <ProductRecord>() { new ProductRecord(1L, "a", DateTime.UtcNow), new ProductRecord(2L, "b", DateTime.UtcNow), new ProductRecord(3L, "c", DateTime.UtcNow), new ProductRecord(4L, "d", DateTime.UtcNow), } ); //Act var json = _serializer.Serialize(product); var deserializedProduct = _serializer.Deserialize(json, typeof(Product)) as Product; //Assert deserializedProduct.Id.ShouldBe(product.Id); deserializedProduct.Name.ShouldBe(product.Name); deserializedProduct.IsPublished.ShouldBe(product.IsPublished); }
public async Task <IAggregateRoot> RestoreFromSnapshotAsync(Type aggregateRootType, string aggregateRootId) { var payload = await _aggregateSnapshotStore.GetSnapshotPayloadAsync(aggregateRootId); if (payload == null) { return(null); } return(_aggregateSnapshotSerializer.Deserialize(payload, aggregateRootType) as IAggregateRoot); }
public async Task <IAggregateRoot> RestoreFromSnapshotAsync(Type aggregateRootType, string aggregateRootId) { var snapshot = await _snapshotCollection .GetCollection(aggregateRootId) .Find(s => s.AggregateRootId == aggregateRootId) .FirstOrDefaultAsync(); if (snapshot == null) { return(null); } return(_aggregateSnapshotSerializer.Deserialize(snapshot.Payload, aggregateRootType) as IAggregateRoot); }
public async Task <IAggregateRoot> RestoreFromSnapshotAsync(Type aggregateRootType, string aggregateRootId) { var snapshot = default(Snapshot); using (var connection = _snapshotRepository.GetConnection()) { var result = await connection.QueryListAsync <Snapshot>(new { AggregateRootId = aggregateRootId }, _snapshotRepository.GetTableName(aggregateRootId)); snapshot = result.SingleOrDefault(); } if (snapshot == null) { return(null); } return(_aggregateSnapshotSerializer.Deserialize(snapshot.SerializedPayload, aggregateRootType) as IAggregateRoot); }