public void TheStateOfAValueReferenceCanBeRestoredFromAMapSnapshot()
        {
            var reference = new ValueReferenceDefinitionBuilder().Build().CreateValueReference(engine);

            reference.RestoreFromSnapshot(engine, new ValueReference.Snapshot("1", new Dictionary <string, ValueReference.Snapshot>()));
            Assert.AreEqual(new Dictionary <string, ValueReference>(), reference.ValueAsMap());
        }
        public void CanSetTheValueContainedByAReferenceToAMap()
        {
            var initialDictionary = new Dictionary <string, ValueReferenceDefinition>();
            var reference         = new ValueReferenceDefinitionBuilder().WithStartingValue(initialDictionary).Build().CreateValueReference(engine);
            var newDictionary     = new Dictionary <string, ValueReference>();

            reference.Set(newDictionary);
            Assert.AreEqual(reference.ValueAsMap(), newDictionary);
        }
        public void CanWatchANonExistantKeyInAMap()
        {
            var mapReference = new ValueReferenceDefinitionBuilder()
                               .WithStartingValue(new Dictionary <string, ValueReferenceDefinition>()).Build().CreateValueReference(engine);
            var fooReference        = mapReference.ValueAsMap()["foo"];
            var watchListenerCalled = false;

            fooReference.Watch(newFoo =>
            {
                watchListenerCalled = true;
            });
            Assert.IsTrue(watchListenerCalled);
        }
        public void AssigningAValueInAMapUpdatesTheParent()
        {
            var mapReference = new ValueReferenceDefinitionBuilder()
                               .WithStartingValue(new Dictionary <string, ValueReferenceDefinition>()).Build().CreateValueReference(engine);
            var map = mapReference.ValueAsMap();
            int watchListenerCalled = 0;

            mapReference.Watch(updatedMap =>
            {
                watchListenerCalled++;
            });

            map["foo"].Set(BigDouble.One);
            Assert.AreEqual(3, watchListenerCalled);
        }
        public void WatchListenerReceivesMapValueWhenChildUpdates()
        {
            var mapReference = new ValueReferenceDefinitionBuilder()
                               .WithStartingValue(new Dictionary <string, ValueReferenceDefinition>()).Build().CreateValueReference(engine);
            var map = mapReference.ValueAsMap();
            int watchListenerCalled = 0;

            mapReference.Watch(updatedMap =>
            {
                Assert.IsNotNull(updatedMap as IDictionary <string, ValueReference>);
                watchListenerCalled++;
            });

            map["foo"].Set(BigDouble.One);
            Assert.AreEqual(3, watchListenerCalled);
        }