How to use ClassB class of ExampleTest package

Best Nunit code snippet using ExampleTest.ClassB

EqualConstraintTests.cs

Source:EqualConstraintTests.cs Github

copy

Full Screen

1// ***********************************************************************2// Copyright (c) 2007-2013 Charlie Poole3//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;25using System.Collections.Generic;26using System.Globalization;27using NUnit.Framework.Internal;28using NUnit.TestUtilities.Comparers;29namespace NUnit.Framework.Constraints30{31 [TestFixture]32 public class EqualConstraintTests : ConstraintTestBase33 {34 [SetUp]35 public void SetUp()36 {37 theConstraint = new EqualConstraint(4);38 expectedDescription = "4";39 stringRepresentation = "<equal 4>";40 }41 static object[] SuccessData = new object[] {4, 4.0f, 4.0d, 4.0000m};42 static object[] FailureData = new object[]43 {44 new TestCaseData(5, "5"),45 new TestCaseData(null, "null"),46 new TestCaseData("Hello", "\"Hello\""),47 new TestCaseData(double.NaN, double.NaN.ToString()),48 new TestCaseData(double.PositiveInfinity, double.PositiveInfinity.ToString())49 };50 #region DateTimeEquality51 public class DateTimeEquality52 {53 [Test]54 public void CanMatchDates()55 {56 DateTime expected = new DateTime(2007, 4, 1);57 DateTime actual = new DateTime(2007, 4, 1);58 Assert.That(actual, new EqualConstraint(expected));59 }60 [Test]61 public void CanMatchDatesWithinTimeSpan()62 {63 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);64 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);65 TimeSpan tolerance = TimeSpan.FromMinutes(5.0);66 Assert.That(actual, new EqualConstraint(expected).Within(tolerance));67 }68 [Test]69 public void CanMatchDatesWithinDays()70 {71 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);72 DateTime actual = new DateTime(2007, 4, 4, 13, 0, 0);73 Assert.That(actual, new EqualConstraint(expected).Within(5).Days);74 }75 [Test]76 public void CanMatchDatesWithinHours()77 {78 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);79 DateTime actual = new DateTime(2007, 4, 1, 16, 0, 0);80 Assert.That(actual, new EqualConstraint(expected).Within(5).Hours);81 }82 [Test]83 public void CanMatchUsingIsEqualToWithinTimeSpan()84 {85 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);86 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);87 Assert.That(actual, Is.EqualTo(expected).Within(TimeSpan.FromMinutes(2)));88 }89 [Test]90 public void CanMatchDatesWithinMinutes()91 {92 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);93 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);94 Assert.That(actual, new EqualConstraint(expected).Within(5).Minutes);95 }96 [Test]97 public void CanMatchTimeSpanWithinMinutes()98 {99 TimeSpan expected = new TimeSpan(10, 0, 0);100 TimeSpan actual = new TimeSpan(10, 2, 30);101 Assert.That(actual, new EqualConstraint(expected).Within(5).Minutes);102 }103 [Test]104 public void CanMatchDatesWithinSeconds()105 {106 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);107 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);108 Assert.That(actual, new EqualConstraint(expected).Within(300).Seconds);109 }110 [Test]111 public void CanMatchDatesWithinMilliseconds()112 {113 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);114 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);115 Assert.That(actual, new EqualConstraint(expected).Within(300000).Milliseconds);116 }117 [Test]118 public void CanMatchDatesWithinTicks()119 {120 DateTime expected = new DateTime(2007, 4, 1, 13, 0, 0);121 DateTime actual = new DateTime(2007, 4, 1, 13, 1, 0);122 Assert.That(actual, new EqualConstraint(expected).Within(TimeSpan.TicksPerMinute*5).Ticks);123 }124 [Test]125 public void ErrorIfDaysPrecedesWithin()126 {127 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Days.Within(5)));128 }129 [Test]130 public void ErrorIfHoursPrecedesWithin()131 {132 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Hours.Within(5)));133 }134 [Test]135 public void ErrorIfMinutesPrecedesWithin()136 {137 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Minutes.Within(5)));138 }139 [Test]140 public void ErrorIfSecondsPrecedesWithin()141 {142 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Seconds.Within(5)));143 }144 [Test]145 public void ErrorIfMillisecondsPrecedesWithin()146 {147 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Milliseconds.Within(5)));148 }149 [Test]150 public void ErrorIfTicksPrecedesWithin()151 {152 Assert.Throws<InvalidOperationException>(() => Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now).Ticks.Within(5)));153 }154 }155 #endregion156 #region DateTimeOffsetEquality157#if !PORTABLE158 public class DateTimeOffsetShouldBeSame159 {160 161 [Datapoints]162 public static readonly DateTimeOffset[] sameDateTimeOffsets = 163 {164 new DateTimeOffset(new DateTime(2014, 1, 30, 12, 34, 56), new TimeSpan(6, 15, 0)), 165 new DateTimeOffset(new DateTime(2014, 1, 30, 9, 19, 56), new TimeSpan(3, 0, 0)),166 new DateTimeOffset(new DateTime(2014, 1, 30, 9, 19, 56), new TimeSpan(3, 1, 0)),167 new DateTimeOffset(new DateTime(2014, 1, 30, 9, 19, 55), new TimeSpan(3, 0, 0)),168 new DateTimeOffset(new DateTime(2014, 1, 30, 9, 19, 55), new TimeSpan(3, 50, 0))169 };170 [Theory]171 public void PositiveEqualityTest(DateTimeOffset value1, DateTimeOffset value2)172 {173 Assume.That(value1 == value2);174 Assert.That(value1, Is.EqualTo(value2));175 }176 [Theory]177 public void NegativeEqualityTest(DateTimeOffset value1, DateTimeOffset value2)178 {179 Assume.That(value1 != value2);180 Assert.That(value1, Is.Not.EqualTo(value2));181 }182 [Theory]183 public void PositiveEqualityTestWithTolerance(DateTimeOffset value1, DateTimeOffset value2)184 {185 Assume.That((value1 - value2).Duration() <= new TimeSpan(0, 1, 0));186 Assert.That(value1, Is.EqualTo(value2).Within(1).Minutes);187 }188 [Theory]189 public void NegativeEqualityTestWithTolerance(DateTimeOffset value1, DateTimeOffset value2)190 {191 Assume.That((value1 - value2).Duration() > new TimeSpan(0, 1, 0));192 193 Assert.That(value1, Is.Not.EqualTo(value2).Within(1).Minutes);194 }195 [Theory]196 public void NegativeEqualityTestWithToleranceAndWithSameOffset(DateTimeOffset value1, DateTimeOffset value2)197 {198 Assume.That((value1 - value2).Duration() > new TimeSpan(0, 1, 0));199 200 Assert.That(value1, Is.Not.EqualTo(value2).Within(1).Minutes.WithSameOffset);201 }202 [Theory]203 public void PositiveEqualityTestWithToleranceAndWithSameOffset(DateTimeOffset value1, DateTimeOffset value2)204 {205 Assume.That((value1 - value2).Duration() <= new TimeSpan(0, 1, 0));206 Assume.That(value1.Offset == value2.Offset);207 Assert.That(value1, Is.EqualTo(value2).Within(1).Minutes.WithSameOffset);208 }209 [Theory]210 public void NegativeEqualityTestWithinToleranceAndWithSameOffset(DateTimeOffset value1, DateTimeOffset value2)211 {212 Assume.That((value1 - value2).Duration() <= new TimeSpan(0, 1, 0));213 Assume.That(value1.Offset != value2.Offset);214 Assert.That(value1, Is.Not.EqualTo(value2).Within(1).Minutes.WithSameOffset);215 }216 }217 public class DateTimeOffSetEquality218 {219 [Test]220 public void CanMatchDates()221 {222 var expected = new DateTimeOffset(new DateTime(2007, 4, 1));223 var actual = new DateTimeOffset(new DateTime(2007, 4, 1));224 Assert.That(actual, new EqualConstraint(expected));225 }226 [Test]227 public void CanMatchDatesWithinTimeSpan()228 {229 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));230 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));231 var tolerance = TimeSpan.FromMinutes(5.0);232 Assert.That(actual, new EqualConstraint(expected).Within(tolerance));233 }234 [Test]235 public void CanMatchDatesWithinDays()236 {237 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));238 var actual = new DateTimeOffset(new DateTime(2007, 4, 4, 13, 0, 0));239 Assert.That(actual, new EqualConstraint(expected).Within(5).Days);240 }241 [Test]242 public void CanMatchUsingIsEqualToWithinTimeSpan()243 {244 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));245 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));246 Assert.That(actual, Is.EqualTo(expected).Within(TimeSpan.FromMinutes(2)));247 }248 [Test]249 public void CanMatchDatesWithinMinutes()250 {251 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));252 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));253 Assert.That(actual, new EqualConstraint(expected).Within(5).Minutes);254 }255 [Test]256 public void CanMatchDatesWithinSeconds()257 {258 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));259 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));260 Assert.That(actual, new EqualConstraint(expected).Within(300).Seconds);261 }262 [Test]263 public void CanMatchDatesWithinMilliseconds()264 {265 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));266 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));267 Assert.That(actual, new EqualConstraint(expected).Within(300000).Milliseconds);268 }269 [Test]270 public void CanMatchDatesWithinTicks()271 {272 var expected = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 0, 0));273 var actual = new DateTimeOffset(new DateTime(2007, 4, 1, 13, 1, 0));274 Assert.That(actual, new EqualConstraint(expected).Within(TimeSpan.TicksPerMinute*5).Ticks);275 }276 [Test]277 public void DTimeOffsetCanMatchDatesWithinHours()278 {279 var a = DateTimeOffset.Parse("2012-01-01T12:00Z");280 var b = DateTimeOffset.Parse("2012-01-01T12:01Z");281 Assert.That(a, Is.EqualTo(b).Within(TimeSpan.FromMinutes(2)));282 }283 }284#endif285 #endregion286 #region DictionaryEquality287 public class DictionaryEquality288 {289 [Test]290 public void CanMatchDictionaries_SameOrder()291 {292 Assert.AreEqual(new Dictionary<int, int> {{0, 0}, {1, 1}, {2, 2}},293 new Dictionary<int, int> {{0, 0}, {1, 1}, {2, 2}});294 }295 [Test]296 public void CanMatchDictionaries_Failure()297 {298 Assert.Throws<AssertionException>(299 () => Assert.AreEqual(new Dictionary<int, int> {{0, 0}, {1, 1}, {2, 2}},300 new Dictionary<int, int> {{0, 0}, {1, 5}, {2, 2}}));301 }302 [Test]303 public void CanMatchDictionaries_DifferentOrder()304 {305 Assert.AreEqual(new Dictionary<int, int> {{0, 0}, {1, 1}, {2, 2}},306 new Dictionary<int, int> {{0, 0}, {2, 2}, {1, 1}});307 }308#if !PORTABLE && !NETSTANDARD1_6309 [Test]310 public void CanMatchHashtables_SameOrder()311 {312 Assert.AreEqual(new Hashtable {{0, 0}, {1, 1}, {2, 2}},313 new Hashtable {{0, 0}, {1, 1}, {2, 2}});314 }315 [Test]316 public void CanMatchHashtables_Failure()317 {318 Assert.Throws<AssertionException>(319 () => Assert.AreEqual(new Hashtable {{0, 0}, {1, 1}, {2, 2}},320 new Hashtable {{0, 0}, {1, 5}, {2, 2}}));321 }322 [Test]323 public void CanMatchHashtables_DifferentOrder()324 {325 Assert.AreEqual(new Hashtable {{0, 0}, {1, 1}, {2, 2}},326 new Hashtable {{0, 0}, {2, 2}, {1, 1}});327 }328 [Test]329 public void CanMatchHashtableWithDictionary()330 {331 Assert.AreEqual(new Hashtable {{0, 0}, {1, 1}, {2, 2}},332 new Dictionary<int, int> {{0, 0}, {2, 2}, {1, 1}});333 }334#endif335 }336 #endregion337 #region FloatingPointEquality338 public class FloatingPointEquality339 {340 [TestCase(double.NaN)]341 [TestCase(double.PositiveInfinity)]342 [TestCase(double.NegativeInfinity)]343 [TestCase(float.NaN)]344 [TestCase(float.PositiveInfinity)]345 [TestCase(float.NegativeInfinity)]346 public void CanMatchSpecialFloatingPointValues(object value)347 {348 Assert.That(value, new EqualConstraint(value));349 }350 [TestCase(20000000000000004.0)]351 [TestCase(19999999999999996.0)]352 public void CanMatchDoublesWithUlpTolerance(object value)353 {354 Assert.That(value, new EqualConstraint(20000000000000000.0).Within(1).Ulps);355 }356 [TestCase(20000000000000008.0)]357 [TestCase(19999999999999992.0)]358 public void FailsOnDoublesOutsideOfUlpTolerance(object value)359 {360 var ex = Assert.Throws<AssertionException>(() => Assert.That(value, new EqualConstraint(20000000000000000.0).Within(1).Ulps));361 Assert.That(ex.Message, Does.Contain("+/- 1 Ulps"));362 }363 [TestCase(19999998.0f)]364 [TestCase(20000002.0f)]365 public void CanMatchSinglesWithUlpTolerance(object value)366 {367 Assert.That(value, new EqualConstraint(20000000.0f).Within(1).Ulps);368 }369 [TestCase(19999996.0f)]370 [TestCase(20000004.0f)]371 public void FailsOnSinglesOutsideOfUlpTolerance(object value)372 {373 var ex = Assert.Throws<AssertionException>(() => Assert.That(value, new EqualConstraint(20000000.0f).Within(1).Ulps));374 Assert.That(ex.Message, Does.Contain("+/- 1 Ulps"));375 }376 [TestCase(9500.0)]377 [TestCase(10000.0)]378 [TestCase(10500.0)]379 public void CanMatchDoublesWithRelativeTolerance(object value)380 {381 Assert.That(value, new EqualConstraint(10000.0).Within(10.0).Percent);382 }383 [TestCase(8500.0)]384 [TestCase(11500.0)]385 public void FailsOnDoublesOutsideOfRelativeTolerance(object value)386 {387 var ex = Assert.Throws<AssertionException>(() => Assert.That(value, new EqualConstraint(10000.0).Within(10.0).Percent));388 Assert.That(ex.Message, Does.Contain("+/- 10.0d Percent"));389 }390 [TestCase(9500.0f)]391 [TestCase(10000.0f)]392 [TestCase(10500.0f)]393 public void CanMatchSinglesWithRelativeTolerance(object value)394 {395 Assert.That(value, new EqualConstraint(10000.0f).Within(10.0f).Percent);396 }397 [TestCase(8500.0f)]398 [TestCase(11500.0f)]399 public void FailsOnSinglesOutsideOfRelativeTolerance(object value)400 {401 var ex = Assert.Throws<AssertionException>(() => Assert.That(value, new EqualConstraint(10000.0f).Within(10.0f).Percent));402 Assert.That(ex.Message, Does.Contain("+/- 10.0f Percent"));403 }404 /// <summary>Applies both the Percent and Ulps modifiers to cause an exception</summary>405 [Test]406 public void ErrorWithPercentAndUlpsToleranceModes()407 {408 Assert.Throws<InvalidOperationException>(() =>409 {410 var shouldFail = new EqualConstraint(100.0f).Within(10.0f).Percent.Ulps;411 });412 }413 /// <summary>Applies both the Ulps and Percent modifiers to cause an exception</summary>414 [Test]415 public void ErrorWithUlpsAndPercentToleranceModes()416 {417 Assert.Throws<InvalidOperationException>(() =>418 {419 EqualConstraint shouldFail = new EqualConstraint(100.0f).Within(10.0f).Ulps.Percent;420 });421 }422 [Test]423 public void ErrorIfPercentPrecedesWithin()424 {425 Assert.Throws<InvalidOperationException>(() => Assert.That(1010, Is.EqualTo(1000).Percent.Within(5)));426 }427 [Test]428 public void ErrorIfUlpsPrecedesWithin()429 {430 Assert.Throws<InvalidOperationException>(() => Assert.That(1010.0, Is.EqualTo(1000.0).Ulps.Within(5)));431 }432 [TestCase(1000, 1010)]433 [TestCase(1000U, 1010U)]434 [TestCase(1000L, 1010L)]435 [TestCase(1000UL, 1010UL)]436 public void ErrorIfUlpsIsUsedOnIntegralType(object x, object y)437 {438 Assert.Throws<InvalidOperationException>(() => Assert.That(y, Is.EqualTo(x).Within(2).Ulps));439 }440 [Test]441 public void ErrorIfUlpsIsUsedOnDecimal()442 {443 Assert.Throws<InvalidOperationException>(() => Assert.That(100m, Is.EqualTo(100m).Within(2).Ulps));444 }445 }446 #endregion447 #region UsingModifier448 public class UsingModifier449 {450 [Test]451 public void UsesProvidedIComparer()452 {453 var comparer = new ObjectComparer();454 Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));455 Assert.That(comparer.WasCalled, "Comparer was not called");456 }457#if !PORTABLE458 [Test]459 public void CanCompareUncomparableTypes()460 {461 Assert.That(2 + 2, Is.Not.EqualTo("4"));462 var comparer = new ConvertibleComparer();463 Assert.That(2 + 2, Is.EqualTo("4").Using(comparer));464 }465#endif466 [Test]467 public void UsesProvidedEqualityComparer()468 {469 var comparer = new ObjectEqualityComparer();470 Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));471 Assert.That(comparer.Called, "Comparer was not called");472 }473 [Test]474 public void UsesProvidedGenericEqualityComparer()475 {476 var comparer = new GenericEqualityComparer<int>();477 Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));478 Assert.That(comparer.WasCalled, "Comparer was not called");479 }480 [Test]481 public void UsesProvidedGenericComparer()482 {483 var comparer = new GenericComparer<int>();484 Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));485 Assert.That(comparer.WasCalled, "Comparer was not called");486 }487 [Test]488 public void UsesProvidedGenericComparison()489 {490 var comparer = new GenericComparison<int>();491 Assert.That(2 + 2, Is.EqualTo(4).Using(comparer.Delegate));492 Assert.That(comparer.WasCalled, "Comparer was not called");493 }494 [Test]495 public void UsesProvidedLambda_IntArgs()496 {497 Assert.That(2 + 2, Is.EqualTo(4).Using<int>((x, y) => x.CompareTo(y)));498 }499 [Test]500 public void UsesProvidedLambda_StringArgs()501 {502 Assert.That("hello", Is.EqualTo("HELLO").Using<string>((x, y) => StringUtil.Compare(x, y, true)));503 }504 [Test]505 public void UsesProvidedListComparer()506 {507 var list1 = new List<int>() {2, 3};508 var list2 = new List<int>() {3, 4};509 var list11 = new List<List<int>>() {list1};510 var list22 = new List<List<int>>() {list2};511 var comparer = new IntListEqualComparer();512 Assert.That(list11, new CollectionEquivalentConstraint(list22).Using(comparer));513 }514 public class IntListEqualComparer : IEqualityComparer<List<int>>515 {516 public bool Equals(List<int> x, List<int> y)517 {518 return x.Count == y.Count;519 }520 public int GetHashCode(List<int> obj)521 {522 return obj.Count.GetHashCode();523 }524 }525 [Test]526 public void UsesProvidedArrayComparer()527 {528 var array1 = new int[] {2, 3};529 var array2 = new int[] {3, 4};530 var list11 = new List<int[]>() {array1};531 var list22 = new List<int[]>() {array2};532 var comparer = new IntArrayEqualComparer();533 Assert.That(list11, new CollectionEquivalentConstraint(list22).Using(comparer));534 }535 public class IntArrayEqualComparer : IEqualityComparer<int[]>536 {537 public bool Equals(int[] x, int[] y)538 {539 return x.Length == y.Length;540 }541 public int GetHashCode(int[] obj)542 {543 return obj.Length.GetHashCode();544 }545 }546 }547 #endregion548 #region TypeEqualityMessages549 private readonly string NL = Environment.NewLine;550 private static IEnumerable DifferentTypeSameValueTestData551 {552 get553 {554 var ptr = new System.IntPtr(0);555 var ExampleTestA = new ExampleTest.classA(0);556 var ExampleTestB = new ExampleTest.classB(0);557 var clipTestA = new ExampleTest.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Clip.ReallyLongClassNameShouldBeHere();558 var clipTestB = new ExampleTest.Clip.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Clip.ReallyLongClassNameShouldBeHere();559 yield return new object[] { 0, ptr };560 yield return new object[] { ExampleTestA, ExampleTestB };561 yield return new object[] { clipTestA, clipTestB };562 }563 }564 [Test]565 public void SameValueDifferentTypeExactMessageMatch()566 {567 var ex = Assert.Throws<AssertionException>(() => Assert.AreEqual(0, new System.IntPtr(0)));568 Assert.AreEqual(ex.Message, " Expected: 0 (Int32)"+ NL + " But was: 0 (IntPtr)"+ NL);569 }570 [Test]571 public void SameValueAndTypeButDifferentReferenceShowNotShowTypeDifference()572 {573 var ex = Assert.Throws<AssertionException>(() => Assert.AreEqual(Is.Zero, Is.Zero));574 Assert.AreEqual(ex.Message, " Expected: <<equal 0>>"+ NL + " But was: <<equal 0>>"+ NL);575 }576 [Test, TestCaseSource("DifferentTypeSameValueTestData")]577 public void SameValueDifferentTypeRegexMatch(object expected, object actual)578 {579 var ex = Assert.Throws<AssertionException>(() => Assert.AreEqual(expected, actual));580 Assert.That(ex.Message, Does.Match(@"\s*Expected\s*:\s*.*\s*\(.+\)\r?\n\s*But\s*was\s*:\s*.*\s*\(.+\)"));581 }582 }583 namespace ExampleTest.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Clip {584 class ReallyLongClassNameShouldBeHere {585 public override bool Equals(object obj)586 {587 if (obj == null || GetType() != obj.GetType())588 {589 return false;590 }591 return obj.ToString() == this.ToString();592 }593 public override int GetHashCode()594 {595 return "a".GetHashCode();596 }597 public override string ToString()598 {599 return "a";600 }601 }602 }603 namespace ExampleTest.Clip.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Outer.Middle.Inner.Clip604 {605 class ReallyLongClassNameShouldBeHere {606 public override bool Equals(object obj)607 {608 if (obj == null || GetType() != obj.GetType())609 {610 return false;611 }612 return obj.ToString()==this.ToString();613 }614 public override int GetHashCode()615 {616 return "a".GetHashCode();617 }618 public override string ToString()619 {620 return "a";621 }622 }623 }624 namespace ExampleTest {625 class baseTest {626 readonly int _value;627 public baseTest()628 {629 _value = 0;630 }631 public baseTest(int value) {632 _value = value;633 }634 public override bool Equals(object obj)635 {636 if (obj == null || GetType() != obj.GetType())637 {638 return false;639 }640 return _value.Equals(((baseTest)obj)._value); 641 }642 public override string ToString()643 {644 return _value.ToString();645 }646 public override int GetHashCode()647 {648 return _value.GetHashCode();649 }650 }651 class classA : baseTest {652 public classA(int x) : base(x) { }653 }654 class classB : baseTest655 {656 public classB(int x) : base(x) { }657 }658 }659 #endregion660#if !PORTABLE661 /// <summary>662 /// ConvertibleComparer is used in testing to ensure that objects663 /// of different types can be compared when appropriate.664 /// </summary>665 /// <remark>Introduced when testing issue 1897.666 /// https://github.com/nunit/nunit/issues/1897667 /// </remark>668 public class ConvertibleComparer : IComparer<IConvertible>669 {670 public int Compare(IConvertible x, IConvertible y)671 {672 var str1 = Convert.ToString(x, CultureInfo.InvariantCulture);673 var str2 = Convert.ToString(y, CultureInfo.InvariantCulture);674 return string.Compare(str1, str2, StringComparison.Ordinal);675 }676 }677#endif678}...

Full Screen

Full Screen

ExampleTest.cs

Source:ExampleTest.cs Github

copy

Full Screen

...29 public void ResolvingNamedParameters()30 {31 var builder = new ContainerBuilder();32 builder.Register<ParameterClassA>().WithNamedParameter("test", "A").As<ParameterClassA>();33 builder.Register<ParameterClassB>().WithNamedParameter("test", 2).As<ParameterClassB>();34 var cnt = builder.Build();35 var bInst = cnt.Resolve<ParameterClassB>();36 Assert.AreEqual(bInst.Test, 2);37 Assert.AreEqual(bInst.ClassA.Test, "A");38 }39 [TestMethod]40 public void ResolvingEvalutedParameter()41 {42 var builder = new ContainerBuilder();43 builder.Register<ClassThatLogs>()44 .WithEvalutedParamter("logger", requestingType => new SampleLogger(requestingType));45 var instance = builder.Build().BeginLifetimeScope().Resolve<ClassThatLogs>();46 Assert.AreEqual(typeof(ClassThatLogs), instance.GetLoggedType);47 }48 /// <summary>49 /// The registering without "as".50 /// </summary>51 [TestMethod]52 public void RegisteringWithoutAs()53 {54 var builder = new ContainerBuilder();55 builder.Register<ClassA>();56 var resolver = builder.Build();57 var resolvedInstance = resolver.Resolve<ClassA>();58 Assert.AreEqual(typeof(ClassA), resolvedInstance.GetType());59 }60 /// <summary>61 /// Registering the subclass.62 /// </summary>63 [TestMethod]64 public void RegisteringSubclass()65 {66 var builder = new ContainerBuilder();67 builder.Register<ClassB>().As<ClassA>();68 var resolver = builder.Build();69 var resolvedInstance = resolver.Resolve<ClassA>();70 Assert.AreEqual(typeof(ClassB), resolvedInstance.GetType());71 }72 [TestMethod]73 [ExpectedException(typeof(InvalidOperationException))]74 public void DoulbeRegistration()75 {76 var bld = new ContainerBuilder();77 bld.Register<ClassB>().As<ClassA>();78 bld.Register<ClassB>().As<ClassA>();79 bld.Build();80 }81 /// <summary>82 /// Registering the interface.83 /// </summary>84 [TestMethod]85 public void RegisteringInterface()86 {87 var builder = new ContainerBuilder();88 builder.Register<ClassB>().As<InterfaceForClassB>();89 var resolver = builder.Build();90 var resolvedInstance = resolver.Resolve<InterfaceForClassB>();91 Assert.AreEqual(typeof(ClassB), resolvedInstance.GetType());92 }93 /// <summary>94 /// Registering the not assignable class.95 /// </summary>96 [TestMethod]97 [ExpectedException(typeof(NotAssignableException))]98 public void RegisteringNotAssignableClass()99 {100 var builder = new ContainerBuilder();101 builder.Register<ClassA>().As<ClassB>();102 builder.Build();103 }104 /// <summary>105 /// Registering the same type twice.106 /// </summary>107 [TestMethod]108 public void RegisteringTheSameTypeTwice()109 {110 var builder = new ContainerBuilder();111 builder.Register<ClassA>().As<IFoo>();112 builder.Register<ClassB>().As<IFoo>();113 var continer = builder.Build();114 var impl = continer.Resolve<IEnumerable<IFoo>>();115 Assert.AreEqual(impl.Count(), 2);116 }117 /// <summary>118 /// Resolving the type of the unregistered.119 /// </summary>120 [TestMethod]121 [ExpectedException(typeof(CannotResolveTypeException))]122 public void ResolvingUnregisteredType()123 {124 var builder = new ContainerBuilder();125 builder.Build().Resolve<ClassA>();126 }127 /// <summary>128 /// Registering the interface as in and out types.129 /// </summary>130 [TestMethod]131 [ExpectedException(typeof(NotAssignableException))]132 public void RegisteringInterfaceAsInAndOut()133 {134 var builder = new ContainerBuilder();135 builder.Register<InterfaceForClassB>();136 builder.Build().Resolve<InterfaceForClassB>();137 }138 /// <summary>139 /// Resolving the implicit.140 /// </summary>141 [TestMethod]142 public void ResolvingImplicit()143 {144 var builder = new ContainerBuilder { ResolveImplicit = true };145 builder.Register<ClassB>();146 var factory = builder.Build();147 var resolvedInstance = factory.Resolve<InterfaceForClassB>();148 Assert.AreEqual(typeof(ClassB), resolvedInstance.GetType());149 }150 /// <summary>151 /// Resolving the implicit not registered.152 /// </summary>153 [TestMethod]154 [ExpectedException(typeof(CannotResolveTypeException))]155 public void ResolvingImplicitNotRegistered()156 {157 var builder = new ContainerBuilder { ResolveImplicit = true };158 builder.Register<ClassA>();159 var factory = builder.Build();160 var resolvedInstance = factory.Resolve<InterfaceForClassB>();161 Assert.AreEqual(typeof(ClassB), resolvedInstance.GetType());162 }163 /// <summary>164 /// Resolving types with dependencies.165 /// </summary>166 [TestMethod]167 public void ResolvingSimpleDependency()168 {169 var builder = new ContainerBuilder { ResolveImplicit = true };170 builder.Register<ClassB>().As<InterfaceForClassB>();171 builder.Register<ClassV>();172 var factory = builder.Build();173 var resolvedInstance = factory.Resolve<ClassV>();174 Assert.AreEqual(typeof(ClassV), resolvedInstance.GetType());175 }176 /// <summary>177 /// Resolving circular dependencies.178 /// </summary>179 [TestMethod]180 [ExpectedException(typeof(CircularDependenciesException))]181 public void ResolvingCircular()182 {183 var builder = new ContainerBuilder { ResolveImplicit = true };184 builder.Register<Class1>();185 builder.Register<Class2>();186 var factory = builder.Build();187 var resolvedInstance = factory.Resolve<Class2>();188 Assert.AreEqual(typeof(Class2), resolvedInstance.GetType());189 }190 [TestMethod]191 public void RegisterTypesCollectionFromAssembly()192 {193 var builder = new ContainerBuilder();194 builder.Register(Assembly.GetExecutingAssembly());195 var instances = builder.Build().Resolve<IEnumerable<ClassA>>();196 Assert.AreEqual(instances.Count(), 2);197 }198 /// <summary>The registering types with attribute.</summary>199 [TestMethod]200 public void RegisteringTypesWithAttribute()201 {202 var builder = new ContainerBuilder();203 builder.Register();204 var factory = builder.Build();205 var resolved1 = factory.Resolve<InterfaceForClassB>();206 var resolved2 = factory.Resolve<IEnumerable<ClassA>>();207 Assert.AreEqual(resolved1.GetType(), typeof(ClassB));208 Assert.AreEqual(resolved2.Count(), 2);209 }210 [TestMethod]211 public void AsImplementedInterfaceRegistration()212 {213 var builder = new ContainerBuilder();214 builder.Register<ClassA>().AsImplementedInterfaces();215 var cnt = builder.Build();216 var instance = cnt.Resolve<IFoo>();217 Assert.AreEqual(typeof(ClassA), instance.GetType());218 }219 [TestMethod]220 public void NestedLifetimeScopeInstancePerDependency()221 {222 var builder = new ContainerBuilder();223 builder.Register<ClassA>().As<IFoo>().PerLifetimeScope();224 var cnt = builder.Build();225 var firstInstance = cnt.Resolve<IFoo>();226 var nestedScope = cnt.BeginLifetimeScope();227 var nestedFirst = nestedScope.Resolve<IFoo>();228 var secondInstance = cnt.Resolve<IFoo>();229 var nestedSecond = nestedScope.Resolve<IFoo>();230 Assert.AreSame(firstInstance, secondInstance);231 Assert.AreSame(nestedFirst, nestedSecond);232 Assert.AreNotSame(firstInstance, nestedFirst);233 }234 [TestMethod]235 public void NestedLifetimeScopSingleeInstance()236 {237 var builder = new ContainerBuilder();238 builder.Register<ClassA>().As<IFoo>().SingleInstance();239 var cnt = builder.Build();240 var firstInstance = cnt.Resolve<IFoo>();241 var nestedScope = cnt.BeginLifetimeScope();242 var nestedFirst = nestedScope.Resolve<IFoo>();243 var secondInstance = cnt.Resolve<IFoo>();244 var nestedSecond = nestedScope.Resolve<IFoo>();245 Assert.AreSame(firstInstance, secondInstance);246 Assert.AreSame(nestedFirst, nestedSecond);247 Assert.AreSame(firstInstance, nestedFirst);248 }249 [TestMethod]250 public void InstancesPerLifeScopeDispoed()251 {252 var bld = new ContainerBuilder();253 bld.Register<DisposableClass>().PerLifetimeScope();254 var cnt = bld.Build();255 var mainInstance = cnt.Resolve<DisposableClass>();256 var nestedScope = cnt.BeginLifetimeScope();257 var nestedInstance = nestedScope.Resolve<DisposableClass>();258 cnt.Dispose();259 Assert.IsTrue(mainInstance.DisposeCalled);260 Assert.IsTrue(nestedInstance.DisposeCalled);261 }262 [TestMethod]263 [ExpectedException(typeof(LifetimeScopeDisposedException))]264 public void ResolvingAfterDisposalThrowsException()265 {266 var bld = new ContainerBuilder();267 bld.Register<DisposableClass>();268 var cnt = bld.Build();269 cnt.Dispose();270 cnt.Resolve<DisposableClass>();271 }272 [TestMethod]273 public void RegisteringTypesWithPredicates()274 {275 var bld = new ContainerBuilder();276 bld.Register(type => typeof(IFoo).IsAssignableFrom(type), Assembly.GetExecutingAssembly()).As<IFoo>();277 var container = bld.Build();278 var foos = container.Resolve<IEnumerable<IFoo>>();279 Assert.AreEqual(3, foos.Count());280 }281 [TestMethod]282 public void ResolvingMultipleTypesWithPredicateAndPerLiftetimeScope()283 {284 var bld = new ContainerBuilder();285 bld.Register(type => typeof(IFoo).IsAssignableFrom(type), Assembly.GetExecutingAssembly())286 .As<IFoo>()287 .PerLifetimeScope();288 var container = bld.Build();289 var foos = container.Resolve<IEnumerable<IFoo>>().ToList();290 Assert.AreEqual(3, foos.Count());291 Assert.AreNotSame(foos[0], foos[1]);292 Assert.AreNotSame(foos[1], foos[2]);293 }294 [TestMethod]295 public void RegisteringConcreteInstance()296 {297 var instanceB = new ClassB();298 var bld = new ContainerBuilder();299 bld.Register<ClassA>().As(instanceB).PerDependency();300 using (var cnt = bld.Build())301 {302 var mainB = cnt.Resolve<ClassA>();303 ClassA nestedB;304 using (var scope = cnt.BeginLifetimeScope())305 {306 nestedB = scope.Resolve<ClassA>();307 }308 Assert.AreSame(instanceB, mainB);309 Assert.AreSame(instanceB, nestedB);310 }311 }312 [TestMethod]313 public void RegisteringFactoryOfInstance()314 {315 var called = 0;316 var bld = new ContainerBuilder();317 bld.Register<ClassA>().As(ctx =>318 {319 called += 1;320 return new ClassB();321 }).PerLifetimeScope();322 using (var cnt = bld.Build())323 {324 cnt.Resolve<ClassA>();325 cnt.Resolve<ClassA>();326 using (var scope = cnt.BeginLifetimeScope())327 {328 scope.Resolve<ClassA>();329 }330 }331 Assert.AreEqual(2, called);332 }333 [TestMethod]334 public void SomeDisposableWithinhInsideContext()335 {336 var builder = new ContainerBuilder();337 builder.Register<SomeContext>().PerLifetimeScope();338 builder.Register<SomeDisposable>().PerLifetimeScope();339 SomeContext ctx;340 using (var scope = builder.Build().BeginLifetimeScope())341 {342 ctx = scope.Resolve<SomeContext>();343 }344 Assert.IsTrue(ctx.Disposables.First().Disposed);345 }346 [TestMethod]347 public void RegisteringClassesWithModule()348 {349 var bld = new ContainerBuilder();350 bld.RegisterModule(new SampleModule());351 var aInstance = bld.Build().Resolve<ClassA>();352 Assert.AreEqual(typeof(ClassB), aInstance.GetType());353 }354 [TestMethod]355 public void RegisteringEmbeddedModules()356 {357 var bld = new ContainerBuilder();358 bld.RegisterModule(new EmbeddingModule());359 var cnt = bld.Build();360 var aInstance = cnt.Resolve<ClassA>();361 var fooInstance = cnt.Resolve<IFoo>();362 Assert.AreEqual(typeof(ClassB), aInstance.GetType());363 Assert.AreEqual(typeof(ClassB), fooInstance.GetType());364 }365 [TestMethod]366 public void ModuleActivationListener()367 {368 var bld = new ContainerBuilder();369 bld.RegisterModule(new ModuleWithRegisteredInstanceListener());370 var cnt = bld.Build();371 var instance = cnt.Resolve<ActivableClass>();372 Assert.IsTrue(instance.Activated);373 }374 [TestMethod]375 public void ModuleResolvingRegisteredCalledProperly()376 {377 var mod = new ModuleWithResolveTrackingAndOwnRegistration();378 var bld = new ContainerBuilder();379 bld.RegisterModule(mod);380 ClassA i1;381 ClassA i2;382 using (var cnt = bld.Build().BeginLifetimeScope())383 {384 i1 = cnt.Resolve<ClassA>();385 i2 = cnt.Resolve<ClassA>();386 }387 Assert.AreSame(i1, i2);388 Assert.AreEqual(2, mod.Called);389 }390 [TestMethod]391 public void ModuleResolvingCalledProperly()392 {393 var mod = new ModuleWithResolveTracking();394 var bld = new ContainerBuilder();395 bld.Register<ClassA>().PerLifetimeScope();396 bld.RegisterModule(mod);397 ClassA i1;398 ClassA i2;399 using (var cnt = bld.Build().BeginLifetimeScope())400 {401 i1 = cnt.Resolve<ClassA>();402 i2 = cnt.Resolve<ClassA>();403 }404 Assert.AreSame(i1, i2);405 Assert.AreEqual(2, mod.Called);406 }407 [TestMethod]408 public void Register_RegisteringFactoryAsType()409 {410 var bld = new ContainerBuilder();411 var bInst = new ClassB();412 bld.Register(context => bInst).As<InterfaceForClassB>();413 var cnt = bld.Build();414 Assert.AreSame(bInst, cnt.Resolve<InterfaceForClassB>());415 }416 [TestMethod]417 public void Resolve_Lazy()418 {419 var bld = new ContainerBuilder();420 bld.Register<ClassInstanceCount>().PerLifetimeScope();421 ClassInstanceCount.Instances = 0;422 var cnt = bld.Build();423 var laztInst = cnt.Resolve<Lazy<ClassInstanceCount>>();424 Assert.AreEqual(0, ClassInstanceCount.Instances);425 // ReSharper disable once NotAccessedVariable426 var inst = laztInst.Value;427 Assert.AreEqual(1, ClassInstanceCount.Instances);428 laztInst = cnt.Resolve<Lazy<ClassInstanceCount>>();429 // ReSharper disable once RedundantAssignment430 inst = laztInst.Value;431 Assert.AreEqual(1, ClassInstanceCount.Instances);432 }433 [TestMethod]434 public void Resolve_LazyCombinedWithEnumerable()435 {436 var bld = new ContainerBuilder();437 bld.Register<ClassInstanceCount>();438 var cnt = bld.Build();439 var instancesEvaluator = cnt.Resolve<Lazy<IEnumerable<ClassInstanceCount>>>();440 var instances = instancesEvaluator.Value;441 Assert.AreEqual(1, instances.Count());442 }443 [TestMethod]444 [ExpectedException(typeof(RegistrationNotAllowedException))]445 public void Register_ForbidenType_ThrowsExcp()446 {447 (new ContainerBuilder()).Register<LifetimeProxy>().As<ILifetimeScope>();448 }449 [TestMethod]450 public void Resolve_ClassWithLifeTimeScopeInjected_ReturnsProperInstances()451 {452 var bld = new ContainerBuilder();453 bld.Register<InjectLifetimeScopeClass>();454 var cnt = bld.Build();455 var cl = cnt.Resolve<InjectLifetimeScopeClass>();456 Assert.AreSame(cnt, cl.Scope);457 }458 [TestMethod]459 public void Resolve_ClassWithLifeTimeScopeInjected_NestedLifetimeScope_ReturnsProperInstances()460 {461 var bld = new ContainerBuilder();462 bld.Register<InjectLifetimeScopeClass>();463 var cnt = bld.Build();464 var lf = cnt.BeginLifetimeScope();465 var cl = lf.Resolve<InjectLifetimeScopeClass>();466 Assert.AreSame(lf, cl.Scope);467 }468 [TestMethod]469 public void Keyed_Resolve()470 {471 const string someKey = "someKey";472 var bld = new ContainerBuilder();473 bld.Register<ClassB>().As<IFoo>().Keyed(someKey);474 bld.Register<ClassA>().As<IFoo>();475 var cnt = bld.Build();476 var firstInstance = cnt.Resolve<IFoo>();477 var second = cnt.ResolveKeyed<IFoo>(someKey);478 Assert.IsInstanceOfType(firstInstance, typeof(ClassA));479 Assert.IsInstanceOfType(second, typeof(ClassB));480 }481 [TestMethod]482 public void Resolve_Keyed_WithIEnumerable()483 {484 const string someKey = "someKey";485 var bld = new ContainerBuilder();486 bld.Register<ClassB>().As<IFoo>().Keyed(someKey).PerLifetimeScope();487 bld.Register<ClassA>().As<IFoo>().Keyed(someKey).PerLifetimeScope();488 bld.Register<FooClass>().As<IFoo>();489 var cnt = bld.Build();490 var coll = cnt.ResolveKeyed<IEnumerable<IFoo>>(someKey).ToList();491 var inst = cnt.Resolve<IFoo>();492 Assert.IsInstanceOfType(inst, typeof(FooClass));493 Assert.AreEqual(2, coll.Count);494 Assert.IsInstanceOfType(coll[0], typeof(ClassB));495 }496 [TestMethod]497 public void RegisterAndResolve_ValidFactory_GeneralObjectFacotory()498 {499 var target = new ClassA();500 var bld = new ContainerBuilder();501 bld.Register(ctx => (object)target).As<IFoo>();502 var cnt = bld.Build();503 var inst = cnt.Resolve<IFoo>();504 Assert.AreSame(target, inst);505 }506 [TestMethod, ExpectedException(typeof(CannotResolveTypeException))]507 public void RegisterAndResolve_InvalidFactory_ThrowsExcp()508 {...

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2ClassB b = new ClassB();3b.MethodB();4using ExampleTest;5ClassC c = new ClassC();6c.MethodC();7using ExampleTest;8ClassC c = new ClassC();9c.MethodC();

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 {4 public void MethodB()5 {6 ClassA a = new ClassA();7 a.MethodA();8 }9 }10}11using ExampleTest;12{13 {14 public void MethodC()15 {16 ClassB b = new ClassB();17 b.MethodB();18 }19 }20}21The import statement is used to import the package in the file. The syntax of the import statement is as follows:22import package_name;23Let’s see the example of the import statement. In the above example, let’s say you want to use ClassC in another package. You can import the ExampleTest package in the other package as follows:24using ExampleTest;25{26 {27 public void MethodD()28 {29 ClassC c = new ClassC();30 c.MethodC();31 }32 }33}34You can import the ExampleTest package in the other package as follows:35using ExampleTest;36You can import multiple packages in a single file as follows:37using ExampleTest;38using ExampleTest1;39using ExampleTest2;40You can also import the packages using the alias as follows:41using ExampleTest as ET;42using ExampleTest1 as ET1;

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 {4 public void print()5 {6 Console.WriteLine("ClassB");7 }8 }9}10using ExampleTest;11{12 {13 public void print()14 {15 Console.WriteLine("ClassA");16 }17 }18}19using ExampleTest;20{21 {22 static void Main(string[] args)23 {24 ClassA obj1 = new ClassA();25 obj1.print();26 ClassB obj2 = new ClassB();27 obj2.print();28 }29 }30}31using ExampleTest.ClassA;32using ExampleTest.ClassB;

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 {4 public void Display()5 {6 System.Console.WriteLine("ClassB");7 }8 }9}10using ExampleTest;11{12 {13 public void Display()14 {15 System.Console.WriteLine("ClassC");16 }17 }18}19using ExampleTest;20{21 {22 public void Display()23 {24 System.Console.WriteLine("ClassD");25 }26 }27}28using ExampleTest;29{30 {31 public void Display()32 {33 System.Console.WriteLine("ClassE");34 }35 }36}37using ExampleTest;38{39 {40 public void Display()41 {42 System.Console.WriteLine("ClassF");43 }44 }45}46using ExampleTest;47{48 {49 public void Display()50 {51 System.Console.WriteLine("ClassG");52 }53 }54}55using ExampleTest;56{57 {58 public void Display()59 {60 System.Console.WriteLine("ClassH");61 }62 }63}64using ExampleTest;65{66 {67 public void Display()68 {69 System.Console.WriteLine("ClassI");70 }71 }72}73using ExampleTest;74{75 {76 public void Display()77 {78 System.Console.WriteLine("ClassJ");79 }80 }81}

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 {4 public void MethodB()5 {6 Console.WriteLine("MethodB of ClassB");7 }8 }9}10using ExampleTest;11{12 {13 public void MethodC()14 {15 Console.WriteLine("MethodC of ClassC");16 }17 }18}19using ExampleTest;20{21 {22 public void MethodD()23 {24 Console.WriteLine("MethodD of ClassD");25 }26 }27}28using ExampleTest;29{30 {31 public void MethodE()32 {33 Console.WriteLine("MethodE of ClassE");34 }35 }36}37using ExampleTest;38{39 {40 public void MethodF()41 {42 Console.WriteLine("MethodF of ClassF");43 }44 }45}46using ExampleTest;47{48 {49 public void MethodG()50 {51 Console.WriteLine("MethodG of ClassG");52 }53 }54}55using ExampleTest;56{57 {58 public void MethodH()59 {60 Console.WriteLine("MethodH of ClassH");61 }62 }63}64using ExampleTest;65{66 {67 public void MethodI()68 {69 Console.WriteLine("MethodI of ClassI");70 }71 }72}73using ExampleTest;74{75 {76 public void MethodJ()77 {

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2using System;3{4 {5 public void Display()6 {7 Console.WriteLine("ClassB Display");8 }9 }10}11using ExampleTest;12using System;13{14 {15 public void Display()16 {17 Console.WriteLine("ClassC Display");18 }19 }20}

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 {4 public void Print()5 {6 Console.WriteLine("ClassB is called");7 }8 }9}10using ExampleTest;11{12 {13 ClassB b;14 public ClassA()15 {16 b = new ClassB();17 b.Print();18 }19 }20}21using ExampleTest;22{23 {24 static void Main(string[] args)25 {26 ClassA a = new ClassA();27 }28 }29}

Full Screen

Full Screen

ClassB

Using AI Code Generation

copy

Full Screen

1using ExampleTest;2{3 public static void Main()4 {5 ClassB b = new ClassB();6 b.Display();7 }8}

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