How to use GenC class of B package

Best Nunit code snippet using B.GenC

TypeNameDifferenceTests.cs

Source:TypeNameDifferenceTests.cs Github

copy

Full Screen

...65        class GenA<T>66        { }67        class GenB<T>68        { }69        class GenC<T, R>70        { }71        namespace B72        {73            class GenX<T>74            { }75            class GenY<T>76            { }77        }78    }79    namespace B80    {81        class GenA<T>82        { }83        class GenB<T>84        { }85        class GenC<T, R>86        { }87        namespace B88        {89            class GenX<T>90            { }91            class GenY<T>92            { }93        }94    }95    #endregion96    public class TypeNameDifferenceTests97    {98        #region Mock types99        class Dummy100        {101            internal readonly int value;102            public Dummy(int value)103            {104                this.value = value;105            }106            public override string ToString()107            {108                return "Dummy " + value;109            }110        }111        class Dummy1112        {113            internal readonly int value;114            public Dummy1(int value)115            {116                this.value = value;117            }118            public override string ToString()119            {120                return "Dummy " + value;121            }122        }123        class DummyGenericClass<T>124        {125            private readonly object _obj;126            public DummyGenericClass(object obj)127            {128                _obj = obj;129            }130            public override string ToString()131            {132                return _obj.ToString();133            }134        }135        #endregion136        TypeNameDifferenceResolver _differenceGetter;137        [SetUp]138        public void TestSetup()139        {140            _differenceGetter = new TypeNameDifferenceResolver();141        }142        private void TestShortenedNameDifference(object objA, object objB, string expectedA, string expectedB)143        {144            string actualA, actualB;145            _differenceGetter.ResolveTypeNameDifference(146                 objA, objB, out actualA, out actualB);147            Assert.That(actualA, Is.EqualTo(expectedA));148            Assert.That(actualB, Is.EqualTo(expectedB));149        }150        [Test]151        public void TestResolveTypeNameDifferenceNonGenericDifferingTypes()152        {153            TestShortenedNameDifference(154                new Dummy(1),155                new Dummy1(1),156                "TypeNameDifferenceTests+Dummy",157                "TypeNameDifferenceTests+Dummy1");158        }159        [Test]160        public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypes()161        {162            TestShortenedNameDifference(163                new Dummy(1),164                new Dummy(1),165                "TypeNameDifferenceTests+Dummy",166                "TypeNameDifferenceTests+Dummy");167        }168        [Test]169        public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypesSingularDiffNamespace()170        {171            TestShortenedNameDifference(172                new DifferingNamespace1.Dummy(1),173                new Dummy(1),174                "Dummy",175                "TypeNameDifferenceTests+Dummy");176        }177        [Test]178        public void TestResolveTypeNameDifferenceNonGenericNonDifferingTypesBothDiffNamespace()179        {180            TestShortenedNameDifference(181                new DifferingNamespace1.Dummy(1),182                new DifferingNamespace2.Dummy(1),183                "DifferingNamespace1.Dummy",184                "DifferingNamespace2.Dummy");185        }186        [Test]187        public void TestResolveTypeNameDifferenceGeneric()188        {189            TestShortenedNameDifference(190                new DummyGenericClass<Dummy1>(new Dummy(1)),191                new DummyGenericClass<Dummy>(new Dummy(1)),192                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy1]",193                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");194        }195        [Test]196        public void TestResolveTypeNameDifferenceGenericDifferingNamespaces()197        {198            TestShortenedNameDifference(199                new DummyGenericClass<Dummy>(new Dummy(1)),200                new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),201                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]",202                "TypeNameDifferenceTests+DummyGenericClass`1[Dummy]");203            TestShortenedNameDifference(204                new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),205                new DummyGenericClass<Dummy>(new Dummy(1)),206                "TypeNameDifferenceTests+DummyGenericClass`1[Dummy]",207                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");208            TestShortenedNameDifference(209                new DummyGenericClass<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1)),210                new DummyGenericClass<DifferingNamespace2.Dummy>(new DifferingNamespace2.Dummy(1)),211                "TypeNameDifferenceTests+DummyGenericClass`1[DifferingNamespace1.Dummy]",212                "TypeNameDifferenceTests+DummyGenericClass`1[DifferingNamespace2.Dummy]");213        }214        [Test]215        public void TestResolveTypeNameDifferenceGenericDifferentAmountGenericParams()216        {217            TestShortenedNameDifference(218                new DummyGenericClass<Dummy>(new Dummy(1)),219                new KeyValuePair<int, string>(1, ""),220                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]",221                "KeyValuePair`2[Int32,String]");222            TestShortenedNameDifference(223                new KeyValuePair<int, string>(1, ""),224                new DummyGenericClass<Dummy>(new Dummy(1)),225                "KeyValuePair`2[Int32,String]",226                "TypeNameDifferenceTests+DummyGenericClass`1[TypeNameDifferenceTests+Dummy]");227        }228        [Test]229        public void TestResolveNameDifferenceOneIsGenericOtherIsNot()230        {231            TestShortenedNameDifference(232                new DummyGenericClass<Dummy>(new Dummy(1)),233                new Dummy(1),234                "DummyGenericClass`1[Dummy]",235                "Dummy");236            TestShortenedNameDifference(237                new Dummy(1),238                new DummyGenericClass<Dummy>(new Dummy(1)),239                "Dummy",240                "DummyGenericClass`1[Dummy]");241            TestShortenedNameDifference(242                new KeyValuePair<string, int>("str", 0),243                new Dummy(1),244                "KeyValuePair`2[String,Int32]",245                "Dummy");246            TestShortenedNameDifference(247                new Dummy(1),248                new KeyValuePair<string, int>("str", 0),249                "Dummy",250                "KeyValuePair`2[String,Int32]");251            TestShortenedNameDifference(252                new Dummy(1),253                new A.GenA<B.GenA<B.GenC<string, int>>>(),254                "Dummy",255                "GenA`1[GenA`1[GenC`2[String,Int32]]]");256            TestShortenedNameDifference(257                new A.GenA<B.GenA<B.GenC<string, int>>>(),258                new Dummy(1),259                "GenA`1[GenA`1[GenC`2[String,Int32]]]",260                "Dummy");261        }262        [Test]263        public void TestNestedGenerics()264        {265            TestShortenedNameDifference(266                new DifferingNamespace1.DummyGeneric<List<string>>(new List<string>()),267                new DifferingNamespace1.DummyGeneric<IEnumerable<string>>(new List<string>()),268                "DummyGeneric`1[List`1[String]]",269                "DummyGeneric`1[IEnumerable`1[String]]");270            TestShortenedNameDifference(271                new DifferingNamespace1.DummyGeneric<IEnumerable<string>>(new List<string>()),272                new DifferingNamespace1.DummyGeneric<List<string>>(new List<string>()),273                "DummyGeneric`1[IEnumerable`1[String]]",274                "DummyGeneric`1[List`1[String]]");275            TestShortenedNameDifference(276                new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>>(new KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>()),277                new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>>(new KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>()),278                "DummyGeneric`1[KeyValuePair`2[DifferingNamespace1.Dummy,DifferingNamespace2.Dummy]]",279                "DummyGeneric`1[KeyValuePair`2[DifferingNamespace2.Dummy,DifferingNamespace1.Dummy]]");280            TestShortenedNameDifference(281                new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>>(new KeyValuePair<DifferingNamespace2.Dummy, DifferingNamespace1.Dummy>()),282                new DifferingNamespace1.DummyGeneric<KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>>(new KeyValuePair<DifferingNamespace1.Dummy, DifferingNamespace2.Dummy>()),283                "DummyGeneric`1[KeyValuePair`2[DifferingNamespace2.Dummy,DifferingNamespace1.Dummy]]",284                "DummyGeneric`1[KeyValuePair`2[DifferingNamespace1.Dummy,DifferingNamespace2.Dummy]]");285            TestShortenedNameDifference(286                new A.GenA<A.B.GenX<int>>(),287                new B.GenA<A.B.GenX<short>>(),288                "A.GenA`1[GenX`1[Int32]]",289                "B.GenA`1[GenX`1[Int16]]");290            TestShortenedNameDifference(291                new B.GenA<A.B.GenX<short>>(),292                new A.GenA<A.B.GenX<int>>(),293                "B.GenA`1[GenX`1[Int16]]",294                "A.GenA`1[GenX`1[Int32]]");295            TestShortenedNameDifference(296                new A.GenC<int, string>(),297                new B.GenC<int, A.GenA<string>>(),298                "A.GenC`2[Int32,String]",299                "B.GenC`2[Int32,GenA`1[String]]");300            TestShortenedNameDifference(301                new A.GenA<A.GenC<string, int>>(),302                new B.GenC<A.GenA<List<int>>, B.GenC<string, int>>(),303                "GenA`1[GenC`2[String,Int32]]",304                "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,Int32]]");305            TestShortenedNameDifference(306               new B.GenC<A.GenA<List<int>>, B.GenC<string, int>>(),307               new A.GenA<A.GenC<string, int>>(),308               "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,Int32]]",309               "GenA`1[GenC`2[String,Int32]]");310            TestShortenedNameDifference(311               new B.GenC<A.GenA<List<int>>, B.GenC<string, B.GenC<string, int>>>(),312               new A.GenA<B.GenC<string, B.GenC<string,int>>>(),313               "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,GenC`2[String,Int32]]]",314               "GenA`1[GenC`2[String,GenC`2[String,Int32]]]");315            TestShortenedNameDifference(316               new A.GenA<B.GenC<string, B.GenC<string, int>>>(),317               new B.GenC<A.GenA<List<int>>, B.GenC<string, B.GenC<string, int>>>(),318               "GenA`1[GenC`2[String,GenC`2[String,Int32]]]",319               "GenC`2[GenA`1[List`1[Int32]],GenC`2[String,GenC`2[String,Int32]]]");320        }321        [Test]322        public void TestIsObjectInstanceGeneric()323        {324            var notGeneric = new DifferingNamespace1.Dummy(1);325            Assert.False(_differenceGetter.IsTypeGeneric(notGeneric.GetType()));326            var generic = new DifferingNamespace1.DummyGeneric<DifferingNamespace1.Dummy>(new DifferingNamespace1.Dummy(1));327            Assert.That(_differenceGetter.IsTypeGeneric(generic.GetType()));328        }329        [Test]330        public void TestGetTopLevelGenericName()331        {332            var generic = new DifferingNamespace1.DummyGeneric<int>(1).GetType();333            var expected = "NUnit.Framework.Internal.DifferingNamespace1.DummyGeneric`1";334            var actual = _differenceGetter.GetGenericTypeName(generic);335            Assert.AreEqual(expected, actual);336        }337        [Test]338        public void TestGetTopLevelGenericNameThrowsWhenNotGeneric()339        {340            var notGeneric = new object().GetType();341            Assert.Throws<ArgumentException>(() => _differenceGetter.GetGenericTypeName(notGeneric));342        }343        [Test]344        public void TestReconstructShortenedGenericTypeName()345        {346            var expected = "KeyValuePair`2[String,Int32]";347            var actual = _differenceGetter.ReconstructGenericTypeName(348                "KeyValuePair`2",349                new List<string>() { "String", "Int32" });350            Assert.AreEqual(expected, actual);351        }352        private void TestShortenTypeNames(object objA, object objB, string shortenedA, string shortenedB)353        {354            string actualA, actualB;355            _differenceGetter.ShortenTypeNames(objA.GetType(), objB.GetType(), out actualA, out actualB);356            Assert.AreEqual(shortenedA, actualA);357            Assert.AreEqual(shortenedB, actualB);358        }359        [Test]360        public void TestShortenTypeNamesDifferingNamespace()361        {362            TestShortenTypeNames(363               new DifferingNamespace1.Dummy(1),364               new DifferingNamespace2.Dummy(1),365               "DifferingNamespace1.Dummy",366               "DifferingNamespace2.Dummy");367        }368        private void TestShortenGenericTopLevelTypeNames(object objA, object objB, string shortenedA, string shortenedB)369        {370            string actualA, actualB;371            _differenceGetter.GetShortenedGenericTypes(objA.GetType(), objB.GetType(), out actualA, out actualB);372            Assert.AreEqual(shortenedA, actualA);373            Assert.AreEqual(shortenedB, actualB);374        }375        [Test]376        public void TestShortenGenericTopLevelTypes()377        {378            TestShortenGenericTopLevelTypeNames(379                new A.GenA<int>(),380                new B.GenA<int>(),381                "A.GenA`1",382                "B.GenA`1");383            TestShortenGenericTopLevelTypeNames(384                new KeyValuePair<string, int>(),385                new KeyValuePair<int, string>(),386                "KeyValuePair`2",387                "KeyValuePair`2");388        }389        private void TestFullyShortenTypeName(Type type, string expectedOutput)390        {391            string actual = _differenceGetter.FullyShortenTypeName(type);392            Assert.AreEqual(expectedOutput, actual);393        }394        [Test]395        public void TestFullyShortenTypeName()396        {397            TestFullyShortenTypeName(398                new A.GenA<A.GenA<int>>().GetType(),399                "GenA`1[GenA`1[Int32]]");400            TestFullyShortenTypeName(401                new A.GenC<B.GenA<int>, A.GenA<int>>().GetType(),402                "GenC`2[GenA`1[Int32],GenA`1[Int32]]");403        }404    }405}...

Full Screen

Full Screen

test4.cs

Source:test4.cs Github

copy

Full Screen

...8    public static string teststr1 = null;9    public static string[] teststr2 = new string[3];10    public static string teststr3 = null;11    public const string teststr4 = "const string\"";	// special case for DiffObjRef12    public const string testgenstr4 = "GenC const string\"";  // special case for DiffObjRef13    public static string teststr5 = null;  // special case for DiffObjRef14    public static bool TestSameObjRef()15    {16        Console.WriteLine();17        Console.WriteLine("When NGEN'ed, two strings in different modules have different object reference");18        Console.WriteLine("When NGEN'ed, two strings in the same module have same object reference");19        Console.WriteLine("When JIT'ed, two strings always have same object reference");20        Console.WriteLine();21        Console.WriteLine("Testing SameObjRef");22        bool passed = true;23        string b = null;24        try25        {26            teststr1 = "static \uC09C\u7B8B field";27            b = C.teststr1;28            throw new Exception();29        }30        catch (System.Exception)31        {32        }33        if ((object)teststr1 != (object)b)34        {35            passed = false;36            Console.WriteLine("FAILED, (object) teststr1 == (object) b is expected");37        }38        try39        {40            teststr2[0] = "\u3F2Aarray element 0";41            b = C.teststr2[0];42            throw new Exception();43        }44        catch (System.Exception)45        {46            if ((object)teststr2[0] != (object)C.teststr2[0])47            {48                passed = false;49                Console.WriteLine("FAILED, (object) teststr2[0] == (object)C.teststr2[0] is expected");50            }51        }52        try53        {54            throw new Exception();55        }56        catch (System.Exception)57        {58            teststr2[1] = "array element 1\uCB53";59            b = C.teststr2[1];60        }61        if ((object)teststr2[1] != (object)b)62        {63            passed = false;64            Console.WriteLine("FAILED, (object) teststr2[1] == (object) b is expected");65        }66        try67        {68            throw new Exception();69        }70        catch (System.Exception)71        {72        }73        finally74        {75            teststr2[2] = "array \u47BBelement 2";76        }77        if ((object)teststr2[2] != (object)C.teststr2[2])78        {79            passed = false;80            Console.WriteLine("FAILED, (object)teststr2[2] == (object)C.teststr2[2] is expected");81        }82        try83        {84            teststr3 = @"method return\\";85            throw new Exception();86        }87        catch (System.Exception)88        {89            if ((object)teststr3 != (object)C.teststr3())90            {91                passed = false;92                Console.WriteLine("FAILED, (object) teststr3 == (object)C.teststr3() is expected");93            }94            try95            {96            }97            finally98            {99                if ((object)teststr4 != (object)C.teststr4)100                {101                    passed = false;102                    Console.WriteLine("FAILED, (object)teststr4 != (object)C.teststr4  is expected");103                }104                try105                {106                    throw new Exception();107                }108                catch109                {110                }111                finally112                {113                    teststr5 = String.Empty;114                    if ((object)teststr5 != (object)C.teststr5)115                    {116                        passed = false;117                        Console.WriteLine("FAILED, (object) teststr5 != (object)C.teststr5  is expected");118                    }119                }120            }121        }122        // Generic Class123        try124        {125            teststr1 = "GenC static \uC09C\u7B8B field";126            b = GenC<string>.teststr1;127            throw new Exception();128        }129        catch (System.Exception)130        {131        }132        if ((object)teststr1 != (object)b)133        {134            passed = false;135            Console.WriteLine("FAILED, (object)teststr1 == (object)GenC<string>.teststr1 is expected");136        }137        try138        {139            teststr2[0] = "GenC \u3F2Aarray element 0";140            throw new Exception();141        }142        catch (System.Exception)143        {144            if ((object)teststr2[0] != (object)GenC<string>.teststr2[0])145            {146                passed = false;147                Console.WriteLine("FAILED, (object) teststr2[0] == (object)GenC<string>.teststr2[0] is expected");148            }149        }150        try151        {152            throw new Exception();153        }154        catch (System.Exception)155        {156            teststr2[1] = "GenC array element 1\uCB53";157            b = GenC<string>.teststr2[1];158        }159        if ((object)teststr2[1] != (object)b)160        {161            passed = false;162            Console.WriteLine("FAILED, (object) teststr2[1] == (object)GenC<string>.teststr2[1] is expected");163        }164        try165        {166            throw new Exception();167        }168        catch (System.Exception)169        {170        }171        finally172        {173            teststr2[2] = "GenC array \u47BBelement 2";174        }175        if ((object)teststr2[2] != (object)GenC<string>.teststr2[2])176        {177            passed = false;178            Console.WriteLine("FAILED, (object)teststr2[2] == (object)GenC<string>.teststr2[2] is expected");179        }180        try181        {182            teststr3 = @"GenC method return\\";183            throw new Exception();184        }185        catch (System.Exception)186        {187            if ((object)teststr3 != (object)GenC<string>.teststr3<int>())188            {189                passed = false;190                Console.WriteLine("FAILED, (object) teststr3 == (object)GenC<string>.teststr3<int>() is expected");191            }192            try193            {194            }195            finally196            {197                if ((object)testgenstr4 != (object)GenC<string>.teststr4)198                {199                    passed = false;200                    Console.WriteLine("FAILED, (object)testgenstr4 != (object)GenC<string>.teststr4  is expected");201                }202                try203                {204                    throw new Exception();205                }206                catch207                {208                }209                finally210                {211                    teststr5 = String.Empty;212                    if ((object)teststr5 != (object)GenC<string>.teststr5)213                    {214                        passed = false;215                        Console.WriteLine("FAILED, (object) teststr5 != (object)GenC<string>.teststr5  is expected");216                    }217                }218            }219        }220        return passed;221    }222    public static bool TestDiffObjRef()223    {224        Console.WriteLine();225        Console.WriteLine("When NGEN'ed, two strings in different modules have different object reference");226        Console.WriteLine("When NGEN'ed, two strings in the same module have same object reference");227        Console.WriteLine("When JIT'ed, two strings always have same object reference");228        Console.WriteLine();229        Console.WriteLine("Testing DiffObjRef");230        bool passed = true;231        string b = null;232        try233        {234            teststr1 = "static \uC09C\u7B8B field";235            b = C.teststr1;236            throw new Exception();237        }238        catch (System.Exception)239        {240        }241        if ((object)teststr1 == (object)b)242        {243            passed = false;244            Console.WriteLine("FAILED, (object) teststr1 == (object) b is NOT expected");245        }246        try247        {248            teststr2[0] = "\u3F2Aarray element 0";249            b = C.teststr2[0];250            throw new Exception();251        }252        catch (System.Exception)253        {254            if ((object)teststr2[0] == (object)C.teststr2[0])255            {256                passed = false;257                Console.WriteLine("FAILED, (object) teststr2[0] == (object)C.teststr2[0] is NOT expected");258            }259        }260        try261        {262            throw new Exception();263        }264        catch (System.Exception)265        {266            teststr2[1] = "array element 1\uCB53";267            b = C.teststr2[1];268        }269        if ((object)teststr2[1] == (object)b)270        {271            passed = false;272            Console.WriteLine("FAILED, (object) teststr2[1] == (object) b is NOT expected");273        }274        try275        {276            throw new Exception();277        }278        catch (System.Exception)279        {280        }281        finally282        {283            teststr2[2] = "array \u47BBelement 2";284        }285        if ((object)teststr2[2] == (object)C.teststr2[2])286        {287            passed = false;288            Console.WriteLine("FAILED, (object)teststr2[2] == (object)C.teststr2[2] is NOT expected");289        }290        try291        {292            teststr3 = @"method return\\";293            throw new Exception();294        }295        catch (System.Exception)296        {297            if ((object)teststr3 == (object)C.teststr3())298            {299                passed = false;300                Console.WriteLine("FAILED, (object) teststr3 == (object)C.teststr3() is NOT expected");301            }302            try303            {304            }305            finally306            {307                // Special case for const literal teststr4308                // two consecutive LDSTR is emitted by C# compiler for the following statement309                // as a result, both are interned in the same module and object comparison returns true310                if ((object)teststr4 != (object)C.teststr4)311                {312                    passed = false;313                    Console.WriteLine("FAILED, (object)teststr4 == (object)C.teststr4  is expected");314                }315                try316                {317                    throw new Exception();318                }319                catch320                {321                }322                finally323                {324                    teststr5 = String.Empty;325                    // Special case for String.Empty326                    // String.Empty is loaded using LDSFLD, rather than LDSTR in any module327                    // as a result, it is always the same reference to [mscorlib]System.String::Empty,328                    // and object comparison return true329                    if ((object)teststr5 != (object)C.teststr5)330                    {331                        passed = false;332                        Console.WriteLine("FAILED, (object) teststr5 == (object)C.teststr5 is expected");333                    }334                }335            }336        }337        // Generic Class338        try339        {340            teststr1 = "GenC static \uC09C\u7B8B field";341            b = GenC<string>.teststr1;342            throw new Exception();343        }344        catch (System.Exception)345        {346        }347        if ((object)teststr1 == (object)b)348        {349            passed = false;350            Console.WriteLine("FAILED, (object)teststr1 == (object)GenC<string>.teststr1 is NOT expected");351        }352        try353        {354            teststr2[0] = "GenC \u3F2Aarray element 0";355            throw new Exception();356        }357        catch (System.Exception)358        {359            if ((object)teststr2[0] == (object)GenC<string>.teststr2[0])360            {361                passed = false;362                Console.WriteLine("FAILED, (object) teststr2[0] == (object)GenC<string>.teststr2[0] is NOT expected");363            }364        }365        try366        {367            throw new Exception();368        }369        catch (System.Exception)370        {371            teststr2[1] = "GenC array element 1\uCB53";372            b = GenC<string>.teststr2[1];373        }374        if ((object)teststr2[1] == (object)b)375        {376            passed = false;377            Console.WriteLine("FAILED, (object) teststr2[1] == (object)GenC<string>.teststr2[1] is NOT expected");378        }379        try380        {381            throw new Exception();382        }383        catch (System.Exception)384        {385        }386        finally387        {388            teststr2[2] = "GenC array \u47BBelement 2";389        }390        if ((object)teststr2[2] == (object)GenC<string>.teststr2[2])391        {392            passed = false;393            Console.WriteLine("FAILED, (object)teststr2[2] == (object)GenC<string>.teststr2[2] is NOT expected");394        }395        try396        {397            teststr3 = @"GenC method return\\";398            throw new Exception();399        }400        catch (System.Exception)401        {402            if ((object)teststr3 == (object)GenC<string>.teststr3<int>())403            {404                passed = false;405                Console.WriteLine("FAILED, (object) teststr3 == (object)GenC<string>.teststr3<int>() is NOT expected");406            }407            try408            {409            }410            finally411            {412                // Special case for const literal teststr4413                // two consecutive LDSTR is emitted by C# compiler for the following statement414                // as a result, both are interned in the same module and object comparison returns true415                if ((object)testgenstr4 != (object)GenC<string>.teststr4)416                {417                    passed = false;418                    Console.WriteLine("FAILED, (object)testgenstr4 == (object)GenC<string>.teststr4 is expected");419                }420                try421                {422                    throw new Exception();423                }424                catch425                {426                }427                finally428                {429                    teststr5 = String.Empty;430                    // Special case for String.Empty431                    // String.Empty is loaded using LDSFLD, rather than LDSTR in any module432                    // as a result, it is always the same reference to [mscorlib]System.String::Empty,433                    // and object comparison return true434                    if ((object)teststr5 != (object)GenC<string>.teststr5)435                    {436                        passed = false;437                        Console.WriteLine("FAILED, (object) teststr5 == (object)GenC<string>.teststr5 is expected");438                    }439                }440            }441        }442        return passed;443    }444    public static int Main(string[] args)445    {446        bool passed = false;447        if ((args.Length < 1) || (args[0].ToUpper() == "SAMEOBJREF"))448            passed = TestSameObjRef();449        else if (args[0].ToUpper() == "DIFFOBJREF")450            passed = TestDiffObjRef();451        else...

Full Screen

Full Screen

test1.cs

Source:test1.cs Github

copy

Full Screen

...47        {48            Console.WriteLine("(object)teststr5 == (object)C.teststr5 is expected.  FAILED");49            passed = false;50        }51        if ((object)teststr1 == (object)GenC<string>.teststr1)52        {53            Console.WriteLine("(object)teststr1 == (object)GenC<string>.teststr1 is not expected.  FAILED");54            passed = false;55        }56        if ((object)teststr2[0] == (object)GenC<string>.teststr2[0])57        {58            Console.WriteLine("(object)teststr2[0] == (object)GenC<string>.teststr2[0] is not expected.  FAILED");59            passed = false;60        }61        if ((object)teststr3() == (object)GenC<string>.teststr3<string>())62        {63            Console.WriteLine("(object)teststr3() == (object)GenC<string>.teststr3<string>() is not expected.  FAILED");64            passed = false;65        }66        if (Object.ReferenceEquals((object)teststr4, (object)GenC<string>.teststr4))67        {68            Console.WriteLine("Object.ReferenceEquals((object)teststr4, (object)GenC<string>.teststr4) is not expected.  FAILED");69            passed = false;70        }71        if ((object)teststr5 != (object)GenC<string>.teststr5)72        {73            Console.WriteLine("(object)teststr5 != (object)GenC<string>.teststr5 is not expected.  FAILED");74            passed = false;75        }76        return passed;77    }78    public static bool TestDiffObjRef()79    {80        Console.WriteLine();81        Console.WriteLine("When NGEN'ed, two strings in different modules have different object reference");82        Console.WriteLine("When NGEN'ed, two strings in the same module have same object reference");83        Console.WriteLine("When JIT'ed, two strings always have same object reference");84        Console.WriteLine();85        Console.WriteLine("Testing DiffObjRef");86        bool passed = true;87        if ((object)teststr1 == (object)C.teststr1)88        {89            Console.WriteLine("(object)teststr1 == (object)C.teststr1 is not expected.  FAILED");90            passed = false;91        }92        if ((object)teststr2[0] == (object)C.teststr2[0])93        {94            Console.WriteLine("(object)teststr2[0] == (object)C.teststr2[0] is not expected.  FAILED");95            passed = false;96        }97        if (Object.ReferenceEquals((object)teststr3(), (object)C.teststr3()))98        {99            Console.WriteLine("(object)teststr3() == (object)C.teststr3() is not expected.  FAILED");100            passed = false;101        }102        // Special case for const literal teststr4103        // two consecutive LDSTR is emitted by C# compiler for the following statement104        // as a result, both are interned in the same module and object comparison returns true105        if ((object)teststr4 != (object)C.teststr4)106        {107            Console.WriteLine("(object)teststr4 != (object)C.teststr4 is not expected.  FAILED");108            passed = false;109        }110        // Special case for String.Empty111        // String.Empty is loaded using LDSFLD, rather than LDSTR in any module112        // as a result, it is always the same reference to [mscorlib]System.String::Empty,113        // and object comparison return true114        if ((object)teststr5 != (object)C.teststr5)115        {116            Console.WriteLine("(object)teststr5 != (object)C.teststr5 is not expected.  FAILED");117            passed = false;118        }119        if ((object)"GenC static \uC09C\u7B8B field" == (object)GenC<string>.teststr1)120        {121            Console.WriteLine("(object)\"GenC static \uC09C\u7B8B field\" == (object)GenC<string>.teststr1 is not expected.  FAILED");122            passed = false;123        }124        if ((object)"GenC \u3F2Aarray element 0" == (object)GenC<string>.teststr2[0])125        {126            Console.WriteLine("(object)\"GenC \u3F2Aarray element 0\" == (object)GenC<string>.teststr2[0] is not expected.  FAILED");127            passed = false;128        }129        if ((object)@"GenC method return\\" == (object)GenC<string>.teststr3<string>())130        {131            Console.WriteLine("(object)\"GenC method return\\\" == (object)GenC<string>.teststr3<string>() is not expected.  FAILED");132            passed = false;133        }134        // Special case for const literal teststr4135        // two consecutive LDSTR is emitted by C# compiler for the following statement136        // as a result, both are interned in the same module and object comparison returns true137        if (!Object.ReferenceEquals((object)"GenC const string\"", (object)GenC<string>.teststr4))138        {139            Console.WriteLine("(object)\"GenC const string\"\" != (object)GenC<string>.teststr4 is not expected.  FAILED");140            passed = false;141        }142        // Special case for String.Empty143        // String.Empty is loaded using LDSFLD, rather than LDSTR in any module144        // as a result, it is always the same reference to [mscorlib]System.String::Empty,145        // and object comparison return true146        if ((object)teststr5 != (object)GenC<string>.teststr5)147        {148            Console.WriteLine("(object)teststr5 != (object)GenC<string>.teststr5 is not expected.  FAILED");149            passed = false;150        }151        return passed;152    }153    public static int Main(string[] args)154    {155        bool passed = false;156        if ((args.Length < 1) || (args[0].ToUpper() == "SAMEOBJREF"))157            passed = TestSameObjRef();158        else if (args[0].ToUpper() == "DIFFOBJREF")159            passed = TestDiffObjRef();160        else161        {162            Console.WriteLine("Usage: Test1.exe [SameObjRef|DiffObjRef]");...

Full Screen

Full Screen

test2.cs

Source:test2.cs Github

copy

Full Screen

...17        bool passed = true;18        switch (C.teststr1)19        {20            case "static \uC09C\u7B8B field":21                switch (GenC<object>.teststr2[0])22                {23                    case "\u3F2Aarray element 0":24                        passed = false;25                        break;26                    default:27                        break;28                }29                break;30            default:31                passed = false;32                break;33        }34        switch (C.teststr3())35        {36            case @"method return\\":37                switch (GenC<string>.teststr5)38                {39                    case "":40                        switch (C.teststr3())41                        {42                            case @"method return\\":43                                break;44                            default:45                                passed = false;46                                break;47                        }48                        break;49                    default:50                        passed = false;51                        break;52                }53                break;54            default:55                passed = false;56                break;57        }58        int i;59        for (i = 1; (i < teststr2.Length) && (object)C.teststr2[i] == (object)teststr2[i]; i++)60            ;61        if (i != teststr2.Length)62        {63            Console.WriteLine("for, (object)C.teststr2[i]==(object)teststr2[i] is not expected, FAILED");64            passed = false;65        }66        switch (GenC<string>.teststr1)67        {68            case "static \uC09C\u7B8B field":69                passed = false;70                break;71            default:72                switch (GenC<string>.teststr2[0])73                {74                    case "GenC \u3F2Aarray element 0":75                        break;76                    default:77                        passed = false;78                        break;79                }80                break;81        }82        switch (GenC<int>.teststr3<int>())83        {84            case @"GenC method return\\":85                switch (GenC<string>.teststr4)86                {87                    case "GenC const string\"":88                        break;89                    default:90                        passed = false;91                        break;92                }93                break;94            default:95                passed = false;96                break;97        }98        for (i = 1; (i < teststr2.Length) && (object)GenC<object>.teststr2[i] != (object)C.teststr2[i]; i++)99            ;100        if (i != teststr2.Length)101        {102            Console.WriteLine("for, (object)GenC<object>.teststr2[i]!=(object)C.teststr2[i] is not expected, FAILED");103            passed = false;104        }105        return passed;106    }107    public static bool TestDiffObjRef()108    {109        Console.WriteLine();110        Console.WriteLine("When NGEN'ed, two strings in different modules have different object reference");111        Console.WriteLine("When NGEN'ed, two strings in the same module have same object reference");112        Console.WriteLine("When JIT'ed, two strings always have same object reference");113        Console.WriteLine();114        Console.WriteLine("Testing DiffObjRef");115        bool passed = true;116        switch (C.teststr1)117        {118            case "static \uC09C\u7B8B field":119                switch (C.teststr2[0])120                {121                    case "\u3F2Aarray element 0":122                        break;123                    default:124                        passed = false;125                        break;126                }127                break;128            default:129                passed = false;130                break;131        }132        switch (C.teststr3())133        {134            case @"method return\\":135                switch (GenC<string>.teststr5)136                {137                    case "":138                        switch (C.teststr3())139                        {140                            case @"method return\\":141                                break;142                            default:143                                passed = false;144                                break;145                        }146                        break;147                    default:148                        passed = false;149                        break;150                }151                break;152            default:153                passed = false;154                break;155        }156        for (int i = 1; (i < teststr2.Length) && (object)C.teststr2[i] == (object)teststr2[i]; i++)157        {158            Console.WriteLine("for, (object)C.teststr2[i]==(object)teststr2[i] is not expected, FAILED");159            passed = false;160        }161        switch (GenC<string>.teststr1)162        {163            case "static \uC09C\u7B8B field":164                passed = false;165                break;166            default:167                switch (GenC<string>.teststr2[0])168                {169                    case "GenC \u3F2Aarray element 0":170                        break;171                    default:172                        passed = false;173                        break;174                }175                break;176        }177        switch (GenC<int>.teststr3<int>())178        {179            case @"GenC method return\\":180                switch (GenC<string>.teststr4)181                {182                    case "GenC const string\"":183                        break;184                    default:185                        passed = false;186                        break;187                }188                break;189            default:190                passed = false;191                break;192        }193        for (int i = 1; (i < teststr2.Length) && (object)GenC<object>.teststr2[i] == (object)"GenC array element 1\uCB53"; i++)194        {195            Console.WriteLine("for, (object)GenC<object>.teststr2[i]==(object)C.teststr2[i] is not expected, FAILED");196            passed = false;197        }198        return passed;199    }200    public static int Main(string[] args)201    {202        bool passed = false;203        if ((args.Length < 1) || (args[0].ToUpper() == "SAMEOBJREF"))204            passed = TestSameObjRef();205        else if (args[0].ToUpper() == "DIFFOBJREF")206            passed = TestDiffObjRef();207        else208        {209            Console.WriteLine("Usage: Test2.exe [SameObjRef|DiffObjRef]");...

Full Screen

Full Screen

GenCodeVisitor.cs

Source:GenCodeVisitor.cs Github

copy

Full Screen

...5using ProgramTree;6using System.Reflection.Emit;7namespace SimpleLang.Visitors8{9    public class GenCodeVisitor: Visitor10    {11        private Dictionary<string, LocalBuilder> vars = new Dictionary<string, LocalBuilder>();12        private GenCodeCreator genc;13        public GenCodeVisitor()14        {15            genc = new GenCodeCreator();16        }17        public override void VisitIdNode(IdNode id) 18        {19            // Этот Visit не вызывается если переменная стоит слева от оператора присваивания !20            // Т.е. он вызывается только если id находится в выражении, а значит, мы просто кладем его значение на стек!21            genc.Emit(OpCodes.Ldloc, vars[id.Name]);22        }23        public override void VisitIntNumNode(IntNumNode num) 24        {25            genc.Emit(OpCodes.Ldc_I4, num.Num);26        }27        public override void VisitBinOpNode(BinOpNode binop) 28        {29            binop.Left.Visit(this);...

Full Screen

Full Screen

Gaa.cs

Source:Gaa.cs Github

copy

Full Screen

...15            Random rand = new Random();16            int N = 10;17            static int size = 10;18            public List<int> GenA = new List<int>();19            public List<int> GenC = new List<int>();20            public List<int> GenB = new List<int>();21            public int ostA = size;22            public int ostB = size;23            public int ostC = size;24            public Xromossomi(int i)25            {26                ostA = i;27                ostB = i;28                ostC = i;29            }30            public Xromossomi() { }31        }32        Xromossomi nach()33        {34            Xromossomi xrom = new Xromossomi();35            int buff = 0;36            for (int i = 0; i < N / 2 - 1; i++)37            {38                if (xrom.ostA == 2)39                {40                    buff = 2;41                    xrom.ostA = 0;42                }43                else44                    if (xrom.ostA == 1)45                    {46                        xrom.GenA[xrom.GenA.Count - 1]++;47                        xrom.ostA = 0;48                        buff = 0;49                    }50                    else51                        if (xrom.ostA == 0)52                            buff = 0;53                        else54                            xrom.ostA -= buff = rand.Next(2, xrom.ostA);55                xrom.GenA.Add(buff);56            }57            xrom.GenA.Add(xrom.ostA);58            //59            int s = N % 3 == 2 ? N / 3 + 1 : N / 3;60            int t = N % 3 == 1 || N % 3 == 2 ? N / 3 + 1 : N / 3;61            buff = 0;62            for (int i = 0; i < N / 2 - 1; i++)63            {64                if (xrom.ostB == 0 && 10 == xrom.GenA.Sum() && xrom.GenA[2] != 0)65                {66                }67                if (xrom.ostB == 2)68                {69                    buff = 2;70                    xrom.ostB = 0;71                }72                else73                    if (xrom.ostB == 1)74                    {75                        if (xrom.GenB.Count == 0)76                            xrom.GenA[(N / 3) - 1]++;77                        else78                            xrom.GenB[xrom.GenB.Count - 1]++;79                        xrom.ostB = 0;80                    }81                    else82                        if (xrom.ostB == 0)83                            buff = 0;84                        else85                            xrom.ostB -= buff = rand.Next(2, xrom.ostB);86                xrom.GenB.Add(buff);87            }88            xrom.GenB.Add(xrom.ostB);89            ///90            for (int i = 0; i < N / 2 - 1; i++)91            {92                if (xrom.ostC == 2)93                {94                    buff = 2;95                    xrom.ostC = 0;96                }97                else98                    if (xrom.ostC == 1)99                    {100                        xrom.GenC[xrom.GenC.Count - 1]++;101                        xrom.ostC = 0;102                    }103                    else104                        if (xrom.ostC == 0)105                            buff = 0;106                        else107                            xrom.ostC -= buff = rand.Next(2, xrom.ostC);108                xrom.GenC.Add(buff);109            }110            if (xrom.ostC == 1)111            {112                xrom.GenC[xrom.GenC.Count - 1]++;113                xrom.ostC = 0;114            }115            else116                xrom.GenC.Add(xrom.ostC);117            return xrom;118        }119        public List<Xromossomi> SetXrom()120        {121            for (int i = 0; i < 50; i++)122            {123                nabor.Add(nach());124            }125            xor();126            return nabor;127        }128        void xor()129        {130            int[] massA = new int[50];131            int[] massB = new int[50];132            int[] massC = new int[50];133            int buff;134            int v;135            for (int i = 0; i < 50; i++)136            {137                massA[i] = i;138            }139            List<Xromossomi> nabor1 = new List<Xromossomi>();140            for (int i = 0; i < 50; i++)141                nabor1.Add(new Xromossomi());142            for (int i = 0; i < 50; i++)143            {144                buff = massA[v = rand.Next(50)];145                massA[v] = massA[v = rand.Next(50)];146                massA[v] = buff;147            }148            //149            for (int i = 0; i < 50; i++)150            {151                buff = massB[v = rand.Next(50)];152                massB[v] = massB[v = rand.Next(50)];153                massB[v] = buff;154            }155            //156            for (int i = 0; i < 50; i++)157            {158                buff = massC[v = rand.Next(50)];159                massC[v] = massC[v = rand.Next(50)];160                massC[v] = buff;161            }162            for (int i = 0; i < 50; i++)163            {164                nabor1[i].GenA = nabor[massA[i]].GenA;165                nabor1[i].GenB = nabor[massA[i]].GenB;166                nabor1[i].GenC = nabor[massA[i]].GenC;167            }168            nabor = nabor1;169        }170        void mutation()171        {172            Random rand = new Random();173            int i;174            foreach (var elem1 in nabor)175            {176                for (int i1 = 0; i1 < 1; i1++)177                {178                    if (elem1.GenA[i = rand.Next(elem1.GenA.Count - 1)] - 2 > 1)179                    {180                        elem1.GenA[i] -= 2;181                        elem1.GenA[rand.Next(elem1.GenA.Count - 1)] += 2;182                    }183                    if (elem1.GenB[i = rand.Next(elem1.GenB.Count - 1)] - 2 > 1)184                    {185                        elem1.GenB[i] -= 2;186                        elem1.GenB[rand.Next(elem1.GenB.Count - 1)] += 2;187                    }188                    if (elem1.GenC[i = rand.Next(elem1.GenC.Count - 1)] - 2 > 1)189                    {190                        elem1.GenC[i] -= 2;191                        elem1.GenC[rand.Next(elem1.GenC.Count - 1)] += 2;192                    }193                }194            };195        }196    }197}...

Full Screen

Full Screen

GenC

Using AI Code Generation

copy

Full Screen

1using B;2{3    static void Main()4    {5        GenC obj = new GenC();6        obj.Show();7    }8}9using C;10{11    static void Main()12    {13        GenC obj = new GenC();14        obj.Show();15    }16}

Full Screen

Full Screen

GenC

Using AI Code Generation

copy

Full Screen

1using B;2{3{4public static void Main()5{6GenC obj = new GenC();7obj.show();8}9}10}11using B;12{13{14public static void Main()15{16GenC obj = new GenC();17obj.show();18}19}20}21Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42221.cs(11,1): error CS0246: The type or namespace name `GenC' could not be found. Are you missing a using directive or an assembly reference?231.cs(11,1): error CS0246: The type or namespace name `GenC' could not be found. Are you missing a using directive or an assembly reference?241.cs(11,1): error CS0246: The type or namespace name `GenC' could not be found. Are you missing a using directive or an assembly reference?251 Error(s)

Full Screen

Full Screen

GenC

Using AI Code Generation

copy

Full Screen

1using B;2{3    static void Main()4    {5        GenC<int> g = new GenC<int>();6        g.Show(10);7    }8}9using B;10{11    static void Main()12    {13        GenD<int> g = new GenD<int>();14        g.Show(10);15    }16}17using B;18{19    static void Main()20    {21        GenE<int> g = new GenE<int>();22        g.Show(10);23    }24}25using B;26{27    static void Main()28    {29        GenF<int> g = new GenF<int>();30        g.Show(10);31    }32}33using B;34{35    static void Main()36    {37        GenG<int> g = new GenG<int>();38        g.Show(10);39    }40}41using B;42{43    static void Main()44    {45        GenH<int> g = new GenH<int>();46        g.Show(10);47    }48}49using B;50{51    static void Main()52    {53        GenI<int> g = new GenI<int>();54        g.Show(10);55    }56}57using B;58{59    static void Main()60    {61        GenJ<int> g = new GenJ<int>();62        g.Show(10);63    }64}65using B;66{67    static void Main()68    {69        GenK<int> g = new GenK<int>();70        g.Show(10);71    }72}73using B;

Full Screen

Full Screen

GenC

Using AI Code Generation

copy

Full Screen

1using B;2{3static void Main()4{5GenC obj = new GenC();6obj.Show();7}8}

Full Screen

Full Screen

GenC

Using AI Code Generation

copy

Full Screen

1using B;2{3    static void Main()4    {5        GenC<int> obj = new GenC<int>();6        obj.display(10);7    }8}9using B;10{11    static void Main()12    {13        GenC<int> obj = new GenC<int>();14        obj.display(10);15    }16}17using B;18{19    static void Main()20    {21        GenC<int> obj = new GenC<int>();22        obj.display(10);23    }24}25using B;26{27    static void Main()28    {29        GenC<int> obj = new GenC<int>();30        obj.display(10);31    }32}33using B;34{35    static void Main()36    {37        GenC<int> obj = new GenC<int>();38        obj.display(10);39    }40}41using B;42{43    static void Main()44    {

Full Screen

Full Screen

Nunit tutorial

Nunit is a well-known open-source unit testing framework for C#. This framework is easy to work with and user-friendly. LambdaTest’s NUnit Testing Tutorial provides a structured and detailed learning environment to help you leverage knowledge about the NUnit framework. The NUnit tutorial covers chapters from basics such as environment setup to annotations, assertions, Selenium WebDriver commands, and parallel execution using the NUnit framework.

Chapters

  1. NUnit Environment Setup - All the prerequisites and setup environments are provided to help you begin with NUnit testing.
  2. NUnit With Selenium - Learn how to use the NUnit framework with Selenium for automation testing and its installation.
  3. Selenium WebDriver Commands in NUnit - Leverage your knowledge about the top 28 Selenium WebDriver Commands in NUnit For Test Automation. It covers web browser commands, web element commands, and drop-down commands.
  4. NUnit Parameterized Unit Tests - Tests on varied combinations may lead to code duplication or redundancy. This chapter discusses how NUnit Parameterized Unit Tests and their methods can help avoid code duplication.
  5. NUnit Asserts - Learn about the usage of assertions in NUnit using Selenium
  6. NUnit Annotations - Learn how to use and execute NUnit annotations for Selenium Automation Testing
  7. Generating Test Reports In NUnit - Understand how to use extent reports and generate reports with NUnit and Selenium WebDriver. Also, look into how to capture screenshots in NUnit extent reports.
  8. Parallel Execution In NUnit - Parallel testing helps to reduce time consumption while executing a test. Deep dive into the concept of Specflow Parallel Execution in NUnit.

NUnit certification -

You can also check out the LambdaTest Certification to enhance your learning in Selenium Automation Testing using the NUnit framework.

YouTube

Watch this tutorial on the LambdaTest Channel to learn how to set up the NUnit framework, run tests and also execute parallel testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful