Пример #1
0
        public async Task GetAtVersionAsync_returns_correct_value()
        {
            // Arrange
            var stream = await _fixture.GetStreamADAsync();

            var firstValue  = "firstValue";
            var middleValue = "middleValue";                        // <= Expected value
            var lastValue   = "lastValue";
            await stream.AppendAsync(new StoredValue(firstValue));  // version 0

            await stream.AppendAsync(new StoredValue(middleValue)); // version 1 <= Pick this one

            await stream.AppendAsync(new StoredValue(lastValue));   // version 2

            var middleVersion = ExpectedVersion.Specific(1);

            // Act
            var result = await stream.GetAtVersionAsync((ulong)middleVersion.Value);

            // Assert 2
            Assert.IsNotNull(result);
            Assert.IsTrue(result.HasValue);
            Assert.IsInstanceOfType(result, typeof(Result <StoredValue>));
            Assert.AreEqual(middleValue, result.Value.Parse <string>());
        }
Пример #2
0
        public async Task TrySetValueAsync_with_correct_version_succeeds()
        {
            // Arrange
            var valueAD = await _fixture.GetValueADAsync();

            var firstValue = "firstValue";
            await valueAD.SetAsync(new StoredValue(firstValue));

            var expectedVersion = ExpectedVersion.Specific(0);

            // Act
            var lastValue = "lastValue";
            var addResult = await valueAD.TrySetAsync(new StoredValue(lastValue), expectedVersion);

            // Assert
            Assert.IsNotNull(addResult);
            Assert.IsTrue(addResult.HasValue);
            Assert.IsNotInstanceOfType(addResult, typeof(VersionMismatch <Pointer>));
        }
Пример #3
0
        // Pass in data that was encrypted at rest
        // for upload to SAFENetwork.
        public async Task <(NetworkEvent, Result <Pointer>)> Upload(WALContent walContent)
        {
            var data       = ZipEncryptedEvent.From(walContent.EncryptedContent);
            var localEvt   = data.GetEvent(_pwd);
            var networkEvt = await GetNetworkEvent(localEvt);

            var expectedVersion = walContent.SequenceNr == 0 ? ExpectedVersion.None : ExpectedVersion.Specific(walContent.SequenceNr - 1);
            var result          = await _stream.TryAppendAsync(new StoredValue(networkEvt), expectedVersion);

            return(networkEvt, result);
        }