How to use MethodNames class of NUnit.Framework.Attributes package

Best Nunit code snippet using NUnit.Framework.Attributes.MethodNames

ReflectionExtensionsTests.cs

Source:ReflectionExtensionsTests.cs Github

copy

Full Screen

1// ***********************************************************************2// Copyright (c) 2015 Charlie Poole, Rob Prouse3//4// Permission is hereby granted, free of charge, to any person obtaining5// a copy of this software and associated documentation files (the6// "Software"), to deal in the Software without restriction, including7// without limitation the rights to use, copy, modify, merge, publish,8// distribute, sublicense, and/or sell copies of the Software, and to9// permit persons to whom the Software is furnished to do so, subject to10// the following conditions:11//12// The above copyright notice and this permission notice shall be13// included in all copies or substantial portions of the Software.14//15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,16// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF17// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND18// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE19// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION20// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION21// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.22// ***********************************************************************23using System;24using System.Collections.Generic;25using System.Linq;26using System.Reflection;27using System.Text;28using NUnit.Compatibility;29namespace NUnit.Framework.Compatibility30{31 /// <summary>32 /// A series of unit tests to ensure that the type extensions in the .NET Standard33 /// framework behave the same as their counterparts in the full framework34 /// </summary>35 [TestFixture]36 public class ReflectionExtensionsTests37 {38 [Test]39 public void CanCallTypeInfoOnAllPlatforms()40 {41 var result = typeof(Object).GetTypeInfo();42 Assert.That(result, Is.Not.Null);43 }44 [Test]45 public void CanGetGenericArguments()46 {47 var result = typeof(GenericTestClass<string, DateTime>).GetGenericArguments();48 Assert.That(result.Length, Is.EqualTo(2));49 Assert.That(result[0], Is.EqualTo(typeof(string)));50 Assert.That(result[1], Is.EqualTo(typeof(DateTime)));51 }52 [Test]53 public void CanGetConstructors()54 {55 var result = typeof(DerivedTestClass).GetConstructors();56 Assert.That(result.Length, Is.EqualTo(3));57 foreach (var ctor in result)58 {59 Assert.That(ctor.IsStatic, Is.False);60 Assert.That(ctor.IsPublic, Is.True);61 }62 }63 [TestCase(typeof(string))]64 [TestCase(typeof(double))]65 [TestCase(typeof(int))]66 public void CanGetConstructorWithParams(Type paramType)67 {68 var result = typeof(DerivedTestClass).GetConstructor(new[] { paramType });69 Assert.That(result, Is.Not.Null);70 }71 [Test]72 public void CanGetGenericConstructor()73 {74 var result = typeof(GenericTestClass<double, double>)75 .GetConstructor(new[] { typeof(double), typeof(int) });76 Assert.That(result, Is.Not.Null);77 }78 [Test]79 public void IsAssignableFromTest()80 {81 bool pass = typeof(BaseTestClass).IsAssignableFrom(typeof(DerivedTestClass));82 bool fail = typeof(DerivedTestClass).IsAssignableFrom(typeof(BaseTestClass));83 Assert.That(pass, Is.True);84 Assert.That(fail, Is.False);85 }86 [Test]87 public void IsInstanceOfTypeTest()88 {89 var baseClass = new BaseTestClass();90 var derivedClass = new DerivedTestClass();91 Assert.That(typeof(BaseTestClass).IsInstanceOfType(baseClass), Is.True);92 Assert.That(typeof(BaseTestClass).IsInstanceOfType(derivedClass), Is.True);93 Assert.That(typeof(DerivedTestClass).IsInstanceOfType(derivedClass), Is.True);94 Assert.That(typeof(DerivedTestClass).IsInstanceOfType(baseClass), Is.False);95 Assert.That(typeof(DerivedTestClass).IsInstanceOfType(null), Is.False);96 }97 [TestCase(typeof(BaseTestClass), typeof(IDisposable))]98 [TestCase(typeof(DerivedTestClass), typeof(IDisposable))]99 [TestCase(typeof(List<int>), typeof(IList<int>))]100 [TestCase(typeof(List<int>), typeof(IEnumerable<int>))]101 public void CanGetInterfaces(Type type, Type @interface)102 {103 var result = type.GetInterfaces();104 Assert.That(result, Is.Not.Null);105 Assert.That(result, Does.Contain(@interface));106 }107 [TestCase(typeof(BaseTestClass), "Name")]108 [TestCase(typeof(BaseTestClass), "StaticString")]109 [TestCase(typeof(BaseTestClass), "Protected")]110 [TestCase(typeof(BaseTestClass), "Dispose")]111 [TestCase(typeof(BaseTestClass), "Private")]112 [TestCase(typeof(DerivedTestClass), "Name")]113 [TestCase(typeof(DerivedTestClass), "Protected")]114 [TestCase(typeof(DerivedTestClass), "Dispose")]115 public void CanGetMember(Type type, string name)116 {117 var result = type.GetMember(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);118 Assert.That(result, Is.Not.Null);119 Assert.That(result.Length, Is.EqualTo(1));120 }121 [Test]122 public void GetStaticMemberOnBaseClass()123 {124 var result = typeof(DerivedTestClass).GetMember("StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);125 Assert.That(result, Is.Not.Null);126 Assert.That(result.Length, Is.GreaterThan(0));127 }128 [Test]129 public void CanGetPublicField()130 {131 var result = typeof(DerivedTestClass).GetField("_public");132 Assert.That(result, Is.Not.Null);133 }134 [Test]135 public void DoesNotGetPrivateField()136 {137 var result = typeof(DerivedTestClass).GetField("_private");138 Assert.That(result, Is.Null);139 }140 [TestCase(typeof(BaseTestClass), "Name")]141 [TestCase(typeof(DerivedTestClass), "Name")]142 [TestCase(typeof(BaseTestClass), "StaticString")]143 public void CanGetProperty(Type type, string name)144 {145 var result = type.GetProperty(name);146 Assert.That(result, Is.Not.Null);147 }148 [Test]149 public void DoesNotGetStaticPropertyOnBase()150 {151 var result = typeof(DerivedTestClass).GetProperty("StaticString");152 Assert.That(result, Is.Null);153 }154 [TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]155 [TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]156 [TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true)]157 [TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, false)]158 [TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, false)]159 [TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]160 [TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]161 [TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]162 [TestCase(typeof(DerivedTestClass), "Private", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]163 [TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, true)]164 [TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, false)]165 [TestCase(typeof(BaseTestClass), "Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]166 [TestCase(typeof(DerivedTestClass), "Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]167 [TestCase(typeof(BaseTestClass), "Private", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]168 [TestCase(typeof(DerivedTestClass), "Private", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]169 [TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]170 [TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, false)]171 [TestCase(typeof(BaseTestClass), "Name", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]172 [TestCase(typeof(DerivedTestClass), "Name", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]173 [TestCase(typeof(BaseTestClass), "Private", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, true)]174 [TestCase(typeof(BaseTestClass), "StaticString", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]175 [TestCase(typeof(DerivedTestClass), "StaticString", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]176 [TestCase(typeof(BaseTestClass), "PubPriv", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]177 [TestCase(typeof(DerivedTestClass), "PubPriv", BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, true)]178 [TestCase(typeof(BaseTestClass), "PubPriv", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]179 [TestCase(typeof(DerivedTestClass), "PubPriv", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, false)]180 [TestCase(typeof(DerivedTestClass), "Protected", BindingFlags.NonPublic | BindingFlags.Instance, true)]181 [TestCase(typeof(DerivedTestClass), "Internal", BindingFlags.NonPublic | BindingFlags.Instance, true)]182 [TestCase(typeof(BaseTestClass), "Protected", BindingFlags.NonPublic | BindingFlags.Instance, true)]183 [TestCase(typeof(BaseTestClass), "Internal", BindingFlags.NonPublic | BindingFlags.Instance, true)]184 public void CanGetPropertyWithBindingFlags(Type type, string name, BindingFlags flags, bool shouldFind)185 {186 var result = type.GetProperty(name, flags);187 Assert.AreEqual(shouldFind, result != null);188 }189 [TestCase(typeof(BaseTestClass), "Dispose", true)]190 [TestCase(typeof(DerivedTestClass), "Dispose", true)]191 [TestCase(typeof(BaseTestClass), "Goodbye", false)]192 [TestCase(typeof(DerivedTestClass), "Goodbye", false)]193 public void CanGetMethodByName(Type type, string name, bool shouldFind)194 {195 var result = type.GetMethod(name);196 Assert.AreEqual(shouldFind, result != null);197 }198 [TestCase(typeof(BaseTestClass), "Hello", new Type[] { }, true)]199 [TestCase(typeof(DerivedTestClass), "Hello", new Type[] { }, true)]200 [TestCase(typeof(BaseTestClass), "Hello", new Type[] { typeof(string) }, true)]201 [TestCase(typeof(DerivedTestClass), "Hello", new Type[] { typeof(string) }, true)]202 [TestCase(typeof(BaseTestClass), "Goodbye", new Type[] { typeof(double) }, false)]203 [TestCase(typeof(DerivedTestClass), "Goodbye", new Type[] { typeof(int) }, false)]204 public void CanGetMethodByNameAndArgs(Type type, string name, Type[] args, bool shouldFind)205 {206 var result = type.GetMethod(name, args);207 Assert.AreEqual(shouldFind, result != null);208 }209 [TestCase(typeof(BaseTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]210 [TestCase(typeof(DerivedTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]211 [TestCase(typeof(BaseTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]212 [TestCase(typeof(DerivedTestClass), "Dispose", BindingFlags.Public | BindingFlags.Instance, true)]213 [TestCase(typeof(BaseTestClass), "StaticMethod", BindingFlags.Public | BindingFlags.Static, true)]214 [TestCase(typeof(DerivedTestClass), "StaticMethod", BindingFlags.Public | BindingFlags.Static, false)]215 [TestCase(typeof(BaseTestClass), "Goodbye", BindingFlags.NonPublic | BindingFlags.Instance, true)]216 public void CanGetMethodByNameAndBindingFlags(Type type, string name, BindingFlags flags, bool shouldFind)217 {218 var result = type.GetMethod(name, flags);219 Assert.AreEqual(shouldFind, result != null);220 }221 [Test]222 public void CanGetDerivedMethodsOnly()223 {224 var result = typeof(DerivedTestClass).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);225 var methodNames = result.Select(m => m.Name);226 CollectionAssert.AreEquivalent(methodNames, new string[] { "Hello", "Hello", "DerivedInstanceMethod" });227 }228 [TestCase(BindingFlags.Instance | BindingFlags.Public,229 new[] { "DerivedInstanceMethod", "InstanceMethod" },230 new[] { "DerivedProtectedInstanceMethod", "DerivedPrivateInstanceMethod", "ProtectedInstanceMethod", "PrivateInstanceMethod" })]231 [TestCase(BindingFlags.Instance | BindingFlags.NonPublic,232 new[] { "DerivedProtectedInstanceMethod", "DerivedPrivateInstanceMethod", "ProtectedInstanceMethod" },233 new[] { "DerivedInstanceMethod", "InstanceMethod", "PrivateInstanceMethod" })]234 [TestCase(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly,235 new[] { "DerivedInstanceMethod" },236 new[] { "DerivedProtectedInstanceMethod", "DerivedPrivateInstanceMethod", "InstanceMethod", "ProtectedInstanceMethod", "PrivateInstanceMethod" })]237 [TestCase(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly,238 new[] { "DerivedProtectedInstanceMethod", "DerivedPrivateInstanceMethod" },239 new[] { "InstanceMethod", "DerivedInstanceMethod", "ProtectedInstanceMethod", "PrivateInstanceMethod" })]240 public void InstanceCanGetMethodsFromCurrentAndFromBaseClass(BindingFlags flags, string[] containElements, string[] wrongElements)241 {242 var result = typeof(DerivedTestClass).GetMethods(flags);243 var methodNames = result.Select(m => m.Name);244 CollectionAssert.IsSubsetOf(containElements, methodNames);245 foreach (var wrongElement in wrongElements)246 {247 Assert.That(methodNames, Does.Not.Contain(wrongElement));248 }249 }250 [TestCase(251 BindingFlags.Static | BindingFlags.Public,252 new[] { "DerivedStaticMethod" },253 new[] { "DerivedProtectedStaticMethod", "DerivedPrivateStaticMethod" })]254 [TestCase(255 BindingFlags.Static | BindingFlags.NonPublic,256 new[] { "DerivedProtectedStaticMethod", "DerivedPrivateStaticMethod" },257 new[] { "DerivedStaticMethod" })]258 [TestCase(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy,259 new[] { "DerivedStaticMethod", "StaticMethod", },260 new[] { "DerivedProtectedStaticMethod", "ProtectedStaticMethod" })]261 [TestCase(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy,262 new[] { "DerivedProtectedStaticMethod", "DerivedPrivateStaticMethod", "ProtectedStaticMethod" },263 new[] { "DerivedStaticMethod", "StaticMethod" })]264 public void StaticCanGetMethodsFromCurrentAndFromBaseClass(BindingFlags flags, string[] containElements, string[] wrongElements)265 {266 var result = typeof(DerivedTestClass).GetMethods(flags);267 var methodNames = result.Select(m => m.Name);268 CollectionAssert.IsSubsetOf(containElements, methodNames);269 foreach (var wrongElement in wrongElements)270 {271 Assert.That(methodNames, Does.Not.Contain(wrongElement));272 }273 }274 [Test]275 public void CanGetStaticMethodsOnBase()276 {277 var result = typeof(DerivedTestClass).GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);278 foreach(var info in result)279 {280 if (info.Name == "StaticMethod")281 Assert.Pass();282 }283 Assert.Fail("Did not find StaticMethod on the base class");284 }285 [TestCase(BindingFlags.Static)]286 [TestCase(BindingFlags.FlattenHierarchy)]287 [TestCase(BindingFlags.Default)]288 public void DoesNotFindStaticMethodsOnBase(BindingFlags flags)289 {290 var result = typeof(DerivedTestClass).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | flags);291 foreach (var info in result)292 {293 if (info.Name == "StaticMethod")294 Assert.Fail("Should not have found StaticMethod on the base class");295 }296 }297 [TestCase("Name", false, true)]298 [TestCase("Name", true, true)]299 [TestCase("Private", false, false)]300 [TestCase("Private", true, true)]301 public void CanGetGetMethod(string name, bool nonPublic, bool shouldFind)302 {303 var pinfo = typeof(BaseTestClass).GetProperty(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);304 Assert.That(pinfo, Is.Not.Null);305 var minfo = pinfo.GetGetMethod(nonPublic);306 Assert.That(minfo != null, Is.EqualTo(shouldFind));307 }308#if NETSTANDARD1_3 || NETSTANDARD1_6309 [Test]310 public void CanGetAttributesUsingAnInterface()311 {312 var method = typeof(ReflectionExtensionsTests).GetMethod("CanGetAttributesUsingAnInterface");313 Assert.That(method, Is.Not.Null);314 var attr = method.GetAttributes<ITestAction>(false);315 Assert.That(attr, Is.Not.Null);316 }317 [Test]318 public void CanHandleNoGetterPropertyMember()319 {320 var result = typeof(NoGetterPropertyDerivedClass).GetMember("NoGetter", BindingFlags.Default);321 Assert.That(result, Is.Not.Null);322 }323#endif324 }325 public class BaseTestClass : IDisposable326 {327 public static string StaticString { get; set; }328 protected string Protected { get; set; }329 internal string Internal { get; set; }330 public string Name { get; set; }331 private string Private { get; set; }332 public string PubPriv { get; private set; }333 public BaseTestClass() : this("Joe") { }334 public BaseTestClass(string name) { Name = name; }335 public virtual void Hello() { }336 public virtual void Hello(string msg) { }337 public void InstanceMethod() { }338 protected void ProtectedInstanceMethod() { }339 private void PrivateInstanceMethod() { }340 public static void StaticMethod() { }341 protected static void ProtectedStaticMethod() { }342 private static void PrivateStaticMethod() { }343 private void Goodbye(double d) { }344 public void Dispose() { }345 }346 public class DerivedTestClass : BaseTestClass347 {348#pragma warning disable 0169349 private string _private;350#pragma warning restore351 public string _public;352 static DerivedTestClass() { StaticString = "static"; }353 public DerivedTestClass() : this("Rob") { }354 public DerivedTestClass(string name) : base(name) { }355 public DerivedTestClass(double d) : this(d.ToString()) { }356 private DerivedTestClass(StringBuilder name) : this(name.ToString()) { }357 public void DerivedInstanceMethod() { }358 protected void DerivedProtectedInstanceMethod() { }359 private void DerivedPrivateInstanceMethod() { }360 public static void DerivedStaticMethod() { }361 protected static void DerivedProtectedStaticMethod() { }362 private static void DerivedPrivateStaticMethod() { }363 public override void Hello() { }364 public override void Hello(string msg) { }365 }366 public class GenericTestClass<T1, T2>367 {368 public T1 PropertyOne { get; set; }369 public T2 PropertyTwo { get; set; }370 public GenericTestClass(T1 one, T2 two)371 {372 PropertyOne = one;373 PropertyTwo = two;374 }375 }376#if NETSTANDARD1_3 || NETSTANDARD1_6377 public class NoGetterPropertyBaseClass378 {379 public string NoGetter { set { } }380 }381 public class NoGetterPropertyDerivedClass : NoGetterPropertyBaseClass382 {383 }384#endif385}...

Full Screen

Full Screen

TextCSTemplateCompilerTests.cs

Source:TextCSTemplateCompilerTests.cs Github

copy

Full Screen

...222 cu.CompiledTemplateType.BaseType.DisplayNameWithExpandedGenericArgs());223 }224225 [Test]226 public void MethodNames()227 {228 const string RENDER_HEADER = "renderHeader";229 const string RENDER_FOOTER = "renderFooter";230 const string RENDER_BODY = "renderBody";231 const string TITLE = "Title";232233 string templateSrc = @"234#<conf>235 <compiler base-class-name=""NFX.NUnit.Templatization.TeztTemplate""236 namespace=""NFX.NUnit.Templatization""237 abstract=""true""238 summary=""Test master page""239 />240#</conf> ...

Full Screen

Full Screen

ReflectionMethodTests.cs

Source:ReflectionMethodTests.cs Github

copy

Full Screen

1using System;2using System.Text;3using System.Collections.Generic;4using NUnit.Framework;5using FlickrNet;6using System.Reflection;7namespace FlickrNetTest8{9 /// <summary>10 /// Summary description for ReflectionMethodTests11 /// </summary>12 [TestFixture]13 public class ReflectionMethodTests14 {15 public ReflectionMethodTests()16 {17 //18 // TODO: Add constructor logic here19 //20 }21 private TestContext testContextInstance;22 /// <summary>23 ///Gets or sets the test context which provides24 ///information about and functionality for the current test run.25 ///</summary>26 public TestContext TestContext27 {28 get29 {30 return testContextInstance;31 }32 set33 {34 testContextInstance = value;35 }36 }37 #region Additional test attributes38 //39 // You can use the following additional attributes as you write your tests:40 //41 // Use ClassInitialize to run code before running the first test in the class42 // [ClassInitialize()]43 // public static void MyClassInitialize(TestContext testContext) { }44 //45 // Use ClassCleanup to run code after all tests in a class have run46 // [ClassCleanup()]47 // public static void MyClassCleanup() { }48 //49 // Use TestInitialize to run code before running each test 50 // [TestInitialize()]51 // public void MyTestInitialize() { }52 //53 // Use TestCleanup to run code after each test has run54 // [TestCleanup()]55 // public void MyTestCleanup() { }56 //57 #endregion58 [Test]59 public void ReflectionMethodsBasic()60 {61 Flickr f = TestData.GetInstance();62 MethodCollection methodNames = f.ReflectionGetMethods();63 Assert.IsNotNull(methodNames, "Should not be null");64 Assert.AreNotEqual(0, methodNames.Count, "Should return some method names.");65 Assert.IsNotNull(methodNames[0], "First item should not be null");66 }67 [Test]68 public void ReflectionMethodsCheckWeSupport()69 {70 Flickr f = TestData.GetInstance();71 MethodCollection methodNames = f.ReflectionGetMethods();72 Assert.IsNotNull(methodNames, "Should not be null");73 Assert.AreNotEqual(0, methodNames.Count, "Should return some method names.");74 Assert.IsNotNull(methodNames[0], "First item should not be null");75 Type type = typeof(Flickr);76 MethodInfo[] methods = type.GetMethods();77 int failCount = 0;78 foreach (string methodName in methodNames)79 {80 bool found = false;81 string trueName = methodName.Replace("flickr.", "").Replace(".", "").ToLower();82 foreach (MethodInfo info in methods)83 {84 if (trueName == info.Name.ToLower())85 {86 found = true;87 break;88 }89 }90 if (!found)91 {92 failCount++;93 Console.WriteLine("Method '" + methodName + "' not found in FlickrNet.Flickr.");94 }95 }96 Assert.AreEqual(0, failCount, "FailCount should be zero. Currently " + failCount + " unsupported methods found.");97 }98 [Test]99 public void ReflectionMethodsCheckWeSupportAsync()100 {101 Flickr f = TestData.GetInstance();102 MethodCollection methodNames = f.ReflectionGetMethods();103 Assert.IsNotNull(methodNames, "Should not be null");104 Assert.AreNotEqual(0, methodNames.Count, "Should return some method names.");105 Assert.IsNotNull(methodNames[0], "First item should not be null");106 Type type = typeof(Flickr);107 MethodInfo[] methods = type.GetMethods();108 int failCount = 0;109 foreach (string methodName in methodNames)110 {111 bool found = false;112 string trueName = methodName.Replace("flickr.", "").Replace(".", "").ToLower() + "async";113 foreach (MethodInfo info in methods)114 {115 if (trueName == info.Name.ToLower())116 {117 found = true;118 break;119 }120 }121 if (!found)122 {123 failCount++;124 Console.WriteLine("Async Method '" + methodName + "' not found in FlickrNet.Flickr.");125 }126 }127 Assert.AreEqual(0, failCount, "FailCount should be zero. Currently " + failCount + " unsupported methods found.");128 }129 [Test]130 public void ReflectionGetMethodInfoSearchArgCheck()131 {132 PropertyInfo[] properties = typeof(PhotoSearchOptions).GetProperties();133 Method flickrMethod = TestData.GetInstance().ReflectionGetMethodInfo("flickr.photos.search");134 // These arguments are covered, but are named slightly differently from Flickr.135 Dictionary<string, string> exceptions = new Dictionary<string, string>();136 exceptions.Add("license", "licenses"); // Licenses137 exceptions.Add("sort", "sortorder"); // SortOrder138 exceptions.Add("bbox", "boundarybox"); // BoundaryBox139 exceptions.Add("lat", "latitude"); // Latitude140 exceptions.Add("lon", "longitude"); // Longitude141 exceptions.Add("media", "mediatype"); // MediaType142 int numMissing = 0;143 foreach (MethodArgument argument in flickrMethod.Arguments)144 {145 if (argument.Name == "api_key") continue;146 bool found = false;147 string arg = argument.Name.Replace("_", "").ToLower();148 if (exceptions.ContainsKey(arg)) arg = exceptions[arg];149 foreach (PropertyInfo info in properties)150 {151 string propName = info.Name.ToLower();152 if (arg == propName)153 {154 found = true;155 break;156 }157 }158 if (!found)159 {160 numMissing++;161 Console.WriteLine("Argument " + argument.Name + " not found.");162 }163 }164 Assert.AreEqual(0, numMissing, "Number of missing arguments should be zero.");165 }166 [Test]167 [Ignore]168 public void ReflectionMethodsCheckWeSupportAndParametersMatch()169 {170 List<string> exceptions = new List<string>();171 exceptions.Add("flickr.photos.getWithGeoData");172 exceptions.Add("flickr.photos.getWithouGeoData");173 exceptions.Add("flickr.photos.search");174 exceptions.Add("flickr.photos.getNotInSet");175 exceptions.Add("flickr.photos.getUntagged");176 Flickr f = TestData.GetInstance();177 MethodCollection methodNames = f.ReflectionGetMethods();178 Assert.IsNotNull(methodNames, "Should not be null");179 Assert.AreNotEqual(0, methodNames.Count, "Should return some method names.");180 Assert.IsNotNull(methodNames[0], "First item should not be null");181 Type type = typeof(Flickr);182 MethodInfo[] methods = type.GetMethods();183 int failCount = 0;184 foreach (string methodName in methodNames)185 {186 bool found = false;187 bool foundTrue = false;188 string trueName = methodName.Replace("flickr.", "").Replace(".", "").ToLower();189 foreach (MethodInfo info in methods)190 {191 if (trueName == info.Name.ToLower())192 {193 found = true;194 break;195 }196 }197 // Check the number of arguments to see if we have a matching method.198 if (found && !exceptions.Contains(methodName))199 {200 Method method = f.ReflectionGetMethodInfo(methodName);201 foreach (MethodInfo info in methods)202 {203 if (method.Arguments.Count - 1 == info.GetParameters().Length)204 {205 foundTrue = true;206 break;207 }208 }209 }210 if (!found)211 {212 failCount++;213 Console.WriteLine("Method '" + methodName + "' not found in FlickrNet.Flickr.");214 }215 if (found && !foundTrue)216 {217 Console.WriteLine("Method '" + methodName + "' found but no matching method with all arguments.");218 }219 }220 Assert.AreEqual(0, failCount, "FailCount should be zero. Currently " + failCount + " unsupported methods found.");221 }222 [Test]223 public void ReflectionGetMethodInfoTest()224 {225 Flickr f = TestData.GetInstance();226 Method method = f.ReflectionGetMethodInfo("flickr.reflection.getMethodInfo");227 Assert.IsNotNull(method, "Method should not be null");228 Assert.AreEqual("flickr.reflection.getMethodInfo", method.Name, "Method name not set correctly");229 Assert.AreEqual(MethodPermission.None, method.RequiredPermissions);230 Assert.AreEqual(2, method.Arguments.Count, "There should be two arguments");231 Assert.AreEqual("api_key", method.Arguments[0].Name, "First argument should be api_key.");232 Assert.IsFalse(method.Arguments[0].IsOptional, "First argument should not be optional.");233 Assert.AreEqual(9, method.Errors.Count, "There should be 8 errors.");234 Assert.AreEqual(1, method.Errors[0].Code, "First error should have code of 1");235 Assert.AreEqual("Method not found", method.Errors[0].Message, "First error should have code of 1");236 Assert.AreEqual("The requested method was not found.", method.Errors[0].Description, "First error should have code of 1");237 }238 [Test]239 public void ReflectionGetMethodInfoFavContextArguments()240 {241 var methodName = "flickr.favorites.getContext";242 var method = TestData.GetInstance().ReflectionGetMethodInfo(methodName);243 Assert.AreEqual(6, method.Arguments.Count);244 Assert.AreEqual("The id of the photo to fetch the context for.", method.Arguments[1].Description);245 Assert.IsNull(method.Arguments[4].Description);246 }247 private void GetExceptionList()248 {249 Dictionary<int, List<string>> errors = new Dictionary<int, List<string>>();250 Flickr.CacheDisabled = true;251 Flickr f = TestData.GetInstance();252 var list = f.ReflectionGetMethods();253 foreach (var methodName in list)254 {255 Console.WriteLine("Method = " + methodName);256 var method = f.ReflectionGetMethodInfo(methodName);257 foreach (var exception in method.Errors)258 {259 if (!errors.ContainsKey(exception.Code))260 {261 errors[exception.Code] = new List<string>();262 }263 var l = errors[exception.Code];264 if (!l.Contains(exception.Message))265 {266 l.Add(exception.Message);267 }268 }269 }270 foreach (var pair in errors)271 {272 Console.WriteLine("Code,Message");273 foreach (string l in pair.Value)274 {275 Console.WriteLine(pair.Key + ",\"" + l + "\"");276 }277 Console.WriteLine();278 }279 }280 }281}...

Full Screen

Full Screen

MetadataTypeInfoAdapterTest.cs

Source:MetadataTypeInfoAdapterTest.cs Github

copy

Full Screen

1using System;2using System.Collections;3using System.Collections.Generic;4using System.Linq;5using JetBrains.DataFlow;6using JetBrains.Metadata.Reader.API;7using JetBrains.Metadata.Reader.Impl;8using JetBrains.Metadata.Utils;9using JetBrains.Util;10using NUnit.Framework;11using Xunit.Abstractions;12using XunitContrib.Runner.ReSharper.UnitTestProvider;13namespace XunitContrib.Runner.ReSharper.Tests.Abstractions14{15 public class MetadataTypeInfoAdapterTest : IDisposable16 {17 private readonly MetadataLoader loader;18 private readonly LifetimeDefinition lifetimeDefinition;19 public MetadataTypeInfoAdapterTest()20 {21 lifetimeDefinition = Lifetimes.Define(EternalLifetime.Instance);22 var lifetime = lifetimeDefinition.Lifetime;23 var gacResolver = GacAssemblyResolver.CreateOnCurrentRuntimeGac(GacAssemblyResolver.GacResolvePreferences.MatchSameOrNewer);24 var resolver = new CombiningAssemblyResolver(gacResolver, new LoadedAssembliesResolver(lifetime, true));25 loader = new MetadataLoader(resolver);26 lifetime.AddDispose(loader);27 }28 public void Dispose()29 {30 lifetimeDefinition.Terminate();31 }32 [Test]33 public void Should_return_containing_assembly()34 {35 var type = GetTypeInfo(GetType());36 Assert.AreEqual(GetType().Assembly.FullName, type.Assembly.Name);37 }38 [Test]39 public void Should_return_base_type_of_object()40 {41 var type = GetTypeInfo(typeof(BaseType));42 Assert.AreEqual(typeof (object).FullName, type.BaseType.Name);43 }44 [Test]45 public void Should_return_base_type_for_derived_class()46 {47 var typeInfo = GetTypeInfo(typeof (DerivedType));48 Assert.AreEqual(typeof (BaseType).FullName, typeInfo.BaseType.Name);49 }50 [Test]51 public void Should_return_list_of_implemented_interfaces()52 {53 var type = GetTypeInfo(typeof (TypeWithInterfaces));54 var interfaceNames = type.Interfaces.Select(t => t.Name);55 var expected = new[]56 {57 typeof (IDisposable).FullName,58 typeof (IEnumerable<string>).FullName,59 typeof (IEnumerable).FullName60 };61 CollectionAssert.AreEquivalent(expected, interfaceNames);62 }63 [Test]64 public void Should_return_empty_list_if_no_interfaces()65 {66 var type = GetTypeInfo(typeof (DerivedType));67 CollectionAssert.IsEmpty(type.Interfaces);68 }69 [Test]70 public void Should_indicate_if_type_is_abstract()71 {72 var type = GetTypeInfo(typeof (BaseType));73 var derivedType = GetTypeInfo(typeof (DerivedType));74 Assert.True(type.IsAbstract);75 Assert.False(derivedType.IsAbstract);76 }77 [Test]78 public void Should_indicate_if_type_is_generic_type()79 {80 var type = GetTypeInfo(typeof(TypeWithInterfaces));81 var genericInstance = new GenericType<string>();82 var genericType = GetTypeInfo(genericInstance.GetType());83 Assert.IsFalse(type.IsGenericType);84 Assert.IsTrue(genericType.IsGenericType);85 }86 [Test]87 public void Should_indicate_if_type_represents_generic_parameter()88 {89 var type = GetTypeInfo(typeof (TypeWithInterfaces));90 var genericParameterType = GetTypeInfo(typeof (IEnumerable<string>)).GetGenericArguments().First();91 var openGenericParameterType = GetTypeInfo(typeof (IEnumerable<>)).GetGenericArguments().First();92 Assert.IsFalse(type.IsGenericParameter);93 Assert.IsFalse(genericParameterType.IsGenericParameter);94 Assert.IsTrue(openGenericParameterType.IsGenericParameter);95 }96 [Test]97 public void Should_return_generic_arguments()98 {99 var type = GetTypeInfo(typeof (IDictionary<string, int>));100 var args = type.GetGenericArguments().ToList();101 Assert.AreEqual(2, args.Count);102 Assert.AreEqual(typeof(string).FullName, args[0].Name);103 Assert.AreEqual(typeof(int).FullName, args[1].Name);104 }105 [Test]106 public void Should_indicate_if_type_is_sealed()107 {108 var type = GetTypeInfo(typeof (BaseType));109 var sealedType = GetTypeInfo(typeof (SealedType));110 Assert.IsFalse(type.IsSealed);111 Assert.IsTrue(sealedType.IsSealed);112 }113 [Test]114 public void Should_indicate_if_type_is_value_type()115 {116 var type = GetTypeInfo(typeof (BaseType));117 var valueType = GetTypeInfo(typeof (MyValueType));118 Assert.IsFalse(type.IsValueType);119 Assert.IsTrue(valueType.IsValueType);120 }121 [Test]122 public void Should_return_type_name()123 {124 var type = GetTypeInfo(typeof (BaseType));125 Assert.AreEqual(typeof(BaseType).FullName, type.Name);126 }127 [Test]128 public void Should_return_type_name_for_generic_type()129 {130 var type = typeof(GenericType<>);131 var typeInfo = GetTypeInfo(type);132 Assert.AreEqual(type.FullName, typeInfo.Name);133 }134 [Test]135 public void Should_return_inherited_attributes()136 {137 var baseType = GetTypeInfo(typeof (BaseType));138 var derivedType = GetTypeInfo(typeof (DerivedType));139 var attributeType = typeof (CustomAttribute);140 var attributeName = attributeType.AssemblyQualifiedName;141 var baseAttributes = baseType.GetCustomAttributes(attributeName);142 var derivedAttributes = derivedType.GetCustomAttributes(attributeName);143 Assert.AreEqual("Foo", baseAttributes.First().GetConstructorArguments().First());144 Assert.AreEqual("Foo", derivedAttributes.First().GetConstructorArguments().First());145 }146 [Test]147 public void Should_return_multiple_attribute_instances()148 {149 var type = GetTypeInfo(typeof (TypeWithInterfaces));150 var attributeType = typeof (CustomAttribute);151 var attributeArgs = type.GetCustomAttributes(attributeType.AssemblyQualifiedName)152 .Select(a => a.GetConstructorArguments().First()).ToList();153 var expectedArgs = new[] { "Foo", "Bar" };154 CollectionAssert.AreEquivalent(expectedArgs, attributeArgs);155 }156 [Test]157 public void Should_return_specific_method()158 {159 var type = GetTypeInfo(typeof (DerivedType));160 var method = type.GetMethod("PublicMethod", false);161 Assert.NotNull(method);162 Assert.AreEqual("PublicMethod", method.Name);163 }164 [Test]165 public void Should_not_return_private_method()166 {167 var type = GetTypeInfo(typeof(DerivedType));168 var method = type.GetMethod("PrivateMethod", false);169 Assert.Null(method);170 }171 [Test]172 public void Should_return_specific_private_method()173 {174 var type = GetTypeInfo(typeof (DerivedType));175 var method = type.GetMethod("PrivateMethod", true);176 Assert.NotNull(method);177 Assert.AreEqual("PrivateMethod", method.Name);178 }179 [Test]180 public void Should_return_public_methods()181 {182 var type = GetTypeInfo(typeof(DerivedType));183 var methodNames = type.GetMethods(false).Select(m => m.Name).ToList();184 Assert.Contains("PublicMethod", methodNames);185 }186 [Test]187 public void Should_return_inherited_methods()188 {189 var type = GetTypeInfo(typeof (DerivedType));190 var methodNames = type.GetMethods(false).Select(m => m.Name).ToList();191 Assert.Contains("MethodOnBaseClass", methodNames);192 }193 [Test]194 public void Should_return_private_methods()195 {196 var type = GetTypeInfo(typeof(DerivedType));197 var methodNames = type.GetMethods(true).Select(m => m.Name).ToList();198 Assert.Contains("PrivateMethod", methodNames);199 }200 [Test]201 public void Should_return_owning_assembly()202 {203 var type = GetTypeInfo(typeof (BaseType));204 Assert.AreEqual(type.Assembly.Name, typeof(BaseType).Assembly.FullName);205 }206 private ITypeInfo GetTypeInfo(Type type)207 {208 var assembly = loader.LoadFrom(FileSystemPath.Parse(type.Assembly.Location),209 JetFunc<AssemblyNameInfo>.True);210 var typeInfo = new MetadataAssemblyInfoAdapter(assembly).GetType(type.FullName);211 Assert.NotNull(typeInfo, "Cannot load type {0}", type.FullName);212 return typeInfo;213 // Ugh. This requires xunit.execution, which is .net 4.5, but if we change214 // this project to be .net 4.5, the ReSharper tests fail...215 //var assembly = Xunit.Sdk.Reflector.Wrap(type.Assembly);216 //var typeInfo = assembly.GetType(type.FullName);217 //Assert.NotNull(typeInfo, "Cannot load type {0}", type.FullName);218 //return typeInfo;219 }220 }221 public struct MyValueType222 {223 }224 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]225 public class CustomAttribute : Attribute226 {227 private readonly string value;228 public CustomAttribute(string value)229 {230 this.value = value;231 }232 }233 [Custom("Foo")]234 public abstract class BaseType235 {236 public void MethodOnBaseClass()237 {238 }239 }240 public class DerivedType : BaseType241 {242 public void PublicMethod()243 {244 }245 private void PrivateMethod()246 {247 }248 }249 [Custom("Foo"), Custom("Bar")]250 public class TypeWithInterfaces : IDisposable, IEnumerable<string>251 {252 public void Dispose()253 {254 throw new NotImplementedException();255 }256 public IEnumerator<string> GetEnumerator()257 {258 throw new NotImplementedException();259 }260 IEnumerator IEnumerable.GetEnumerator()261 {262 return GetEnumerator();263 }264 }265 public class GenericType<T>266 {267 public void NormalMethod(T t)268 {269 }270 public T GenericMethod()271 {272 return default(T);273 }274 }275 public sealed class SealedType276 {277 }278}...

Full Screen

Full Screen

Specifier.cs

Source:Specifier.cs Github

copy

Full Screen

...14 .OfType<ApiDescriptionAttribute>()15 .FirstOrDefault()16 ?.Description;17 }18 public string[] GetApiMethodNames()19 {20 var methodNames = new List<string>();21 foreach (var apiMethod in typeof(T)22 .GetMethods()23 .Where(info => info.GetCustomAttributes(false)24 .OfType<ApiMethodAttribute>().FirstOrDefault() != null))25 {26 methodNames.Add(apiMethod.Name);27 }28 return methodNames.ToArray();29 }30 public string GetApiMethodDescription(string methodName)31 {32 return typeof(T)...

Full Screen

Full Screen

BotStringsTests.cs

Source:BotStringsTests.cs Github

copy

Full Screen

...35 }36 }37 Assert.IsTrue(isSuccess);38 }39 private static string[] GetCommandMethodNames()40 => typeof(NadekoBot.NadekoBot).Assembly41 .GetExportedTypes()42 .Where(type => type.IsClass && !type.IsAbstract)43 .Where(type => typeof(NadekoModule).IsAssignableFrom(type) // if its a top level module44 || !(type.GetCustomAttribute<GroupAttribute>(true) is null)) // or a submodule45 .SelectMany(x => x.GetMethods()46 .Where(mi => mi.CustomAttributes47 .Any(ca => ca.AttributeType == typeof(NadekoCommandAttribute))))48 .Select(x => x.Name.ToLowerInvariant())49 .ToArray();50 [Test]51 public void AllCommandMethodsHaveNames()52 {53 var allAliases = CommandNameLoadHelper.LoadCommandNames(54 aliasesPath);55 var methodNames = GetCommandMethodNames();56 var isSuccess = true;57 foreach (var methodName in methodNames)58 {59 if (!allAliases.TryGetValue(methodName, out var _))60 {61 TestContext.Error.WriteLine($"{methodName} is missing an alias.");62 isSuccess = false;63 }64 }65 66 Assert.IsTrue(isSuccess);67 }68 69 [Test]70 public void NoObsoleteAliases()71 {72 var allAliases = CommandNameLoadHelper.LoadCommandNames(aliasesPath);73 var methodNames = GetCommandMethodNames()74 .ToHashSet();75 var isSuccess = true;76 foreach (var item in allAliases)77 {78 var methodName = item.Key;79 if (!methodNames.Contains(methodName))80 {81 TestContext.WriteLine($"'{methodName}' from aliases.yml doesn't have a matching command method.");82 isSuccess = false;83 }84 }85 86 Assert.IsTrue(isSuccess);87 }...

Full Screen

Full Screen

RandomAttributeTests.cs

Source:RandomAttributeTests.cs Github

copy

Full Screen

...9namespace NUnit.Framework.Attributes10{11 public class RandomAttributeTests12 {13 [TestCaseSource(typeof(MethodNames))]14 public void CheckRandomResult(string methodName)15 {16 var result = TestBuilder.RunParameterizedMethodSuite(typeof(RandomAttributeFixture), methodName);17 Assert.That(result.Children.Count(), Is.EqualTo(RandomAttributeFixture.COUNT));18 if (result.ResultState != ResultState.Success)19 {20 var msg = new StringBuilder();21 msg.AppendFormat("Unexpected Result: {0}\n", result.ResultState);22 if (result.ResultState.Site == FailureSite.Child)23 foreach (var child in result.Children)24 {25 msg.AppendFormat(" {0}: {1}\n", child.Name, child.ResultState);26 msg.AppendFormat("{0}\n", child.Message);27 }28 Assert.Fail(msg.ToString());29 }30 }31 class MethodNames : IEnumerable32 {33 public IEnumerator GetEnumerator()34 {35 foreach (var method in typeof(RandomAttributeFixture).GetMethods())36 if (method.HasAttribute<TestAttribute>(inherit: false))37 yield return new TestCaseData(method.Name).SetName(method.Name);38 }39 }40 }41}...

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework;2using NUnit.Framework.Attributes;3using NUnit.Framework.Interfaces;4using NUnit.Framework.Internal;5using NUnit.Framework.Internal.Commands;6using NUnit.Framework.Internal.Execution;7using NUnit.Framework.Internal.Filters;8using NUnit.Framework.Internal.Results;9using NUnit.Framework.Internal.Runnable;10using NUnit.Framework.Internal.TestExecution;11using NUnit.Framework.Internal.TestParameters;12using NUnit.Framework.Internal.TestProperties;13using NUnit.Framework.Internal.TestResult;14using NUnit.Framework.Internal.TestRunners;15using NUnit.Framework.Internal.TestSettings;16using NUnit.Framework.Internal.TestUtilities;17using NUnit.Framework.Internal.WorkItems;18using NUnit.Framework.Internal.WorkItems.Commands;19using NUnit.Framework.Internal.WorkItems.Filters;20using NUnit.Framework.Internal.WorkItems.Results;21using NUnit.Framework.Internal.WorkItems.Runnable;22using NUnit.Framework.Internal.WorkItems.TestExecution;23using NUnit.Framework.Internal.WorkItems.TestParameters;24using NUnit.Framework.Internal.WorkItems.TestProperties;25using NUnit.Framework.Internal.WorkItems.TestResult;26using NUnit.Framework.Internal.WorkItems.TestRunners;27using NUnit.Framework.Internal.WorkItems.TestSettings;28using NUnit.Framework.Internal.WorkItems.TestUtilities;29using NUnit.Framework.Internal.WorkItems.WorkItems;30using NUnit.Framework.Internal.WorkItems.WorkItems.Commands;31using NUnit.Framework.Internal.WorkItems.WorkItems.Filters;32using NUnit.Framework.Internal.WorkItems.WorkItems.Results;33using NUnit.Framework.Internal.WorkItems.WorkItems.Runnable;34using NUnit.Framework.Internal.WorkItems.WorkItems.TestExecution;35using NUnit.Framework.Internal.WorkItems.WorkItems.TestParameters;36using NUnit.Framework.Internal.WorkItems.WorkItems.TestProperties;37using NUnit.Framework.Internal.WorkItems.WorkItems.TestResult;38using NUnit.Framework.Internal.WorkItems.WorkItems.TestRunners;39using NUnit.Framework.Internal.WorkItems.WorkItems.TestSettings;40using NUnit.Framework.Internal.WorkItems.WorkItems.TestUtilities;41using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems;42using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.Commands;43using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.Filters;44using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.Results;45using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.Runnable;46using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestExecution;47using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestParameters;48using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestProperties;49using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestResult;50using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestRunners;51using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestSettings;52using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.TestUtilities;53using NUnit.Framework.Internal.WorkItems.WorkItems.WorkItems.WorkItems;

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework;2using NUnit.Framework.Attributes;3{4 {5 public void TestMethod1()6 {7 Assert.AreEqual(1, 1);8 }9 }10}11using NUnit.Framework;12{13 {14 public void TestMethod1()15 {16 Assert.AreEqual(1, 1);17 }18 }19}

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2using NUnit.Framework;3{4 public void TestMethod()5 {6 int a = 10;7 int b = 20;8 int c = 30;9 int d = 40;10 int e = 50;11 int f = 60;12 int g = 70;13 int h = 80;14 int i = 90;15 int j = 100;16 int k = 110;17 int l = 120;18 int m = 130;19 int n = 140;20 int o = 150;21 int p = 160;22 int q = 170;

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2using NUnit.Framework;3using NUnit.Framework.Interfaces;4using NUnit.Framework.Internal;5using System;6using System.Reflection;7using System.Collections.Generic;8using System.Linq;9using System.Text;10using System.Threading.Tasks;11{12 {13 public static string GetMethodName(string methodName)14 {15 return methodName;16 }17 }18}19using NUnit.Framework.Attributes;20using NUnit.Framework;21using NUnit.Framework.Interfaces;22using NUnit.Framework.Internal;23using System;24using System.Reflection;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29{30 {31 public static string GetMethodName(string methodName)32 {33 return methodName;34 }35 }36}37using NUnit.Framework.Attributes;38using NUnit.Framework;39using NUnit.Framework.Interfaces;40using NUnit.Framework.Internal;41using System;42using System.Reflection;43using System.Collections.Generic;44using System.Linq;45using System.Text;46using System.Threading.Tasks;47{48 {49 public static string GetMethodName(string methodName)50 {51 return methodName;52 }53 }54}55using NUnit.Framework.Attributes;56using NUnit.Framework;57using NUnit.Framework.Interfaces;58using NUnit.Framework.Internal;59using System;60using System.Reflection;61using System.Collections.Generic;62using System.Linq;63using System.Text;64using System.Threading.Tasks;65{66 {67 public static string GetMethodName(string methodName)68 {69 return methodName;70 }71 }72}73using NUnit.Framework.Attributes;74using NUnit.Framework;75using NUnit.Framework.Interfaces;76using NUnit.Framework.Internal;77using System;78using System.Reflection;79using System.Collections.Generic;80using System.Linq;81using System.Text;82using System.Threading.Tasks;83{84 {85 public static string GetMethodName(string methodName)86 {87 return methodName;88 }89 }90}91using NUnit.Framework.Attributes;

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2using NUnit.Framework;3{4 {5 public void TestMethod()6 {7 Assert.IsTrue(true);8 }9 }10}11using NUnit.Framework;12using System;13using System.Reflection;14{15 {16 static void Main(string[] args)17 {18 Type type = typeof(TestClass);19 MethodInfo method = type.GetMethod("TestMethod");20 var attributes = method.GetCustomAttributes();21 foreach (var attribute in attributes)22 {23 if (attribute is TestMethodAttribute)24 {25 Console.WriteLine("Test method");26 }27 }28 }29 }30}

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2using System;3{4 public static void Main()5 {6 MethodNames methodNames = new MethodNames();7 Console.WriteLine(methodNames.MethodName);8 }9}10nameof(VariableName)11nameof(VariableName)12nameof(VariableName)13nameof(VariableName)14using System;15{16 public static void Main()17 {18 string name = "MethodNames.MethodName";19 Console.WriteLine(name);20 }21}22new StackFrame().GetMethod().Name23new StackFrame().GetMethod().Name24new StackFrame().GetMethod().Name25new StackFrame().GetMethod().Name26using System;27using System.Diagnostics;28{29 public static void Main()30 {31 string name = new StackFrame().GetMethod().Name;32 Console.WriteLine(name);33 }34}

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2{3 {4 public void TestMethod()5 {6 var methodNames = new MethodNames();7 methodNames.TestMethod();8 }9 }10}

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2{3 static void Main(string[] args)4 {5 MethodNames mn = new MethodNames();6 mn.Test1();7 mn.Test2();8 mn.Test3();9 Console.ReadKey();10 }11}

Full Screen

Full Screen

MethodNames

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework.Attributes;2{3 public void TestMethod()4 {5 }6}7using NUnit.Framework.Attributes;8{9 public void TestMethod()10 {11 }12}

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.

Run Nunit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful