Ejemplo n.º 1
0
        public void TestClear()
        {
            var bag = new LazyPropertyHolderBase();

            bag.PropertiesCount.Is(0);

            bag.SetValue("int", 1);
            bag.SetValue("string", 2);

            bag.PropertiesCount.Is(2);

            bag.ClearProperties();
            bag.PropertiesCount.Is(0);
        }
        public void TestDeletePropertyObject()
        {
            var bag          = new LazyPropertyHolderBase();
            var propertyName = "Property-Name";

            bag.DeleteProperty(propertyName).IsFalse();
            bag.SetValue(propertyName, 10);
            bag.DeleteProperty(propertyName).IsTrue();
        }
        public void TestTryGetValueAsObject()
        {
            var bag          = new LazyPropertyHolderBase();
            var propertyName = "Property-Name";

            bag.TryGetValueAsObject(propertyName, out _).IsFalse();

            bag.SetValue(propertyName, DateTimeOffset.Now);
            bag.TryGetValueAsObject(propertyName, out _).IsTrue();
        }
Ejemplo n.º 4
0
        public void TestTryGetValueReturnFalse()
        {
            var bag = new LazyPropertyHolderBase();

            var propertyName = "Property-Name";

            bag.TryGetValue <int>(propertyName, out _).IsFalse();

            bag.SetValue(propertyName, 1);
            bag.TryGetValue <int>(propertyName, out _).IsTrue();
            bag.TryGetValue <string>(propertyName, out _).IsFalse();
        }
Ejemplo n.º 5
0
        public void TestCurdWithSortOfDataTypes <T>(T value)
        {
            var propertyName = "Property-" + (value?.ToString() ?? "null");

            var bag = new LazyPropertyHolderBase();

            bag.SetValue(propertyName, value).Is(true);
            bag.PropertiesCount.Is(1);

            bag.GetValue <T>(propertyName).Is(value);
            bag.Properties.Is(new KeyValuePair <string, object>[] {
                new KeyValuePair <string, object>(propertyName, value),
            });

            bag.TryGetValue(propertyName, out T obtainedValue).Is(true);
            obtainedValue.Is(value);

            bag.DeleteProperty <T>(propertyName).Is(true);
            bag.PropertiesCount.Is(0);
        }
Ejemplo n.º 6
0
        public void TestChangeHandlerInvoked <T>(int[] setValues, bool[] shouldInvokedValues)
        {
            var propertyName = "Property-Name";
            var bag          = new LazyPropertyHolderBase();

            var prev = default(int);

            for (var i = 0; i < setValues.Length; i++)
            {
                var next          = setValues[i];
                var shouldInvoked = shouldInvokedValues[i];

                this.Output.WriteLine("prev: {0}, next: {1}", prev, next);

                var onChangingCalled = false;
                var onChangedCalled  = false;

                bag.SetValue(
                    propertyName,
                    next,
                    onChanging: (oldValue, newValue) =>
                {
                    oldValue.Is(prev);
                    newValue.Is(next);
                    onChangingCalled = true;
                },
                    onChanged: (oldValue, newValue) =>
                {
                    oldValue.Is(prev);
                    newValue.Is(next);
                    onChangedCalled = true;
                });

                onChangingCalled.Is(shouldInvoked);
                onChangedCalled.Is(shouldInvoked);

                prev = next;
            }
        }