Пример #1
0
 public void Test_DeleteNotEmptyAt0()
 {
     stringTextContext = new StringTextContext("test content");
     DeleteOperation delete = new DeleteOperation(0);
     stringTextContext.Delete(null, delete);
     Assert.AreEqual("est content", stringTextContext.Data, "Inconsistent state after deletion!");
 }
Пример #2
0
 public void Test_DeleteNotEmptyTwiceAt0ThenInMiddle()
 {
     stringTextContext = new StringTextContext("test content");
     DeleteOperation delete1 = new DeleteOperation(0);
     DeleteOperation delete2 = new DeleteOperation(5);
     stringTextContext.Delete(null, delete1);
     Assert.AreEqual("est content", stringTextContext.Data, "Inconsistent state after deletion!");;
     stringTextContext.Delete(null, delete2);
     Assert.AreEqual("est cntent", stringTextContext.Data, "Inconsistent state after deletion!");
 }
        public void SetUp()
        {
            log4net.Config.BasicConfigurator.Configure();

            serverConnection = new LocalConnection();
            clientConnection = new LocalConnection();
            LocalProtocol.Connect(serverConnection, clientConnection);

            serverContext = new StringTextContext();
            clientContext = new StringTextContext();

            server = new DifferentialSynchronizationStrategy(0, serverContext, serverConnection);
            client = new DifferentialSynchronizationStrategy(1, clientContext, clientConnection);
        }
        /// <summary>
        /// Creates a new differential synchronization session on an already established
        /// networking connection.
        /// </summary>
        /// <param name="siteId">The <see cref="SiteId">SiteId</see> for this site.</param>
        /// <param name="context">The <see cref="Context">text context</see> to be operate on.</param>
        /// <param name="connection">The connection that is used to communicate with the other site.</param>
        public DifferentialSynchronizationStrategy(int siteId, ITextContext context, IConnection connection)
        {
            SiteId = siteId;
            DiffMatchPatch =  new diff_match_patch();
            Context = context;
            Connection = connection;
            Shadow = new StringTextContext(context.Data);
            TokenRequestSent = false;

            HasChanged = false;

            TokenState = SiteId == 0 ? TokenState.HavingToken : TokenState.WaitingForToken;

            Connection.Received += ConnectionReceived;
            Context.Changed += ContextChanged;
        }
Пример #5
0
 public void Initialize()
 {
     stringTextContext = new StringTextContext();
 }
Пример #6
0
 public void Test_SetSelectionNotEmptyAtSame()
 {
     stringTextContext = new StringTextContext("selection");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     stringTextContext.SetSelection(2, 2);
     Assert.AreEqual(2, stringTextContext.SelectionStart, "SelectionStart not 2!");
     Assert.AreEqual(2, stringTextContext.SelectionEnd, "SelectionEnd not 2!");
     Assert.AreEqual("", stringTextContext.SelectedText, "SelectedText not ''");
 }
Пример #7
0
 public void Test_SetSelectionNotEmptyAt1And5()
 {
     stringTextContext = new StringTextContext("selection");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     stringTextContext.SetSelection(1, 5);
     Assert.AreEqual(1, stringTextContext.SelectionStart, "SelectionStart not 1!");
     Assert.AreEqual(5, stringTextContext.SelectionEnd, "SelectionEnd not 5!");
     Assert.AreEqual("elec", stringTextContext.SelectedText, "SelectedText not elec");
 }
Пример #8
0
 public void Test_SetRemoteSelectionNotEmpty()
 {
     stringTextContext = new StringTextContext("remote");
     Assert.AreEqual("remote", stringTextContext.Data, "Initial Data is not equal to argument string!");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     Assert.AreEqual("", stringTextContext.SelectedText, "Initial SelectedText not empty!");
     stringTextContext.SetRemoteSelection(null, 2, 4);
     Assert.AreEqual("remote", stringTextContext.Data, "Initial Data is not empty after Refresh!");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "SelectionStart not 0 after Refresh!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "SelectionEnd not 0 after Refresh!");
     Assert.AreEqual("", stringTextContext.SelectedText, "Initial SelectedText not empty after Refresh!");
 }
Пример #9
0
 public void Test_RefreshNotEmptyAndSelected()
 {
     stringTextContext = new StringTextContext("refresh");
     stringTextContext.SetSelection(1,3);
     Assert.AreEqual("refresh", stringTextContext.Data, "Initial Data is not equal to argument string!");
     Assert.AreEqual(1, stringTextContext.SelectionStart, "SelectionStart not 1!");
     Assert.AreEqual(3, stringTextContext.SelectionEnd, "SelectionEnd not 3!");
     Assert.AreEqual("ef", stringTextContext.SelectedText, "Initial SelectedText not empty!");
     stringTextContext.Refresh();
     Assert.AreEqual("refresh", stringTextContext.Data, "Initial Data is not empty after Refresh!");
     Assert.AreEqual(1, stringTextContext.SelectionStart, "SelectionStart not 1 after Refresh!");
     Assert.AreEqual(3, stringTextContext.SelectionEnd, "SelectionEnd not 3 after Refresh!");
     Assert.AreEqual("ef", stringTextContext.SelectedText, "Initial SelectedText not empty after Refresh!");
 }
Пример #10
0
 public void Test_RefreshNotEmpty()
 {
     stringTextContext = new StringTextContext("refresh");
     Assert.AreEqual("refresh", stringTextContext.Data, "Initial Data is not equal to argument string!");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     Assert.AreEqual("", stringTextContext.SelectedText, "Initial SelectedText not empty!");
     stringTextContext.Refresh();
     Assert.AreEqual("refresh", stringTextContext.Data, "Initial Data is not equal to argumetn string after Refresh!");
     Assert.AreEqual(0, stringTextContext.SelectionStart, "Initial SelectionStart not 0 after Refresh!");
     Assert.AreEqual(0, stringTextContext.SelectionEnd, "Initial SelectionEnd not 0 after Refresh!");
     Assert.AreEqual("", stringTextContext.SelectedText, "Initial SelectedText not empty after Refresh!");
 }
Пример #11
0
 public void Test_InitNotEmpty()
 {
     stringTextContext = new StringTextContext("test content");
     Assert.AreEqual("test content", stringTextContext.Data, "Initial Data is not equal to argument string!");
 }