Exemplo n.º 1
0
        public void Should_CopeWithLateAttachedConnection()
        {
            var UnconnectedFlag = new DynamicFlag <int>(dispatcher.Object, "thing", Convert.ToInt32, 1337);

            connection.Setup(m => m.GetWorkerFlag("thing")).Returns(new Improbable.Collections.Option <string>("100"));
            Assert.AreEqual(1337, UnconnectedFlag.Value, "Flag has default value before connection");
            UnconnectedFlag.AttachConnection(connection.Object);
            Assert.AreEqual(100, UnconnectedFlag.Value, "Flag establises new value after connection");
            UnconnectedFlag.DetachConnection(connection.Object);
            Assert.AreEqual(100, UnconnectedFlag.Value, "Flags retain value after disconnection");
        }
Exemplo n.º 2
0
        public void Should_TriggerCallbacks()
        {
            Action <FlagUpdateOp> callback = null;
            int lastValue = 0;

            dispatcher.Setup(m => m.OnFlagUpdate(It.IsAny <Action <FlagUpdateOp> >())).Callback <Action <FlagUpdateOp> >(cb => callback = cb);
            bool updated   = false;
            var  BasicFlag = new DynamicFlag <int>(dispatcher.Object, "thing", Convert.ToInt32, 1337);

            connection.Setup(m => m.GetWorkerFlag("thing")).Returns(new Improbable.Collections.Option <string>("100"));
            BasicFlag.OnChange((value) => { lastValue = value; updated = true; });

            BasicFlag.AttachConnection(connection.Object);
            Assert.AreEqual(lastValue, 100, "Updates on connection");
            Assert.AreEqual(updated, true);
            updated = false;

            callback(new FlagUpdateOp {
                Name = "thing", Value = "10"
            });
            Assert.AreEqual(lastValue, 10, "Updates on changes");
            Assert.AreEqual(updated, true);
        }