How to use Base method of Telerik.JustMock.Tests.Bar class

Best JustMockLite code snippet using Telerik.JustMock.Tests.Bar.Base

MiscFixture.cs

Source:MiscFixture.cs Github

copy

Full Screen

...131 }132 Assert.True(list.Count == 0);133 }134 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]135 public void ShouldBeAbleToCallBaseForGenericMethod()136 {137 var facade = Mock.Create<TestFacade>();138 Mock.Arrange(() => facade.Done<ContentItem>()).CallOriginal();139 Assert.Throws<ArgumentException>(() => facade.Done<ContentItem>());140 }141 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]142 public void ShouldBeAbleToCallOrignalForOutArgMethod()143 {144 var foo = Mock.Create<FooOut>();145 int expected = 0;146 Mock.Arrange(() => foo.EchoOut(out expected)).CallOriginal();147 foo.EchoOut(out expected);148 Assert.Equal(10, expected);149 }150 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]151 public void ShouldAssertCallOrignalForMethodWithGenericParameter()152 {153 var foo = Mock.Create<FooGeneric>();154 Mock.Arrange(() => foo.Echo<int>(10)).CallOriginal();155 foo.Echo<int>(10);156 }157 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]158 public void ShouldPickCorrectGenericVarientInCaseOfCallOriginal()159 {160 var foo = Mock.Create<FooGeneric>();161 Mock.Arrange(() => foo.Echo<int, int>(10)).CallOriginal();162 Assert.Throws<ArgumentException>(() => foo.Echo<int, int>(10));163 }164 [TestMethod, TestCategory("Lite")]165 public void ShouldAssertInvocationFromInsideAMockedEvent()166 {167 var @interface = Mock.Create<IInterface>();168 Mock.Arrange(() => @interface.TheFunc()).Returns(true);169 var target = new EventContainer(@interface);170 Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);171 Assert.True(target.Result);172 }173 [TestMethod, TestCategory("Lite")]174 public void ShouldAssertRaiseEventAfterAMethodCallFromDifferentMock()175 {176 var @interface = Mock.Create<IInterface>();177 var @extended = Mock.Create<IInterfaceExtended>();178 var target = new EventContainer(@interface);179 Mock.Arrange(() => @interface.TheFunc()).Returns(true);180 Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);181 @extended.TheFunc();182 Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);183 Assert.True(target.NumberOfTimesCalled == 2);184 }185 [TestMethod, TestCategory("Lite"),]186 public void ShouldBeToSubscribeEventForStrictMock()187 {188 new EventContainer(Mock.Create<IInterface>(Behavior.Strict));189 }190 [TestMethod, TestCategory("Lite")]191 public void ShouldNotThrowExceptionForDecimalTypeThatHasMultipleImplicitMethods()192 {193 var foo = Mock.Create<TestBase>();194 decimal value = 1;195 Mock.Arrange(() => foo.SetValue(value)).MustBeCalled();196 foo.SetValue(value);197 Mock.Assert(foo);198 }199 public abstract class TestBase200 {201 public virtual decimal Value { get; set; }202 public virtual void SetValue(decimal newValue)203 {204 Value = newValue;205 }206 }207 public class EventContainer208 {209 public bool Result = false;210 private IInterface @interface = null;211 public int NumberOfTimesCalled { get; set; }212 public EventContainer(IInterface i)213 {214 this.@interface = i;215 this.@interface.TheEvent += new EventHandler(i_TheEvent);216 }217 void i_TheEvent(object sender, EventArgs e)218 {219 this.Result = this.@interface.TheFunc();220 this.NumberOfTimesCalled++;221 }222 }223 public interface IInterface224 {225 event EventHandler TheEvent;226 bool TheFunc();227 }228 public interface IInterfaceExtended229 {230 bool TheFunc();231 }232 public class FooOut233 {234 public virtual void EchoOut(out int argOut)235 {236 argOut = 10;237 }238 }239 public class FooGeneric240 {241 public virtual void Echo<TKey>(TKey key)242 {243 }244 public virtual void Echo<TKey, TKey2>(TKey key)245 {246 throw new ArgumentException();247 }248 }249 public class ContentItem : IFacade<ContentItem>250 {251 }252 public interface IFacade<TParaentFacade> { }253 public class TestFacade254 {255 public virtual TParentFacade Done<TParentFacade>() where TParentFacade : class, IFacade<TParentFacade>256 {257 throw new ArgumentException("My custom error");258 }259 }260#if !COREFX261 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]262 public void ShouldNotImplementInternalVirtualMemberUsingProxyWhenNotVisible()263 {264 var context = Mock.Create<Telerik.JustMock.DemoLibSigned.DummyContext>();265 Assert.NotNull(context);266 }267 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]268 public void ShouldCreateMockForFrameWorkClassWithInternalCtor()269 {270 var downloadDateCompleted = Mock.Create<DownloadDataCompletedEventArgs>();271 Assert.NotNull(downloadDateCompleted != null);272 }273 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]274 public void ShouldAssertStreamMocking()275 {276#if NETCORE277 Telerik.JustMock.Setup.AllowedMockableTypes.Add<System.IO.Stream>();278#endif279 var stream = Mock.Create<Stream>();280 Mock.Arrange(() => stream.Seek(0, SeekOrigin.Begin)).Returns(0L);281 var position = stream.Seek(0, SeekOrigin.Begin);282 Assert.Equal(0, position);283 Mock.Arrange(() => stream.Flush()).MustBeCalled();284 Mock.Arrange(() => stream.SetLength(100)).MustBeCalled();285 Assert.Throws<AssertionException>(() => Mock.Assert(stream));286 stream.Flush();287 stream.SetLength(100);288 Mock.Assert(stream);289 }290#endif291 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]292 public void ShouldMockMultipleInterfaceOnASingleMock()293 {294 var foo = Mock.Create<IFooDispose>();295 var iDisposable = foo as IDisposable;296 bool called = false;297 Mock.Arrange(() => iDisposable.Dispose()).DoInstead(() => called = true);298 iDisposable.Dispose();299 Assert.True(called);300 }301 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]302 public void ShouldMockClassWithInterfaceConstraints()303 {304 var container = Mock.Create<FakeContainer<Product>>();305 Mock.Arrange(() => container.Do<Product>()).MustBeCalled();306 container.Do<Product>();307 }308 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]309 public void ShouldMockMethodCallWithObjectArgumentWithMatcher()310 {311 var container = Mock.Create<IContainer>();312 var called = false;313 Mock.Arrange(() => container.Resolve(Arg.IsAny<IDatabase>())).DoInstead(() => called = true);314 var database = Mock.Create<IDatabase>();315 container.Resolve(database);316 Assert.True(called);317 }318 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]319 public void ShouldBeAbleToAssertNestedSetupDirectly()320 {321 var outer = Mock.Create<FooOuter>();322 var inner = Mock.Create<FooInter>();323 Mock.Arrange(() => outer.GetInnerClass()).Returns(inner);324 Mock.Arrange(() => inner.Value).Returns(10).MustBeCalled();325 Assert.Throws<AssertionException>(() => Mock.Assert(() => outer.GetInnerClass().Value));326 }327 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]328 public void ShouldNotCreateNestedMockWhenReturningCallBackForGenericCall()329 {330 Product product1 = new Product();331 Product product2 = new Product();332 Queue<Product> products = new Queue<Product>();333 products.Enqueue(product1);334 products.Enqueue(product2);335 var context = Mock.Create<IDataContext>();336 Mock.Arrange(() => context.Get<Product>()).Returns(() => products.Dequeue());337 Assert.True(context.Get<Product>().Equals(product1));338 Assert.True(context.Get<Product>().Equals(product2));339 }340 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]341 public void ShouldReturnNullWhenSpecifiedByReturn()342 {343 var exmpleMock = Mock.Create<IExampleInterface>();344 Mock.Arrange(() => exmpleMock.GetMeAllFoos()).Returns((IList<IFoo>)null);345 Assert.Null(exmpleMock.GetMeAllFoos());346 }347#if !COREFX348 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]349 public void ShouldMockInternalMemberFromBaseClass()350 {351 var id = Guid.NewGuid();352 var manager = Mock.Create<IContentManager>();353 var facade = Mock.Create<BlogFacade>(Behavior.CallOriginal);354 Mock.Arrange(() => facade.ContentManager).Returns(manager);355 Mock.Arrange(() => manager.GetItem(Arg.IsAny<Type>(), Arg.AnyGuid))356 .Returns(new Product()).MustBeCalled();357 facade.LoadItem(id);358 Mock.Assert(facade.ContentManager);359 }360#endif361 [TestMethod, TestCategory("Lite")]362 public void ShouldAssertSetupWithObjectArrayAsParams()363 {364 var foo = Mock.Create<Foo<Product>>();365 const int expected = 1;366 Mock.Arrange(() => foo.GetByKey(expected)).Returns(() => null).MustBeCalled();367 foo.GetByKey(expected);368 Mock.Assert(foo);369 }370 [TestMethod, TestCategory("Lite")]371 public void ShouldNotInstantiatePropertyWhenSetExplicitly()372 {373 var foo = Mock.Create<NestedFoo>();374 var actual = new FooThatFails(string.Empty);375 Mock.Arrange(() => foo.FooThatFailsOnCtor).Returns(actual);376 Assert.Equal(foo.FooThatFailsOnCtor, actual);377 }378 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]379 public void ShouldBeAbleToCreateMockWithInternalCtor()380 {381 var expected = "hello";382 var foo = Mock.Create<FooInternal>(x =>383 {384 x.CallConstructor(() => new FooInternal("hello"));385 x.SetBehavior(Behavior.CallOriginal);386 });387 Assert.Equal(foo.Name, expected);388 }389 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]390 public void ShouldExecuteEqualsDuringAssertWithMockArgument()391 {392 var foo = Mock.Create<FooAbstract>();393 var fooWork = Mock.Create<FooWork>();394 fooWork.DoWork(foo);395 Mock.Assert(() => fooWork.DoWork(foo));396 }397 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]398 public void ShouldAssertMultipleOccurrencesSeparatelyForAssertAll()399 {400 IFileReader fileReader = Mock.Create<IFileReader>(Behavior.Strict);401 Mock.Arrange(() => fileReader.FileExists(@"C:\Foo\Categories.txt")).Returns(false).OccursOnce();402 Mock.Arrange(() => fileReader.ReadFile(@"C:\Foo\Categories.txt")).IgnoreArguments().OccursNever();403 fileReader.FileExists(@"C:\Foo\Categories.txt");404 Mock.Assert(fileReader);405 }406 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]407 public void ShouldAssertOccurenceWhenCombinedWithNoSetupCalls()408 {409 string userName = "Bob";410 string password = "Password";411 ILoginService service = Mock.Create<ILoginService>();412 Mock.Arrange(() => service.ValidateUser(userName, password)).Returns(5).OccursOnce();413 Mock.Arrange(() => service.ValidateUser("foo", "bar")).OccursNever();414 SecurityHandler handler = new SecurityHandler(service);415 bool loggedIn = handler.LoginUser(userName, password);416 Assert.True(loggedIn);417 Assert.Equal(handler.UserID, 5);418 Mock.Assert(service);419 }420 public class NestedFoo421 {422 public virtual FooThatFails FooThatFailsOnCtor { get; set; }423 }424 public class FooThatFails425 {426 public FooThatFails(string message)427 {428 }429 public FooThatFails()430 {431 throw new ArgumentException("Failed");432 }433 }434 public class SecurityHandler435 {436 private readonly ILoginService _service;437 public int UserID { get; internal set; }438 public SecurityHandler(ILoginService service)439 {440 _service = service;441 _service.DatabaseName = "NorthWind";442 }443 public bool LoginUser(string userName, string password)444 {445 UserID = _service.ValidateUser(userName, password);446 return (UserID != 0);447 }448 }449 public interface ILoginService450 {451 int ValidateUser(string userName, string password);452 string DatabaseName { get; set; }453 event EventHandler UserLoggedOnEvent;454 event EventHandler DatabaseChangedEvent;455 }456 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]457 public void ShouldAssertCallOriginalOnOverloadsViaProxy()458 {459 var dummyExpression = Mock.Create<DummyExpression>(Behavior.CallOriginal);460 dummyExpression.Evaluate(10);461 }462 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]463 public void ShouldAssertSetPropertyOccurenceForAnyValue()464 {465 var foo = Mock.Create<IFoo>();466 Mock.ArrangeSet<IFoo>(() => foo.EffectiveFrom = DateTime.Now).IgnoreArguments();467 foo.EffectiveFrom = DateTime.Now;468 Assert.Throws<AssertionException>(() => Mock.AssertSet(() => foo.EffectiveFrom = Arg.IsAny<DateTime>(), Occurs.Never()));469 }470 [TestMethod, TestCategory("Lite")]471 public void ShouldAssertWithByteArrayArguments()472 {473 ITestInterface ti = Mock.Create<ITestInterface>();474 byte[] newimagebytes = new byte[1] { 4 };475 ti.DoStuff(newimagebytes);476 Mock.Assert(() => ti.DoStuff(newimagebytes), Occurs.AtLeastOnce());477 }478 [TestMethod, TestCategory("Lite"), TestCategory("Misc")]479 public void UsingShouldNotInterfereWithPreOccurrence()480 {481 var fakereader = Mock.Create<IXmlReader>();482 Mock.Arrange(() => fakereader.EOF).Returns(true).OccursOnce();483 Mock.Arrange(() => fakereader.ReadOuterXml()).Returns("aaa").OccursNever();484 using (fakereader)485 {486 if (!fakereader.EOF)487 {488 string s = fakereader.ReadOuterXml();489 }490 }491 Mock.Assert(fakereader);492 }493 [TestMethod, TestCategory("Lite")]494 public void ShouldAssertNewGuIdArgumentForSpecificValue()495 {496 var localPersister = Mock.Create<IProcessDataPersister>();497 Mock.Arrange(() => localPersister.GetTaskWarnings(new Guid("{00000000-0000-0000-0001-000000000003}")))498 .Returns(new List<TaskWarning>() { new TaskWarning(new Guid("{00000000-0000-0000-0001-000000000003}")) { EscalationLevel = 0 } })499 .MustBeCalled();500 var list = localPersister.GetTaskWarnings(new Guid("{00000000-0000-0000-0001-000000000003}"));501 Assert.NotNull(list);502 Mock.Assert(localPersister);503 }504 [TestMethod, TestCategory("Lite"),]505 public void ShouldConfirmMockingClassWithMethodHidingItsVirtualBase()506 {507 var child = Mock.Create<ChildClass>();508 Assert.NotNull(child);509 }510 public class ChildClass : ParentClass, IElement511 {512 public new bool CanWriteProperty(string propertyName)513 {514 throw new NotImplementedException();515 }516 }517 public interface IElement518 {519 bool CanWriteProperty(string propertyName);...

Full Screen

Full Screen

NinjectAutoMockFixture.cs

Source:NinjectAutoMockFixture.cs Github

copy

Full Screen

...191 throw new InvalidOperationException();192 }193 }194 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]195 public void ShouldSelectConstructorBasedOnSettings()196 {197 // assert the default NInject behavior that injects into the constructor with most parameters198 var container = new MockingContainer<VariousCtors>();199 Assert.Throws<InvalidOperationException>(() => { var inst = container.Instance; });200 // assert the overriden constructor lookup behavior201 var container2 = new MockingContainer<VariousCtors>(new AutoMockSettings { ConstructorArgTypes = new[] { typeof(IFileSystem) } });202 Assert.NotNull(container2.Instance);203 // assert that specifying an invalid constructor throws204 Assert.Throws<MockException>(() => new MockingContainer<VariousCtors>(new AutoMockSettings { ConstructorArgTypes = new[] { typeof(ICalendar) } }));205 }206 public interface IService207 {208 int Value { get; set; }209 }210 public class Module211 {212 public IService service;213 public Module(IService service)214 {215 this.service = service;216 }217 }218 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]219 public void ShouldMakeSingletonExplicitlyRequestedServices()220 {221 var container = new MockingContainer<Module>();222 var s1 = container.Get<IService>();223 var s2 = container.Instance.service;224 Assert.Same(s1, s2);225 }226 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]227 public void ShouldArrangePropertySet()228 {229 // Arrange230 var container = new MockingContainer<Module>();231 container.ArrangeSet<IService>(x => x.Value = 99).MustBeCalled();232 var service = container.Get<IService>();233 // Act 234 service.Value = 99;235 // Assert236 container.Assert<IService>();237 }238 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]239 public void ShouldArrangePropertySetWithMatcher()240 {241 // Arrange242 var container = new MockingContainer<Module>();243 container.ArrangeSet<IService>(x => x.Value = Arg.AnyInt).MustBeCalled();244 var service = container.Get<IService>();245 // Act 246 service.Value = 99;247 // Assert248 container.Assert<IService>();249 }250 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]251 public void ShouldAssertPropertySet()252 {253 // Arrange254 var container = new MockingContainer<Module>();255 // Act 256 container.Get<IService>().Value = 99;257 // Assert258 container.AssertSet<IService>(x => x.Value = 99);259 }260 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]261 public void ShouldAssertPropertySetWithMatcher()262 {263 // Arrange264 var container = new MockingContainer<Module>();265 // Act 266 container.Get<IService>().Value = 99;267 // Assert268 container.AssertSet<IService>(x => x.Value = Arg.AnyInt);269 }270 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]271 public void ShouldAssertPropertySetNegative()272 {273 DebugView.IsTraceEnabled = true;274 // Arrange275 var container = new MockingContainer<Module>();276 // Assert277 container.AssertSet<IService>(x => x.Value = 99, Occurs.Never());278 }279 [TestMethod, TestCategory("Lite"), TestCategory("Ninject")]280 public void ShouldAssertPropertySetNegativeWithMatcher()281 {282 // Arrange283 var container = new MockingContainer<Module>();284 // Assert285 container.AssertSet<IService>(x => x.Value = Arg.AnyInt, Occurs.Never());286 }287 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]288 public void ShouldAssertRaisesAgainstMethod()289 {290 var container = new MockingContainer<Executor>();291 bool raised = false;292 container.Arrange<IExecutor>(x => x.Submit()).Raises(() => container.Get<IExecutor>().Done += null, EventArgs.Empty);293 container.Get<IExecutor>().Done += delegate { raised = true; };294 container.Instance.Submit();295 Assert.True(raised);296 }297 public class Executor298 {299 public Executor(IExecutor executor)300 {301 this.executor = executor;302 }303 public void Submit()304 {305 this.executor.Submit();306 }307 private IExecutor executor;308 }309 public interface IExecutor310 {311 event EventHandler<EventArgs> Done;312 event EventHandler Executed;313 void Submit();314 }315 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]316 public void ShouldAssertMockingNestedDependency()317 {318 var container = new MockingContainer<Foo>();319 container.Bind<Bar>().ToSelf();320 container.Arrange<IUnitOfWork>(uow => uow.DoWork()).MustBeCalled();321 Assert.Throws<AssertionException>(() => container.Assert());322 container.Instance.DoWork();323 container.Assert();324 }325 public class Foo326 {327 public Foo(Bar bar)328 {329 this.bar = bar;330 }331 public void DoWork()332 {333 this.bar.DoWork();334 }335 private readonly Bar bar;336 }337 public class Bar338 {339 public Bar(IUnitOfWork unitOfWork)340 {341 this.unitOfWork = unitOfWork;342 }343 public void DoWork()344 {345 this.unitOfWork.DoWork();346 }347 private readonly IUnitOfWork unitOfWork;348 }349 public interface IUnitOfWork350 {351 void DoWork();352 }353 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]354 public void ShouldResolveTargetTypeWithInterfaceAndConcreteDependencies()355 {356 var container = new MockingContainer<Unit>();357 container.Arrange<IUnitOfWork>(uow => uow.DoWork()).MustBeCalled();358 // this is where it resolves.359 container.Instance.DoWork();360 container.Assert();361 }362 public class Unit363 {364 public Unit(IUnitOfWork unitOfWork, WorkItem workItem)365 {366 this.unitOfWork = unitOfWork;367 this.workItem = workItem;368 }369 public void DoWork()370 {371 workItem.DoWork();372 unitOfWork.DoWork();373 }374 private readonly IUnitOfWork unitOfWork;375 private readonly WorkItem workItem;376 }377 public class WorkItem378 {379 public void DoWork()380 {381 }382 }383 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]384 public void ShouldAssertOccurrenceFromContainerWithoutPriorArrangement()385 {386 var c = new MockingContainer<Unit>();387 c.Instance.DoWork();388 c.Assert<IUnitOfWork>(x => x.DoWork());389 }390 public class DisposableContainer : IDisposable391 {392 public IList<IDisposable> Disposables;393 public DisposableContainer(IList<IDisposable> disposables)394 {395 this.Disposables = disposables;396 }397 public void Dispose()398 {399 this.Disposables.Clear();400 }401 }402 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]403 public void ShouldInjectContainers()404 {405 var c = new MockingContainer<DisposableContainer>();406 var disposables = new List<IDisposable> { Mock.Create<IDisposable>(), Mock.Create<IDisposable>() };407 var i = c.Get<DisposableContainer>(new ConstructorArgument("disposables", disposables));408 i.Dispose();409 Assert.Equal(0, disposables.Count);410 }411 public abstract class DependencyBase412 {413 public IDisposable Dep { get; set; }414 protected DependencyBase(IDisposable dep)415 {416 this.Dep = dep;417 }418 public abstract int Value { get; }419 public abstract string Name { get; set; }420 public int baseValue;421 public virtual int BaseValue422 {423 get { return baseValue; }424 set { baseValue = value; }425 }426 }427 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]428 public void ShouldInjectAbstractType()429 {430 var c = new MockingContainer<DependencyBase>();431 var obj = c.Instance;432 Assert.NotNull(obj.Dep);433 }434 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]435 public void ShouldArrangeMethodsOnInjectedAbstractType()436 {437 var c = new MockingContainer<DependencyBase>();438 var obj = c.Instance;439 Mock.Arrange(() => obj.Value).Returns(5);440 Assert.Equal(5, obj.Value);441 }442 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]443 public void ShouldCheckPropertyMixinOnNonabstractPropertyOnInjectedAbstractType()444 {445 var c = new MockingContainer<DependencyBase>();446 var obj = c.Instance;447 obj.BaseValue = 10;448 Assert.Equal(10, obj.baseValue);449 }450 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]451 public void ShouldInjectAbstractTypeWithSpecifiedCtor()452 {453 var c = new MockingContainer<DependencyBase>(454 new AutoMockSettings { ConstructorArgTypes = new[] { typeof(IDisposable) } });455 var obj = c.Instance;456 Assert.NotNull(obj.Dep);457 }458 [TestMethod, TestCategory("Lite"), TestCategory("AutoMock")]459 public void ShouldIncludeAssertionMessageWhenAssertingContainer()460 {461 var c = new MockingContainer<FileLog>();462 c.Arrange<ICalendar>(x => x.Now).MustBeCalled("Calendar must be used!");463 c.Arrange<IFileSystem>(x => x.Refresh()).MustBeCalled("Should use latest data!");464 var ex = Assert.Throws<AssertionException>(() => c.Assert("Container must be alright!"));465 Assert.True(ex.Message.Contains("Calendar must be used!"));466 Assert.True(ex.Message.Contains("Should use latest data!"));467 Assert.True(ex.Message.Contains("Container must be alright!"));...

Full Screen

Full Screen

NonPublicFixture.cs

Source:NonPublicFixture.cs Github

copy

Full Screen

...142 Assert.Throws<MissingMemberException>(() => Mock.NonPublic.Arrange(foo, "ExecuteProtected"));143 }144#if !SILVERLIGHT145 [TestMethod, TestCategory("Lite"), TestCategory("NonPublic")]146 public void ShouldCreateMockFromClassHavingAbstractInternalMethodInBase()147 {148 var foo = Mock.Create<FooAbstract2>();149 foo.TryCreateToken(string.Empty);150 }151 [TestMethod, TestCategory("Lite"), TestCategory("NonPublic")]152 public void ShouldMockTypeWithInternalCtorWhenInternalVisibleToIsApplied()153 {154 // Provided that InternalsVisibleTo attribute is included in assemblyinfo.cs.155 var foo = Mock.Create<FooInternal>(Behavior.CallOriginal);156 Assert.NotNull(foo.Builder);157 }158 [TestMethod, TestCategory("Lite"), TestCategory("NonPublic")]159 public void ShouldAssertNonPublicMethodFromBase()160 {161 var baz = Mock.Create<Baz>(Behavior.CallOriginal);162 const string targetMethod = "MethodToMock";163 Mock.NonPublic.Arrange(baz, targetMethod).DoNothing();164 baz.MethodToTest();165 Mock.NonPublic.Assert(baz, targetMethod);166 }167#if !PORTABLE168 [TestMethod, TestCategory("Lite"), TestCategory("NonPublic")]169 public void ShouldAssertNonPublicCallWhenOccurrenceIsApplied()170 {171 var baz = Mock.Create<Bar>(Behavior.CallOriginal);172 const string targetMethod = "MethodToMock";173 Mock.NonPublic.Arrange(baz, targetMethod).OccursOnce();174 baz.GetType().GetMethod(targetMethod, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(baz, null);175 Mock.NonPublic.Assert(baz, targetMethod);176 }177 [TestMethod, TestCategory("Lite"), TestCategory("NonPublic"), TestCategory("Assertion")]178 public void ShouldGetTimesCalledOfNonPublicMethod()179 {180 var mock = Mock.Create<Bar>();181 Mock.NonPublic.MakePrivateAccessor(mock).CallMethod("MethodToMock");182 Assert.Equal(1, Mock.NonPublic.GetTimesCalled(mock, "MethodToMock"));183 Assert.Equal(1, Mock.NonPublic.GetTimesCalled(mock, typeof(Bar).GetMethod("MethodToMock", BindingFlags.NonPublic | BindingFlags.Instance)));184 }185#endif186 public class Bar187 {188 protected virtual void MethodToMock()189 {190 throw new ArgumentException("Base method Invoked");191 }192 }193 public class Baz : Bar194 {195 public virtual void MethodToTest()196 {197 MethodToMock();198 }199 }200 internal class FooInternal201 {202 internal FooInternal()203 {204 builder = new StringBuilder();...

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1var barMock = Mock.Create<Bar>();2Mock.Arrange(() => barMock.Base()).MustBeCalled();3barMock.Base();4Mock.Assert(barMock);5var fooMock = Mock.Create<Foo>();6Mock.Arrange(() => fooMock.Base()).MustBeCalled();7fooMock.Base();8Mock.Assert(fooMock);9var barMock = Mock.Create<Bar>();10Mock.Arrange(() => barMock.Base()).MustBeCalled();11barMock.Base();12Mock.Assert(barMock);13var fooMock = Mock.Create<Foo>();14Mock.Arrange(() => fooMock.Base()).MustBeCalled();15fooMock.Base();16Mock.Assert(fooMock);17var barMock = Mock.Create<Bar>();18Mock.Arrange(() => barMock.Base()).MustBeCalled();19barMock.Base();20Mock.Assert(barMock);21var fooMock = Mock.Create<Foo>();22Mock.Arrange(() => fooMock.Base()).MustBeCalled();23fooMock.Base();24Mock.Assert(fooMock);25var barMock = Mock.Create<Bar>();26Mock.Arrange(() => barMock.Base()).MustBeCalled();27barMock.Base();28Mock.Assert(barMock);29var fooMock = Mock.Create<Foo>();30Mock.Arrange(() => fooMock.Base()).MustBeCalled();31fooMock.Base();32Mock.Assert(fooMock);33var barMock = Mock.Create<Bar>();34Mock.Arrange(() => barMock.Base()).MustBeCalled();35barMock.Base();36Mock.Assert(barMock);37var fooMock = Mock.Create<Foo>();38Mock.Arrange(() => fooMock.Base()).MustBeCalled();39fooMock.Base();40Mock.Assert(fooMock);

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.Tests;2{3 {4 public virtual int FooMethod()5 {6 return 0;7 }8 }9 {10 public override int FooMethod()11 {12 return 1;13 }14 }15}16using Telerik.JustMock.Tests;17{18 {19 public virtual int FooMethod()20 {21 return 0;22 }23 }24 {25 public override int FooMethod()26 {27 return 1;28 }29 }30}31using Telerik.JustMock.Tests;32{33 {34 public virtual int FooMethod()35 {36 return 0;37 }38 }39 {40 public override int FooMethod()41 {42 return 1;43 }44 }45}46using Telerik.JustMock.Tests;47{48 {49 public virtual int FooMethod()50 {51 return 0;52 }53 }54 {55 public override int FooMethod()56 {57 return 1;58 }59 }60}61using Telerik.JustMock.Tests;62{63 {64 public virtual int FooMethod()65 {66 return 0;67 }68 }69 {70 public override int FooMethod()71 {72 return 1;73 }74 }75}76using Telerik.JustMock.Tests;77{78 {79 public virtual int FooMethod()80 {81 return 0;82 }83 }

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1Telerik.JustMock.Tests.Bar bar = new Telerik.JustMock.Tests.Bar();2bar.Base();3Telerik.JustMock.Mock.Assert(bar).WasCalled(x => x.Base());4Telerik.JustMock.Tests.Bar bar = new Telerik.JustMock.Tests.Bar();5bar.Base();6Telerik.JustMock.Mock.Assert(bar).WasCalled(x => x.Base());7{8 public abstract void Foo();9 public abstract int Bar();10}11public void ShouldMockAbstractClass()12{13 var mock = Mock.Create<AbstractClass>();14 mock.Foo();15 Assert.AreEqual(0, mock.Bar());16}17{18 public static void Foo()19 {20 }21 public static int Bar()22 {23 return 5;24 }25}26public void ShouldMockStaticClass()27{28 var mock = Mock.Create<StaticClass>();29 mock.Foo();30 Assert.AreEqual(0, mock.Bar());31}32{33 static StaticClassWithPrivateConstructor()34 {35 }36 public static void Foo()37 {38 }39 public static int Bar()40 {41 return 5;42 }43}44public void ShouldMockStaticClassWithPrivateConstructor()45{46 var mock = Mock.Create<StaticClassWithPrivateConstructor>();47 mock.Foo();48 Assert.AreEqual(0, mock.Bar());49}

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1{2 {3 public virtual string Bar()4 {5 return "Foo.Bar";6 }7 }8}9{10 {11 public override string Bar()12 {13 return "Bar.Bar";14 }15 }16}17{18 {19 public virtual string Bar()20 {21 return "Foo.Bar";22 }23 }24}25{26 {27 public override string Bar()28 {29 return "Bar.Bar";30 }31 }32}33{34 {35 public virtual string Bar()36 {37 return "Foo.Bar";38 }39 }40}41{42 {43 public override string Bar()44 {45 return "Bar.Bar";46 }47 }48}49{50 {51 public virtual string Bar()52 {53 return "Foo.Bar";54 }55 }56}57{58 {59 public override string Bar()60 {61 return "Bar.Bar";62 }63 }64}65{66 {67 public virtual string Bar()68 {69 return "Foo.Bar";70 }71 }72}

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1public void TestMethod1()2{3 var bar = Mock.Create<Bar>();4 Mock.Arrange(() => bar.Base()).Returns(1);5 Assert.AreEqual(1, bar.Base());6}7public void TestMethod2()8{9 var bar = Mock.Create<Bar>();10 Mock.Arrange(() => bar.Base()).Returns(1);11 Assert.AreEqual(1, bar.Base());12}13public void TestMethod1()14{15 var bar = Mock.Create<Bar>();16 Mock.Arrange(() => bar.Base()).Returns(1);17 Assert.AreEqual(1, bar.Base());18}19public void TestMethod2()20{21 var bar = Mock.Create<Bar>();22 Mock.Arrange(() => bar.Base()).Returns(1);23 Assert.AreEqual(1, bar.Base());24}25Hello,The tests in the second file are run in a different process (because the first file is run in a separate process), so the mocking is not shared between the processes. This is

Full Screen

Full Screen

Base

Using AI Code Generation

copy

Full Screen

1public void Test()2{3 var foo = Mock.Create<IFoo>(Behavior.CallOriginal);4 var bar = Mock.Create<IBar>(Behavior.CallOriginal);5 Mock.Arrange(() => foo.Base()).DoNothing();6 Mock.Arrange(() => bar.Base()).DoNothing();7 foo.Base();8 bar.Base();9}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JustMockLite automation tests on LambdaTest cloud grid

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

Most used method in Bar

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful