示例#1
0
        public void InsertOperation_CreateInverse_InverseUndoesInsert()
        {
            var state         = new DocumentState(1, "123456789");
            var insert        = new InsertOperation(state, 2, 'x');
            var insertedstate = insert.ApplyTransform(state.CurrentState);

            Assert.AreEqual(state.CurrentState, insert.CreateInverse(state).ApplyTransform(insertedstate));
        }
        public void OperationTransformer_TransformInsertDelete_LocalEqualToRemote()
        {
            var state = new DocumentState(1, "123456789");

            var localOperation  = new InsertOperation(state, 2, 'a');
            var remoteOperation = new DeleteOperation(state, 2);

            var transformed = OperationTransformer.Transform(remoteOperation, localOperation);

            var stateStr = state.CurrentState;

            stateStr = localOperation.ApplyTransform(stateStr);
            stateStr = transformed.ApplyTransform(stateStr);


            Assert.AreEqual("12a456789", stateStr);
        }
示例#3
0
        public void OperationTransformer_TransformInsertInsert_LocalAfterRemote()
        {
            var localState  = new DocumentState(0, "123456789");
            var remoteState = new DocumentState(1, "123456789");

            var localOperation  = new InsertOperation(localState, 4, 'a');
            var remoteOperation = new InsertOperation(remoteState, 2, 'b');

            var transformed = OperationTransformer.Transform(remoteOperation, localOperation);

            var stateStr = localState.CurrentState;

            stateStr = localOperation.ApplyTransform(stateStr);
            stateStr = transformed.ApplyTransform(stateStr);

            Assert.AreEqual("12b34a56789", stateStr);
        }
        public void OperationTransformer_Transform_CP1TP1Satisfied()
        {
            var site1Str = "abcd";
            var site2Str = "abcd";
            var site1    = new DocumentState(1, site1Str);
            var site2    = new DocumentState(2, site2Str);

            var op1 = new InsertOperation(site1, 0, '1');
            var op2 = new InsertOperation(site2, 0, '2');

            site1Str = op2.ApplyTransform(site1Str);
            site1Str = OperationTransformer.Transform(op1, op2).ApplyTransform(site1Str);

            site2Str = op1.ApplyTransform(site2Str);
            site2Str = OperationTransformer.Transform(op2, op1).ApplyTransform(site2Str);

            Assert.AreEqual(site1Str, site2Str);
        }