Пример #1
0
        public void ReverseOfRemoveParticipantIsAddParticipantWithPosition()
        {
            var wavelet = CreateWaveletData();
            var context = A.Fake<WaveletOperationContext>();

            // Build participant list with 3 participants.
            var participants = new List<ParticipantId> { Creator, Another, AThird };
            foreach (var p in participants)
            {
                wavelet.AddParticipant(p);
            }

            // Assert that all participants match the ones we just created
            wavelet.GetParticipants().Should().Contain(participants);

            // The reverse of removing any of the participants is an AddParticipantOperation with the
            // correct position which, when applied, rolls back the participant list.
            for (var i = 0; i < participants.Count; i++)
            {
                // Cache current participant
                var participant = participants[i];

                // Get and apply the exact reverse of the RemoveParticipantOperation (should yield an AddParticipantOperation)
                var reverse = new RemoveParticipantOperation(context, participant).ApplyAndReturnReverse(wavelet);

                reverse.Should().HaveCount(1);
                reverse.Should().Contain(new AddParticipantOperation(context, participant, i));

                // Re-apply the reverse (thus essentially re-adding the just removed participant)
                reverse[0].Apply(wavelet);

                // Assert we're back in original state
                wavelet.GetParticipants().Should().Contain(participants);
            }
        }
Пример #2
0
        public void CannotRemoveNonParticipant()
        {
            var context = A.Fake<WaveletOperationContext>();
            var wavelet = CreateWaveletData();
            var op = new RemoveParticipantOperation(context, Creator);

            var ex = Assert.Throws<OperationException>(() => op.Apply(wavelet));

            ex.Message.Should().Be("Attempt to delete non-existent participant: " + Creator);
        }
Пример #3
0
        public void ReverseOfAddParticipantIsRemoveParticipant()
        {
            var context = A.Fake<WaveletOperationContext>();
            var rop = new RemoveParticipantOperation(context, Creator);
            var aop = new AddParticipantOperation(context, Creator, 0);
            WaveletData wavelet = CreateWaveletData();

            IList<WaveletOperation> reverse = aop.ApplyAndReturnReverse(wavelet);
            WaveletOperation result = reverse[0];

            reverse.Should().HaveCount(1);
            result.Should().BeOfType<RemoveParticipantOperation>();
            result.IsWorthyOfAttribution().Should().BeTrue();
            result.As<RemoveParticipantOperation>().ParticipantId.Should().Be(Creator);
        }
Пример #4
0
 /// <summary>
 ///     Checks to see if a participant is being removed by one operation and added
 ///     by another concurrent operation. In such a situation, at least one of the
 ///     operations is invalid.
 /// </summary>
 /// <param name="removeOperation">The operation to remove a participant.</param>
 /// <param name="addOperation">The operation to add a participant.</param>
 /// <exception cref="TransformException">
 ///     TransformException if the same participant is being concurrently added and
 ///     removed.
 /// </exception>
 private static void CheckParticipantRemovalAndAddition(RemoveParticipantOperation removeOperation,
     AddParticipantOperation addOperation)
 {
     if (removeOperation.ParticipantId.Equals(addOperation.ParticipantId))
         throw new TransformException("Transform error involving participant: " +
                                      removeOperation.ParticipantId.Address);
 }
Пример #5
0
 private static void CheckParticipantRemoval(RemoveParticipantOperation removeOperation,
     WaveletOperation operation)
 {
     ParticipantId participantId = removeOperation.ParticipantId;
     if (participantId.Equals(operation.Context.Creator))
     {
         throw new RemovedAuthorException(participantId.Address);
     }
 }