Exemple #1
0
    public static bool TestValueTypeDelegates()
    {
        Console.Write("Testing delegates to value types...");

        {
            TestValueType t = new TestValueType { X = 123 };
            Func<string, string> d = t.GiveX;
            string result = d("MyPrefix");
            if (result != "MyPrefix123")
                return false;
        }

        {
            object t = new TestValueType { X = 456 };
            Func<string> d = t.ToString;
            string result = d();
            if (result != "456")
                return false;
        }

        {
            Func<int, TestValueType> d = TestValueType.MakeValueType;
            TestValueType result = d(789);
            if (result.X != 789)
                return false;
        }

        Console.WriteLine("OK");
        return true;
    }
        /// <summary>
        ///     Creates a collection of a TestValue Type and selects only the needed items from a Collection with help of the input
        ///     parameter
        /// </summary>
        /// <typeparam name="T">
        ///     the collection type. For example: <see cref="IncontinencePadRewetTestValue" />,
        ///     <see cref="IncontinencePadAcquisitionTimeTestValue" />,<see cref="IncontinencePadRetentionTestValue" />
        /// </typeparam>
        /// <param name="testValue">the testvalues that contain the data</param>
        /// <param name="testValueType">the value type of the test. <see cref="TestValueType" /></param>
        /// <param name="testTypeIncontinencePad">the type of the incontinence pad. <see cref="TestTypeIncontinencePad" /></param>
        /// <param name="toTestTypeTestValueAction">
        ///     the action the get the correct data for a collection item. For example:
        ///     <see cref="ToRewetTestValue" />, <see cref="ToRetentionTestValue" />, <see cref="ToAcquisitionTimeTestValue" />
        /// </param>
        /// <returns>
        ///     A Collection with the Type of the output from the <paramref name="toTestTypeTestValueAction" /> given as a
        ///     input action
        /// </returns>
        public Collection <T> ToTestValuesCollectionByTestType <T>(IEnumerable <TestValue> testValue,
                                                                   TestValueType testValueType,
                                                                   ICollection <TestTypeIncontinencePad> testTypeIncontinencePad,
                                                                   Func <IncontinencePadTestValue, String, String, Int32, T> toTestTypeTestValueAction)
        {
            var tests = new Collection <T>();

            testValue.ToList()
            .Where(
                x =>
                (x.TestValueType == testValueType) &&
                x.IncontinencePadTestValue.TestType.IsIn(testTypeIncontinencePad))
            .ForEach(
                x =>
                tests.Add(toTestTypeTestValueAction(
                              x.IncontinencePadTestValue,
                              x.LastEditedPerson,
                              LaborCreatorServiceHelper.GenerateProdCode(x.TestSheet.MachineNr,
                                                                         x.TestSheet.CreatedDateTime.Year,
                                                                         x.DayInYearOfArticleCreation,
                                                                         x.IncontinencePadTestValue.IncontinencePadTime)
                              ,
                              x.TestValueId)));
            return(tests);
        }
 public static TestValueType IncludeTests(this TestValueType testValueType, ITestRepository testRepository)
 {
     if (testValueType.Tests != null)
     {
         return(testValueType);
     }
     testValueType.Tests = (TestList)testRepository.GetDataByTestValueTypeId(testValueType.Id);
     return(testValueType);
 }
 public static TestValueType IncludeTestType(this TestValueType testValueType, ITestTypeRepository testTypeRepository)
 {
     if (testValueType.TestType != null)
     {
         return(testValueType);
     }
     testValueType.TestType = testTypeRepository.GetDataById(testValueType.TestTypeId).ToList().First();
     return(testValueType);
 }
        public void Empty_value_maybe_roundtrips_successfully_to_json()
        {
            var testObj = new TestValueType {
                TheMaybe = Maybe.Empty <int>()
            };

            var deserialized = PerformRoundtrip(testObj);

            Assert.True(deserialized.TheMaybe.IsEmpty);
        }
        public void Test_IsNotPrimitiveValueType()
        {
            var v1 = new TestValueType();

            Assert.IsTrue(ReflectionMethods.IsNotPrimitiveValueType(v1));

            var v2 = 0;

            Assert.IsFalse(ReflectionMethods.IsNotPrimitiveValueType(v2));
        }
        public void Existing_value_maybe_roundtrips_successfully_to_json()
        {
            var testObj = new TestValueType {
                TheMaybe = Maybe.Is(42)
            };

            var deserialized = PerformRoundtrip(testObj);

            Assert.True(deserialized.TheMaybe.Exists);
            Assert.Equal(42, deserialized.TheMaybe.It);
        }
 public void Update(Int32 testTypeId, string name, Boolean isActive, Int32 id)
 {
     using (var client = new HttpClient(_messageHandler))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var testValueType = new TestValueType(id, testTypeId, name, isActive);
         var response = client.PutAsync(UrlBase, testValueType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
     }
 }
        /// <summary>
        ///     Gets the IncontinencePadTestValue out of a list of testvalues for the correct
        ///     <see cref="TestTypeIncontinencePad" /> and
        ///     <see cref="TestValueType" />
        ///     One must exists and only one.
        /// </summary>
        /// <param name="testValues">the test values containing the wanted item</param>
        /// <param name="testTypeIncontinencePad">the type of the incontinence pad. <see cref="TestTypeIncontinencePad" /></param>
        /// <param name="testValueType">the value type of the incontinence pad. <see cref="TestValueType" /></param>
        /// <returns></returns>
        public IncontinencePadTestValue GetIncontinencePadTestValueForType(IEnumerable <TestValue> testValues,
                                                                           TestTypeIncontinencePad testTypeIncontinencePad,
                                                                           TestValueType testValueType)
        {
            var values = testValues.ToList()
                         .Where(
                x => (x.TestValueType == testValueType) && (x.IncontinencePadTestValue.TestType == testTypeIncontinencePad))
                         .ToList();
            var item = ValidateTestValueOnlyExactlyOneHasToExist(values, testTypeIncontinencePad.ToString(), testValueType.ToString());

            return(item.IncontinencePadTestValue);
        }
Exemple #10
0
 public void Update(Int32 testTypeId, string name, Boolean isActive, Int32 id)
 {
     using (var client = new HttpClient(_messageHandler))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var testValueType = new TestValueType(id, testTypeId, name, isActive);
         var response      = client.PutAsync(UrlBase, testValueType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
     }
 }
        public void Test_GetPrimitiveValueTypeProperties()
        {
            var v1      = new TestValueType();
            var v1Props = UIPropertyMethods.GetPrimitiveValueTypeProperties(v1);

            Assert.AreEqual(2, v1Props.Length);

            var int1 = v1Props.FirstOrDefault(p => p.PropertyName == "Int1");
            var int2 = v1Props.FirstOrDefault(p => p.PropertyName == "Int2");

            Assert.IsNotNull(int1, "Int1");
            Assert.IsNotNull(int2, "Int2");
        }
Exemple #12
0
    public static bool TestValueTypeDelegates()
    {
        Console.Write("Testing delegates to value types...");

        {
            TestValueType t = new TestValueType {
                X = 123
            };
            Func <string, string> d = t.GiveX;
            string result           = d("MyPrefix");
            if (result != "MyPrefix123")
            {
                return(false);
            }
        }

        {
            object t = new TestValueType {
                X = 456
            };
            Func <string> d      = t.ToString;
            string        result = d();
            if (result != "456")
            {
                return(false);
            }
        }

        {
            Func <int, TestValueType> d      = TestValueType.MakeValueType;
            TestValueType             result = d(789);
            if (result.X != 789)
            {
                return(false);
            }
        }

        Console.WriteLine("OK");
        return(true);
    }
 private TestValue CreateDefaultTestValueBabyDiaper(
     TestValueType testValueType,
     TestTypeBabyDiaper
     testTypeBabyDiaper
     )
 => new TestValue
 {
     ArticleTestType            = ArticleType.BabyDiaper,
     CreatedDateTime            = DateTime.Now,
     CreatedPerson              = "system",
     LastEditedDateTime         = DateTime.Now,
     TestValueType              = testValueType,
     LastEditedPerson           = "system",
     DayInYearOfArticleCreation = DateTime.Now.DayOfYear,
     BabyDiaperTestValue        = new BabyDiaperTestValue
     {
         TestType          = testTypeBabyDiaper,
         RetentionRw       = RwType.Ok,
         Rewet140Rw        = RwType.Ok,
         Rewet210Rw        = RwType.Ok,
         PenetrationRwType = RwType.Ok
     }
 };
 private TestValue CreateDefaultTestValueIncontinencePad(
     TestValueType testValueType,
     TestTypeIncontinencePad
     testTypeIncontinencePad
     )
 => new TestValue
 {
     ArticleTestType            = ArticleType.IncontinencePad,
     CreatedDateTime            = DateTime.Now,
     CreatedPerson              = "system",
     LastEditedDateTime         = DateTime.Now,
     TestValueType              = testValueType,
     LastEditedPerson           = "system",
     DayInYearOfArticleCreation = DateTime.Now.DayOfYear,
     IncontinencePadTestValue   = new IncontinencePadTestValue
     {
         TestType = testTypeIncontinencePad,
         AcquisitionTimeFirstRw  = RwType.Ok,
         AcquisitionTimeSecondRw = RwType.Ok,
         AcquisitionTimeThirdRw  = RwType.Ok,
         RetentionRw             = RwType.Ok,
         RewetFreeRw             = RwType.Ok
     }
 };
Exemple #15
0
 public Int32 Insert(TestValueType testValueType)
 {
     return(Insert((Int32)testValueType.TestTypeId, testValueType.Name, (bool)testValueType.IsActive));
 }
Exemple #16
0
    public static bool TestDynamicInvoke()
    {
        Console.Write("Testing dynamic invoke...");

        {
            TestValueType t = new TestValueType {
                X = 123
            };
            Func <string, string> d = t.GiveX;
            string result           = (string)d.DynamicInvoke(new object[] { "MyPrefix" });
            if (result != "MyPrefix123")
            {
                return(false);
            }
        }

        {
            Func <int, TestValueType> d      = TestValueType.MakeValueType;
            TestValueType             result = (TestValueType)d.DynamicInvoke(new object[] { 789 });
            if (result.X != 789)
            {
                return(false);
            }
        }

        {
            IFoo t = new ClassWithIFoo("Class");
            Func <int, string> d = t.DoFoo;
            if ((string)d.DynamicInvoke(new object[] { 987 }) != "Class987")
            {
                return(false);
            }
        }

        {
            IFoo t = new StructWithIFoo("Struct");
            Func <int, string> d = t.DoFoo;
            if ((string)d.DynamicInvoke(new object[] { 654 }) != "Struct654")
            {
                return(false);
            }
        }

        {
            Func <string, string, string> d = ExtensionClass.Combine;
            if ((string)d.DynamicInvoke(new object[] { "Hello", "World" }) != "HelloWorld")
            {
                return(false);
            }
        }

        {
            Func <string, string> d = "Hi".Combine;
            if ((string)d.DynamicInvoke(new object[] { "There" }) != "HiThere")
            {
                return(false);
            }
        }

        {
            Mutate <int> d    = ClassWithByRefs.Mutate;
            object[]     args = new object[] { 8 };
            d.DynamicInvoke(args);
            if ((int)args[0] != 50)
            {
                return(false);
            }
        }

        {
            Mutate <string> d    = ClassWithByRefs.Mutate;
            object[]        args = new object[] { "Hello" };
            d.DynamicInvoke(args);
            if ((string)args[0] != "HelloMutated")
            {
                return(false);
            }
        }

        unsafe
        {
            GetAndReturnPointerDelegate d = ClassWithPointers.GetAndReturnPointer;
            if ((IntPtr)d.DynamicInvoke(new object[] { (IntPtr)8 }) != (IntPtr)50)
            {
                return(false);
            }
        }

#if false
        // This is hitting an EH bug around throw/rethrow from a catch block (pass is not set properly)
        unsafe
        {
            PassPointerByRefDelegate d = ClassWithPointers.PassPointerByRef;
            var args = new object[] { (IntPtr)8 };

            bool caught = false;
            try
            {
                d.DynamicInvoke(args);
            }
            catch (ArgumentException)
            {
                caught = true;
            }

            if (!caught)
            {
                return(false);
            }
        }
#endif

        Console.WriteLine("OK");
        return(true);
    }
 public Int32 Insert(TestValueType testValueType)
 {
     return Insert((Int32)testValueType.TestTypeId, testValueType.Name, (bool)testValueType.IsActive);
 }
 public void Update(TestValueType testValueType)
 {
     Update((Int32)testValueType.TestTypeId, testValueType.Name, (bool)testValueType.IsActive, (Int32)testValueType.Id);
 }
 public void Delete(TestValueType testValueType)
 {
     Delete((Int32)testValueType.Id);
 }
Exemple #20
0
    public static bool TestDynamicInvoke()
    {
        Console.Write("Testing dynamic invoke...");

        {
            TestValueType t = new TestValueType { X = 123 };
            Func<string, string> d = t.GiveX;
            string result = (string)d.DynamicInvoke(new object[] { "MyPrefix" });
            if (result != "MyPrefix123")
                return false;
        }

        {
            Func<int, TestValueType> d = TestValueType.MakeValueType;
            TestValueType result = (TestValueType)d.DynamicInvoke(new object[] { 789 });
            if (result.X != 789)
                return false;
        }

        {
            IFoo t = new ClassWithIFoo("Class");
            Func<int, string> d = t.DoFoo;
            if ((string)d.DynamicInvoke(new object[] { 987 }) != "Class987")
                return false;
        }

        {
            IFoo t = new StructWithIFoo("Struct");
            Func<int, string> d = t.DoFoo;
            if ((string)d.DynamicInvoke(new object[] { 654 }) != "Struct654")
                return false;
        }

        {
            Func<string, string, string> d = ExtensionClass.Combine;
            if ((string)d.DynamicInvoke(new object[] { "Hello", "World" }) != "HelloWorld")
                return false;
        }

        {
            Func<string, string> d = "Hi".Combine;
            if ((string)d.DynamicInvoke(new object[] { "There" }) != "HiThere")
                return false;
        }

        {
            Mutate<int> d = ClassWithByRefs.Mutate;
            object[] args = new object[] { 8 };
            d.DynamicInvoke(args);
            if ((int)args[0] != 50)
                return false;
        }

        {
            Mutate<string> d = ClassWithByRefs.Mutate;
            object[] args = new object[] { "Hello" };
            d.DynamicInvoke(args);
            if ((string)args[0] != "HelloMutated")
                return false;
        }

        unsafe
        {
            GetAndReturnPointerDelegate d = ClassWithPointers.GetAndReturnPointer;
            if ((IntPtr)d.DynamicInvoke(new object[] { (IntPtr)8 }) != (IntPtr)50)
                return false;
        }

        #if false
        // This is hitting an EH bug around throw/rethrow from a catch block (pass is not set properly)
        unsafe
        {
            PassPointerByRefDelegate d = ClassWithPointers.PassPointerByRef;
            var args = new object[] { (IntPtr)8 };

            bool caught = false;
            try
            {
                d.DynamicInvoke(args);
            }
            catch (ArgumentException)
            {
                caught = true;
            }

            if (!caught)
                return false;
        }
        #endif

        Console.WriteLine("OK");
        return true;
    }
        /// <summary>
        ///     Gets the BabyDiaperTestValue out of a list of testvalues for the correct <see cref="TestTypeBabyDiaper" /> and
        ///     <see cref="TestValueType" />
        ///     One must exists and only one.
        /// </summary>
        /// <param name="testValues">the test values containing the wanted item</param>
        /// <param name="testTypeBabyDiaper">the type of the baby diaper. <see cref="TestTypeBabyDiaper" /></param>
        /// <param name="testValueType">the value type of the baby diaper. <see cref="TestValueType" /></param>
        /// <returns></returns>
        public BabyDiaperTestValue GetBabyDiaperTestValueForType(IEnumerable <TestValue> testValues, TestTypeBabyDiaper testTypeBabyDiaper, TestValueType testValueType)
        {
            var values = testValues.ToList()
                         .Where(
                x => (x.TestValueType == testValueType) && (x.BabyDiaperTestValue.TestType == testTypeBabyDiaper))
                         .ToList();
            var item = ValidateTestValueOnlyExactlyOneHasToExist(values, testTypeBabyDiaper.ToString(), testValueType.ToString());

            return(item.BabyDiaperTestValue);
        }
Exemple #22
0
 public void Delete(TestValueType testValueType)
 {
     Delete((Int32)testValueType.Id);
 }
Exemple #23
0
 public void Update(TestValueType testValueType)
 {
     Update((Int32)testValueType.TestTypeId, testValueType.Name, (bool)testValueType.IsActive, (Int32)testValueType.Id);
 }