Exemple #1
0
    public async Task Schema_version_should_be_persisted()
    {
        // arrange
        var entity = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = "SomeUniqueString",
        };

        var persister = new SagaPersister();

        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var context))
        {
            var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

            // act
            await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, context);

            await session.SaveChangesAsync();

            // assert
            var sagaDataContainerId = SagaPersister.DocumentIdForSagaData(session, entity);
            var sagaDataContainer   = await session.LoadAsync <SagaDataContainer>(sagaDataContainerId);

            var sagaDataContainerMetadata = session.Advanced.GetMetadataFor(sagaDataContainer);

            var sagaUniqueIdentityId = sagaDataContainer.IdentityDocId;
            var sagaUniqueIdentity   = await session.LoadAsync <SagaUniqueIdentity>(sagaUniqueIdentityId);

            var sagaUniqueIdentityMetadata = session.Advanced.GetMetadataFor(sagaUniqueIdentity);

            Assert.AreEqual(SagaDataContainer.SchemaVersion, sagaDataContainerMetadata[SchemaVersionExtensions.SagaDataContainerSchemaVersionMetadataKey]);
            Assert.AreEqual(SagaUniqueIdentity.SchemaVersion, sagaUniqueIdentityMetadata[SchemaVersionExtensions.SagaUniqueIdentitySchemaVersionMetadataKey]);
        }
    }