public void CanSetTheValueContainedByAReferenceToABool()
        {
            var reference = new ValueReferenceDefinitionBuilder().WithStartingValue(true).Build().CreateValueReference(engine);

            reference.Set(false);
            Assert.IsFalse(reference.ValueAsBool());
        }
        public void CanSetTheValueContainedByAReferenceToANumber()
        {
            var reference = new ValueReferenceDefinitionBuilder().WithStartingValue(BigDouble.One).Build().CreateValueReference(engine);

            reference.Set(new BigDouble(2));
            Assert.AreEqual(reference.ValueAsNumber(), new BigDouble(2));
        }
        public void CanSetTheValueContainedByAReferenceToAString()
        {
            var reference = new ValueReferenceDefinitionBuilder().WithStartingValue("oldString").Build().CreateValueReference(engine);

            reference.Set("newString");
            Assert.AreEqual(reference.ValueAsString(), "newString");
        }
        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 ChangingValueOfWatchedValueNotifiesListeners()
        {
            var valueReference = new ValueReferenceDefinitionBuilder().Build().CreateValueReference(engine);
            int calls          = 0;

            valueReference.Watch(newValue =>
            {
                calls++;
                if (calls == 1)
                {
                    Assert.AreEqual(BigDouble.Zero, newValue);
                }
                else
                {
                    Assert.AreEqual(BigDouble.One, newValue);
                }
            });
            valueReference.Set(BigDouble.One);
            Assert.AreEqual(2, calls);
        }