public void SuccesfullyCreateObjectWithNoArguments()
        {
            var value = new AgnosticArrayValue();

            Assert.NotNull(value);
            Assert.Null(value.Info);
            Assert.Null(value.Value);
        }
Exemple #2
0
        public void FailToReturnObjectThatIsNotAnArrayType()
        {
            var defaultValue = new int[] { 1, 2, 3 };

            var value = new AgnosticArrayValue(defaultValue);

            Assert.Throws <ArgumentException>(() =>
            {
                var covertedArray = value.ToArray <double>();
            });
        }
        public void SuccesfullyCreateObjectWithMinimalArguments()
        {
            var defaultValue = new int[] { 1, 2, 3 };

            var value = new AgnosticArrayValue(defaultValue);

            Assert.NotNull(value);
            Assert.Collection((int[])value.Value,
                              i => Assert.Equal(defaultValue[0], i),
                              i => Assert.Equal(defaultValue[1], i),
                              i => Assert.Equal(defaultValue[2], i));
            Assert.Equal(defaultValue.GetType(), value.Value.GetType());
        }
        public void FailToCreateObjectWithInvalidValue()
        {
            var defaultValue = new int[] { 1, 2, 3 };
            var name         = "foobar";
            var description  = "foobar description";
            var unit         = new XCalculateLib.Unit("foobar", "foobars", "fb", "fbs");

            bool validator(object i) => ((int[])i).Length >= 0 && ((int[])i).Length < 3;

            Assert.Throws <ArgumentException>(() =>
            {
                var value = new AgnosticArrayValue(defaultValue, new ValueInfo(name, description, unit), validator);
            });
        }
Exemple #5
0
        public void SuccessfullyReturnArrayOfSameType()
        {
            var defaultValue = new int[] { 1, 2, 3 };

            var value = new AgnosticArrayValue(defaultValue);

            var covertedArray = value.ToArray <int[]>();

            Assert.Collection(covertedArray,
                              i => Assert.Equal(defaultValue[0], i),
                              i => Assert.Equal(defaultValue[1], i),
                              i => Assert.Equal(defaultValue[2], i));
            Assert.Equal(defaultValue.GetType(), value.Value.GetType());
        }
        public void SuccessfullySetValueOfNullTypeWithNonNullType()
        {
            var newValue = new int[] { 1, 2, 3 };

            var value = new AgnosticArrayValue();

            value.Value = newValue;

            Assert.Collection((int[])value.Value,
                              i => Assert.Equal(newValue[0], i),
                              i => Assert.Equal(newValue[1], i),
                              i => Assert.Equal(newValue[2], i));
            Assert.Equal(newValue.GetType(), value.Value.GetType());
        }
        public void SuccessfullySetNewValueOfSameType()
        {
            var defaultValue = new int[] { 1, 2, 3 };
            var newValue     = new int[] { 4, 5, 6, 7 };

            var value = new AgnosticArrayValue(defaultValue);

            value.Value = newValue;

            Assert.Collection((int[])value.Value,
                              i => Assert.Equal(newValue[0], i),
                              i => Assert.Equal(newValue[1], i),
                              i => Assert.Equal(newValue[2], i),
                              i => Assert.Equal(newValue[3], i));
            Assert.Equal(newValue.GetType(), value.Value.GetType());
        }
        public void SuccessfullySetNewValueWithDifferentType()
        {
            var defaultValue = new int[] { 1, 2, 3 };
            var newValue     = new double[] { 4.0, 5.0, 6.0, 7.0 };

            var value = new AgnosticArrayValue(defaultValue);

            value.Value = newValue;

            Assert.Collection((double[])value.Value,
                              i => Assert.Equal(newValue[0], i),
                              i => Assert.Equal(newValue[1], i),
                              i => Assert.Equal(newValue[2], i),
                              i => Assert.Equal(newValue[3], i));
            Assert.Equal(newValue.GetType(), value.Value.GetType());
        }
        public void SuccessfullyCreateObjectWithNullValue()
        {
            Array defaultValue = null;
            var   name         = "foobar";
            var   description  = "foobar description";
            var   unit         = new XCalculateLib.Unit("foobar", "foobars", "fb", "fbs");

            bool validator(object i) => true;

            var value = new AgnosticArrayValue(defaultValue, new ValueInfo(name, description, unit), validator);

            Assert.NotNull(value);
            Assert.Null(value.Value);
            Assert.NotNull(value.Info);
            Assert.Equal(name, value.Info.Name);
            Assert.Equal(description, value.Info.Description);
            Assert.Equal(unit, value.Info.Unit);
        }
        public void FailToSetNewValueThatIsInvalid()
        {
            var defaultValue = new int[] { 1, 2, 3 };
            var newValue     = new int[] { 4, 5, 6, 7 };
            var name         = "foobar";
            var description  = "foobar description";
            var unit         = new XCalculateLib.Unit("foobar", "foobars", "fb", "fbs");

            bool validator(Array i)
            {
                return(i.Length > 0 && i.Length <= 3);
            }

            var value = new AgnosticArrayValue(defaultValue, new ValueInfo(name, description, unit), validator);

            Assert.Throws <ArgumentException>(() =>
            {
                value.Value = newValue;
            });
        }
        public void SuccesfullyCreateObjectWithAllArguments()
        {
            var defaultValue = new int[] { 1, 2, 3 };
            var name         = "foobar";
            var description  = "foobar description";
            var unit         = new XCalculateLib.Unit("foobar", "foobars", "fb", "fbs");

            bool validator(object i) => ((int[])i).Length >= 0 && ((int[])i).Length < 200;

            var value = new AgnosticArrayValue(defaultValue, new ValueInfo(name, description, unit), validator);

            Assert.NotNull(value);
            Assert.Collection((int[])value.Value,
                              i => Assert.Equal(defaultValue[0], i),
                              i => Assert.Equal(defaultValue[1], i),
                              i => Assert.Equal(defaultValue[2], i));
            Assert.Equal(defaultValue.GetType(), value.Value.GetType());
            Assert.NotNull(value.Info);
            Assert.Equal(name, value.Info.Name);
            Assert.Equal(description, value.Info.Description);
            Assert.Equal(unit, value.Info.Unit);
        }