static void Main(string[] args) { var GetArrayElement = ""; int[] ArrayOfNums = new int[10]; int GetNumber; Console.WriteLine("Enter 10 numbers"); for (int count = 0; count < 10; count++) { Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Number {0} --> \t", count + 1); GetArrayElement = Console.ReadLine(); bool parseSuccess = int.TryParse(GetArrayElement, out GetNumber); if (parseSuccess) { ArrayOfNums[count] = GetNumber; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("This is not a number! Enter Again"); count -= 1; } } Console.Clear(); DelegateTest DelTestClass = new DelegateTest(); FilterArray DelEvenNum = new FilterArray(EvenNum); FilterArray DelCompareNum = new FilterArray(CompareNum); FilterArray DelDivisibleNum = new FilterArray(DivisibleNum); bool Value = true; while (Value) { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\nEnter Your Choice \n 1.Return all even numbers.\n 2.Return numbers greater than 10\n 3.Return numbers divisible by 5.\n 4. Break"); int UserChoice = Int32.Parse(Console.ReadLine()); switch (UserChoice) { case 1: DelTestClass.GetResult(ArrayOfNums, DelEvenNum); break; case 2: DelTestClass.GetResult(ArrayOfNums, DelCompareNum); break; case 3: DelTestClass.GetResult(ArrayOfNums, DelDivisibleNum); break; case 4: Value = false; break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Wrong choice made!"); break; } } }
public void CreateObjectsTest() { IServiceCollection pool = Implementation.CreateServiceCollection(); IServiceScopeFactory factory = Implementation.CreateServiceScopeFactory(pool); IServiceProvider services = factory.CreateScope().ServiceProvider; try { object staticobj = services.CreateInstance(typeof(StaticObject), 10) as StaticObject; Assert.Fail(); } catch (InvalidOperationException) { } try { IFake fakeobj = services.CreateInstance <IFake>(); Assert.Fail(); } catch (InvalidOperationException) { } try { AbstractObject absobj = services.CreateInstance <AbstractObject>(); Assert.Fail(); } catch (InvalidOperationException) { } try { PrivateObject privateobj = services.CreateInstance <PrivateObject>(5); Assert.Fail(); } catch (InvalidOperationException) { } try { EnumTest enumobj = services.CreateInstance <EnumTest>(); Assert.Fail(); } catch (InvalidOperationException) { } try { DelegateTest delegateobj = services.CreateInstance <DelegateTest>(); Assert.Fail(); } catch (Exception) { } GenericObject <int> intgeneric = services.CreateInstance <GenericObject <int> >(10); Assert.AreEqual(10, intgeneric.Value); GenericObject <double> doublegeneric = services.CreateInstance <GenericObject <double> >(); Assert.AreEqual(0, doublegeneric.Value); try { int[] intarray = services.CreateInstance <int[]>(10); Assert.Fail(); } catch (InvalidOperationException) { } int inttest = services.CreateInstance <int>(5); Assert.AreEqual(5, inttest); StructObject structobj = services.CreateInstance <StructObject>(5); Assert.AreEqual(5, structobj.Value); }