public void UnbindTest()

in rd-net/Test.RdFramework/RdCollectionsTest.cs [154:313]


  public void UnbindTest()
  {
    var serverTopLevelProperty = BindToServer(LifetimeDefinition.Lifetime, NewRdProperty<RdMap<int, RdList<RdProperty<RdSet<int>>>>>(), ourKey);
    serverTopLevelProperty.ValueCanBeNull = true;
    
    var clientTopLevelProperty = BindToClient(LifetimeDefinition.Lifetime, NewRdProperty<RdMap<int, RdList<RdProperty<RdSet<int>>>>>(), ourKey);
    clientTopLevelProperty.ValueCanBeNull = true;

    var clientMap = NewRdMap<int, RdList<RdProperty<RdSet<int>>>>();
    clientMap.ValueCanBeNull = true;
    
    var clientList = NewRdList<RdProperty<RdSet<int>>>();
    clientList.ValueCanBeNull = true;
    var clientProperty = NewRdProperty<RdSet<int>>();
    clientProperty.ValueCanBeNull = true;
    
    var clientSet = NewRdSet<int>();
    
    clientSet.Add(1);
    clientSet.Add(2);
    clientSet.Add(3);
    
    clientProperty.Value = clientSet;
    clientList.Add(clientProperty);
    clientMap[2] = clientList;

    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      clientTopLevelProperty.Value = clientMap;
    });
    Assert.IsFalse(serverTopLevelProperty.Maybe.HasValue);
    
    PumpAllProtocols(true);

    var serverMap = serverTopLevelProperty.Value;

    Assert.AreEqual(1, serverMap.Count);
    Assert.AreEqual(2, serverMap.Keys.Single());

    var serverList = serverMap.Values.Single();
    Assert.AreEqual(1, serverList.Count);
    var serverProperty = serverList[0];
    Assert.IsTrue(serverProperty.Maybe.HasValue);

    var serverSet = serverProperty.Value;
    Assert.AreEqual(3, serverSet.Count);
    Assert.IsTrue(serverSet.Contains(1));
    Assert.IsTrue(serverSet.Contains(2));
    Assert.IsTrue(serverSet.Contains(3));

    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      clientProperty.Value = NewRdSet<int>();
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientSet.BindState);
    Assert.AreEqual(BindState.NotBound,serverSet.BindState);
    Assert.AreEqual(BindState.Bound,clientProperty.BindState);
    Assert.AreEqual(BindState.Bound,serverProperty.BindState);

    clientSet = clientProperty.Value;
    serverSet = serverProperty.Value;
    Assert.AreEqual(BindState.Bound,clientSet.BindState);
    Assert.AreEqual(BindState.Bound,serverSet.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      var oldValue = clientProperty.Value;
      clientProperty.Value = null;
      clientProperty.Value = oldValue;
      clientProperty.Value = null;
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientSet.BindState);
    Assert.AreEqual(BindState.NotBound,serverSet.BindState);
    Assert.AreEqual(BindState.Bound,clientProperty.BindState);
    Assert.AreEqual(BindState.Bound,serverProperty.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      var oldValue = clientList[0];
      clientList[0] = NewRdProperty<RdSet<int>>();
      clientList[0] = oldValue;
      clientList[0] = NewRdProperty<RdSet<int>>();
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientProperty.BindState);
    Assert.AreEqual(BindState.NotBound,serverProperty.BindState);
    Assert.AreEqual(BindState.Bound,clientList.BindState);
    Assert.AreEqual(BindState.Bound,serverList.BindState);


    clientProperty = clientList[0];
    serverProperty = serverList[0];
    Assert.AreEqual(BindState.Bound,clientProperty.BindState);
    Assert.AreEqual(BindState.Bound,serverProperty.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      clientList.Clear();
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientProperty.BindState);
    Assert.AreEqual(BindState.NotBound,serverProperty.BindState);
    Assert.AreEqual(BindState.Bound,clientList.BindState);
    Assert.AreEqual(BindState.Bound,serverList.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      var oldValue = clientMap[clientMap.Keys.Single()];
      clientMap[clientMap.Keys.Single()] = NewRdList<RdProperty<RdSet<int>>>();
      clientMap[clientMap.Keys.Single()] = oldValue;
      clientMap[clientMap.Keys.Single()] = NewRdList<RdProperty<RdSet<int>>>();
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientList.BindState);
    Assert.AreEqual(BindState.NotBound,serverList.BindState);
    Assert.AreEqual(BindState.Bound,clientMap.BindState);
    Assert.AreEqual(BindState.Bound,serverMap.BindState);

    clientList = clientMap.Values.Single();
    serverList = serverMap.Values.Single();
    Assert.AreEqual(BindState.Bound,clientList.BindState);
    Assert.AreEqual(BindState.Bound,serverList.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      clientMap.Clear();
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientList.BindState);
    Assert.AreEqual(BindState.NotBound,serverList.BindState);
    Assert.AreEqual(BindState.Bound,clientMap.BindState);
    Assert.AreEqual(BindState.Bound,serverMap.BindState);
    
    SetSchedulerActive(SchedulerKind.Client, () =>
    {
      var oldValue = clientTopLevelProperty.Value;
      clientTopLevelProperty.Value = null;
      clientTopLevelProperty.Value = oldValue;
      clientTopLevelProperty.Value = null;
    });
    
    PumpAllProtocols(true);
    
    Assert.AreEqual(BindState.NotBound,clientMap.BindState);
    Assert.AreEqual(BindState.NotBound,serverMap.BindState);
  }