public void MWArray_GetField_InvalidOperationException_NonExists_Field_Test()
        {
            var f  = "arrayfield";
            var sa = new MWStructArray(new int[] { 1 }, new string[] { f });

            sa[f] = new MWNumericArray();

            Assert.That(() => MWArrayExtensions.GetField(sa, "nonexists"), Throws.InvalidOperationException);
        }
        public void MWArray_GetField_Array_String_Input()
        {
            var   f      = "arrayfield";
            Array value  = Enumerable.Range(0, 42).Select(i => i.ToString()).ToArray();
            var   sa     = new MWStructArray(new int[] { 1 }, new string[] { f });
            var   result = new MWCharArray(value);

            sa[f] = result;

            Assert.That(MWArrayExtensions.GetField(sa, f).Equals(result));
        }
        public void MWArray_GetField_Char_Input()
        {
            var  f      = "arrayfield";
            char value  = 'c';
            var  sa     = new MWStructArray(new int[] { 1 }, new string[] { f });
            var  result = new MWCharArray(value);

            sa[f] = result;

            Assert.That(MWArrayExtensions.GetField(sa, f).Equals(result));
        }
        public void MWArray_GetField_Bool_Input()
        {
            var  f      = "arrayfield";
            bool value  = true;
            var  sa     = new MWStructArray(new int[] { 1 }, new string[] { f });
            var  result = new MWLogicalArray(value);

            sa[f] = result;

            Assert.That(MWArrayExtensions.GetField(sa, f).Equals(result));
        }
        public void MWArray_GetField_Scalar_Short_Input()
        {
            var   f     = "shortfield";
            short value = 42;
            var   sa    = new MWStructArray(new int[] { 1 }, new string[] { f });

            sa[f] = value;

            var ra = new MWNumericArray(value);

            Assert.That(MWArrayExtensions.GetField(sa, f).Equals(ra));
        }
        public void MWArray_GetField_Composite_Field_Name_Input()
        {
            var f1 = "composite";
            var f2 = "field";

            var   f      = $"{f1}.{f2}";
            Array value  = Enumerable.Range(0, 42).ToArray();
            var   result = new MWNumericArray(value);

            var sa1 = new MWStructArray(new int[] { 1 }, new string[] { f1 });
            var sa2 = new MWStructArray(new int[] { 1 }, new string[] { f2 });

            sa1[f1] = sa2;
            sa2[f2] = result;

            Assert.That(MWArrayExtensions.GetField(sa1, f).Equals(result));
            Assert.That(MWArrayExtensions.GetField(sa2, f2).Equals(result));
            Assert.That(MWArrayExtensions.GetField(sa1, f1).Equals(sa2));
        }
        public void MWArray_GetField_Scalar_Multiple_Input()
        {
            var sf  = "shortfield";
            var lf  = "longfield";
            var _if = "intfield";

            short svalue = 42;
            long  lvalue = 424242424242424;
            int   ivalue = 42424242;

            var sa = new MWStructArray(new int[] { 1 }, new string[] { sf, lf, _if });

            sa[sf]  = svalue;
            sa[lf]  = lvalue;
            sa[_if] = ivalue;

            var lra = new MWNumericArray(lvalue);
            var ira = new MWNumericArray(ivalue);
            var sra = new MWNumericArray(svalue);

            Assert.That(MWArrayExtensions.GetField(sa, sf).Equals(sra));
            Assert.That(MWArrayExtensions.GetField(sa, lf).Equals(lra));
            Assert.That(MWArrayExtensions.GetField(sa, _if).Equals(ira));
        }
 public void MWArray_GetField_InvalidOperationException_EmptyStructArray_Test()
 {
     Assert.That(() => MWArrayExtensions.GetField(new MWStructArray(), "epmty"), Throws.InvalidOperationException);
 }
 public void MWArray_GetField_ArgumentException_Test()
 {
     Assert.That(() => MWArrayExtensions.GetField(new MWNumericArray(), "field"), Throws.ArgumentException);
     Assert.That(() => MWArrayExtensions.GetField(new MWStructArray(), "\n"), Throws.ArgumentException);
     Assert.That(() => MWArrayExtensions.GetField(new MWStructArray(), "field", -1), Throws.ArgumentException);
 }
 public void MWArray_GetField_NullReferenceException_Test()
 {
     Assert.That(() => MWArrayExtensions.GetField(null, "field"), Throws.ArgumentNullException);
     Assert.That(() => MWArrayExtensions.GetField(new MWStructArray(), null), Throws.ArgumentNullException);
 }