How to use TaskWarning class of Telerik.JustMock.Tests package

Best JustMockLite code snippet using Telerik.JustMock.Tests.TaskWarning

Run JustMockLite automation tests on LambdaTest cloud grid

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

MiscFixture.cs

Source: MiscFixture.cs Github

copy
1/*
2 JustMock Lite
3 Copyright © 2010-2015 Progress Software Corporation
4
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8
9   http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16*/
17
18using System;
19using System.Collections.Generic;
20using System.Linq;
21using System.IO;
22using System.Net;
23using Telerik.JustMock.Core;
24
25#if !COREFX
26using Telerik.JustMock.DemoLib;
27#endif
28
29#region JustMock Test Attributes
30#if NUNIT
31using NUnit.Framework;
32using TestCategory = NUnit.Framework.CategoryAttribute;
33using TestClass = NUnit.Framework.TestFixtureAttribute;
34using TestMethod = NUnit.Framework.TestAttribute;
35using TestInitialize = NUnit.Framework.SetUpAttribute;
36using TestCleanup = NUnit.Framework.TearDownAttribute;
37using AssertionException = NUnit.Framework.AssertionException;
38#elif XUNIT
39using Xunit;
40using Telerik.JustMock.XUnit.Test.Attributes;
41using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute;
42using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute;
43using TestMethod = Xunit.FactAttribute;
44using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute;
45using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute;
46using AssertionException = Telerik.JustMock.XUnit.AssertFailedException;
47#elif VSTEST_PORTABLE
48using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
49using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException;
50#else
51using Microsoft.VisualStudio.TestTools.UnitTesting;
52using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException;
53#endif
54#endregion
55
56namespace Telerik.JustMock.Tests
57{
58	[TestClass]
59	public class MiscFixture
60	{
61		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
62		public void ShouldReturnForDateTimeUsedAsArg()
63		{
64			var items = new List<string>() { "Foo", "Bar" };
65
66			var myClass = Mock.Create<IMyClass>(Behavior.Strict);
67
68			Mock.Arrange(() => myClass.GetValuesSince(Arg.IsAny<DateTime>())).Returns(items);
69
70			var actual = myClass.GetValuesSince(DateTime.Now).ToList();
71
72			Assert.Equal(items.Count, actual.Count);
73		}
74
75
76		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
77		public void ShouldAssertInPtrAsReturnValue()
78		{
79			var fooPtr = Mock.Create<IFooPtr>(Behavior.Strict);
80
81			IntPtr ret = new IntPtr(3);
82
83			Mock.Arrange(() => fooPtr.Get("a")).Returns(ret);
84
85			IntPtr actual = fooPtr.Get("a");
86
87			Assert.Equal(ret, actual);
88		}
89
90		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
91		public void ShouldAssertArgumentPassedByImplictConversation()
92		{
93			const string s = "XYZ";
94
95			var foo = Mock.Create<IFoo>();
96
97			Mock.Arrange(() => foo.Get(s)).Returns(10);
98
99			Assert.Throws<AssertionException>(() => Mock.Assert(() => foo.Get(s)));
100
101			int ret = foo.Get(s);
102
103			Mock.Assert(() => foo.Get(s));
104
105			Assert.Equal(10, ret);
106		}
107
108		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
109		public void ShouldAssertArgumentPassedByExplictConversation()
110		{
111			const string s = "XYZ";
112
113			var foo = Mock.Create<IFoo>();
114
115			Mock.Arrange(() => foo.Get(SomeClass<string>.From(s))).Returns(10);
116
117			Assert.Throws<AssertionException>(() => Mock.Assert(() => foo.Get(SomeClass<string>.From(s))));
118
119			int ret = foo.Get(SomeClass<string>.From(s));
120
121			Mock.Assert(() => foo.Get(SomeClass<string>.From(s)));
122
123			Assert.Equal(10, ret);
124		}
125
126		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
127		public void ShouldCreateMockWithGenericConstraints()
128		{
129			var target = Mock.Create<ISomething<int>>();
130			Assert.NotNull(target);
131		}
132
133		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
134		public void ShoudlAssertCallWithGenericConstraint()
135		{
136			var target = Mock.Create<ISomething<int>>();
137			// the following line should not throw any exception.
138			target.DoSomething<int>();
139		}
140
141		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
142		public void ShouldAssertInterfaceForGenericConstaint()
143		{
144			var target = Mock.Create<ISomething<IDummy>>();
145			// the following line should not throw any exception.
146			target.DoSomething<IDummy>();
147		}
148
149
150		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
151		public void ShouldAssertImplicitInterface()
152		{
153			var bar = Mock.Create<IBar>();
154			var barSUT = new Bar(bar);
155
156			barSUT.Do(new Foo());
157
158			Mock.Assert(() => bar.Do(Arg.IsAny<Foo>()));
159		}
160
161
162		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
163		public void ShouldBeAddRemoveConcreteMockItemsFromCollection()
164		{
165			var foo = Mock.Create<Foo>();
166
167			IList<Foo> list = new List<Foo>();
168
169			list.Add(foo);
170
171			if (list.Contains(foo))
172			{
173				list.Remove(foo);
174			}
175			Assert.True(list.Count == 0);
176		}
177
178		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
179		public void ShouldBeAbleToCallBaseForGenericMethod()
180		{
181			var facade = Mock.Create<TestFacade>();
182
183			Mock.Arrange(() => facade.Done<ContentItem>()).CallOriginal();
184
185			Assert.Throws<ArgumentException>(() => facade.Done<ContentItem>());
186		}
187
188		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
189		public void ShouldBeAbleToCallOrignalForOutArgMethod()
190		{
191			var foo = Mock.Create<FooOut>();
192
193			int expected = 0;
194
195			Mock.Arrange(() => foo.EchoOut(out expected)).CallOriginal();
196
197			foo.EchoOut(out expected);
198
199			Assert.Equal(10, expected);
200		}
201
202		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
203		public void ShouldAssertCallOrignalForMethodWithGenericParameter()
204		{
205			var foo = Mock.Create<FooGeneric>();
206			Mock.Arrange(() => foo.Echo<int>(10)).CallOriginal();
207			foo.Echo<int>(10);
208		}
209
210		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
211		public void ShouldPickCorrectGenericVarientInCaseOfCallOriginal()
212		{
213			var foo = Mock.Create<FooGeneric>();
214			Mock.Arrange(() => foo.Echo<int, int>(10)).CallOriginal();
215			Assert.Throws<ArgumentException>(() => foo.Echo<int, int>(10));
216		}
217
218		[TestMethod, TestCategory("Lite")]
219		public void ShouldAssertInvocationFromInsideAMockedEvent()
220		{
221			var @interface = Mock.Create<IInterface>();
222
223			Mock.Arrange(() => @interface.TheFunc()).Returns(true);
224
225			var target = new EventContainer(@interface);
226
227			Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);
228
229			Assert.True(target.Result);
230		}
231
232		[TestMethod, TestCategory("Lite")]
233		public void ShouldAssertRaiseEventAfterAMethodCallFromDifferentMock()
234		{
235			var @interface = Mock.Create<IInterface>();
236			var @extended = Mock.Create<IInterfaceExtended>();
237			var target = new EventContainer(@interface);
238
239			Mock.Arrange(() => @interface.TheFunc()).Returns(true);
240			Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);
241
242			@extended.TheFunc();
243
244			Mock.Raise(() => @interface.TheEvent += null, EventArgs.Empty);
245
246			Assert.True(target.NumberOfTimesCalled == 2);
247		}
248
249		[TestMethod, TestCategory("Lite"),]
250		public void ShouldBeToSubscribeEventForStrictMock()
251		{
252			new EventContainer(Mock.Create<IInterface>(Behavior.Strict));
253		}
254
255		[TestMethod, TestCategory("Lite")]
256		public void ShouldNotThrowExceptionForDecimalTypeThatHasMultipleImplicitMethods()
257		{
258			var foo = Mock.Create<TestBase>();
259			decimal value = 1;
260			Mock.Arrange(() => foo.SetValue(value)).MustBeCalled();
261
262			foo.SetValue(value);
263
264			Mock.Assert(foo);
265		}
266
267		public abstract class TestBase
268		{
269			public virtual decimal Value { get; set; }
270
271			public virtual void SetValue(decimal newValue)
272			{
273				Value = newValue;
274			}
275		}
276
277		public class EventContainer
278		{
279			public bool Result = false;
280
281			private IInterface @interface = null;
282
283			public int NumberOfTimesCalled { get; set; }
284
285			public EventContainer(IInterface i)
286			{
287				this[email protected] = i;
288				this[email protected] += new EventHandler(i_TheEvent);
289			}
290
291			void i_TheEvent(object sender, EventArgs e)
292			{
293				this.Result = this[email protected]();
294				this.NumberOfTimesCalled++;
295			}
296		}
297
298		public interface IInterface
299		{
300			event EventHandler TheEvent;
301			bool TheFunc();
302		}
303
304		public interface IInterfaceExtended
305		{
306			bool TheFunc();
307		}
308
309		public class FooOut
310		{
311			public virtual void EchoOut(out int argOut)
312			{
313				argOut = 10;
314			}
315		}
316
317		public class FooGeneric
318		{
319			public virtual void Echo<TKey>(TKey key)
320			{
321
322			}
323			public virtual void Echo<TKey, TKey2>(TKey key)
324			{
325				throw new ArgumentException();
326			}
327		}
328
329		public class ContentItem : IFacade<ContentItem>
330		{
331
332		}
333
334		public interface IFacade<TParaentFacade> { }
335
336		public class TestFacade
337		{
338			public virtual TParentFacade Done<TParentFacade>() where TParentFacade : class, IFacade<TParentFacade>
339			{
340				throw new ArgumentException("My custom error");
341			}
342		}
343
344#if !COREFX
345
346		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
347		public void ShouldNotImplementInternalVirtualMemberUsingProxyWhenNotVisible()
348		{
349			var context = Mock.Create<Telerik.JustMock.DemoLibSigned.DummyContext>();
350			Assert.NotNull(context);
351		}
352
353
354		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
355		public void ShouldCreateMockForFrameWorkClassWithInternalCtor()
356		{
357			var downloadDateCompleted = Mock.Create<DownloadDataCompletedEventArgs>();
358			Assert.NotNull(downloadDateCompleted != null);
359		}
360
361		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
362		public void ShouldAssertStreamMocking()
363		{
364
365#if NETCORE
366			Telerik.JustMock.Setup.AllowedMockableTypes.Add<System.IO.Stream>();
367#endif
368
369			var stream = Mock.Create<Stream>();
370
371			Mock.Arrange(() => stream.Seek(0, SeekOrigin.Begin)).Returns(0L);
372
373			var position = stream.Seek(0, SeekOrigin.Begin);
374
375			Assert.Equal(0, position);
376
377			Mock.Arrange(() => stream.Flush()).MustBeCalled();
378			Mock.Arrange(() => stream.SetLength(100)).MustBeCalled();
379
380			Assert.Throws<AssertionException>(() => Mock.Assert(stream));
381
382			stream.Flush();
383			stream.SetLength(100);
384
385			Mock.Assert(stream);
386		}
387#endif
388
389		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
390		public void ShouldMockMultipleInterfaceOnASingleMock()
391		{
392			var foo = Mock.Create<IFooDispose>();
393			var iDisposable = foo as IDisposable;
394
395			bool called = false;
396
397			Mock.Arrange(() => iDisposable.Dispose()).DoInstead(() => called = true);
398
399			iDisposable.Dispose();
400
401			Assert.True(called);
402		}
403
404		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
405		public void ShouldMockClassWithInterfaceConstraints()
406		{
407			var container = Mock.Create<FakeContainer<Product>>();
408
409			Mock.Arrange(() => container.Do<Product>()).MustBeCalled();
410
411			container.Do<Product>();
412		}
413
414		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
415		public void ShouldMockMethodCallWithObjectArgumentWithMatcher()
416		{
417			var container = Mock.Create<IContainer>();
418			var called = false;
419
420			Mock.Arrange(() => container.Resolve(Arg.IsAny<IDatabase>())).DoInstead(() => called = true);
421
422			var database = Mock.Create<IDatabase>();
423
424			container.Resolve(database);
425
426			Assert.True(called);
427		}
428
429		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
430		public void ShouldBeAbleToAssertNestedSetupDirectly()
431		{
432			var outer = Mock.Create<FooOuter>();
433			var inner = Mock.Create<FooInter>();
434
435			Mock.Arrange(() => outer.GetInnerClass()).Returns(inner);
436			Mock.Arrange(() => inner.Value).Returns(10).MustBeCalled();
437
438			Assert.Throws<AssertionException>(() => Mock.Assert(() => outer.GetInnerClass().Value));
439		}
440
441		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
442		public void ShouldNotCreateNestedMockWhenReturningCallBackForGenericCall()
443		{
444			Product product1 = new Product();
445			Product product2 = new Product();
446
447			Queue<Product> products = new Queue<Product>();
448
449			products.Enqueue(product1);
450			products.Enqueue(product2);
451
452			var context = Mock.Create<IDataContext>();
453
454			Mock.Arrange(() => context.Get<Product>()).Returns(() => products.Dequeue());
455
456			Assert.True(context.Get<Product>().Equals(product1));
457			Assert.True(context.Get<Product>().Equals(product2));
458		}
459
460
461		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
462		public void ShouldReturnNullWhenSpecifiedByReturn()
463		{
464			var exmpleMock = Mock.Create<IExampleInterface>();
465
466			Mock.Arrange(() => exmpleMock.GetMeAllFoos()).Returns((IList<IFoo>)null);
467
468			Assert.Null(exmpleMock.GetMeAllFoos());
469		}
470
471#if !COREFX
472
473		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
474		public void ShouldMockInternalMemberFromBaseClass()
475		{
476			var id = Guid.NewGuid();
477
478			var manager = Mock.Create<IContentManager>();
479			var facade = Mock.Create<BlogFacade>(Behavior.CallOriginal);
480
481			Mock.Arrange(() => facade.ContentManager).Returns(manager);
482
483			Mock.Arrange(() => manager.GetItem(Arg.IsAny<Type>(), Arg.AnyGuid))
484				.Returns(new Product()).MustBeCalled();
485
486			facade.LoadItem(id);
487
488			Mock.Assert(facade.ContentManager);
489		}
490
491#endif
492
493
494		[TestMethod, TestCategory("Lite")]
495		public void ShouldAssertSetupWithObjectArrayAsParams()
496		{
497			var foo = Mock.Create<Foo<Product>>();
498
499			const int expected = 1;
500
501			Mock.Arrange(() => foo.GetByKey(expected)).Returns(() => null).MustBeCalled();
502
503			foo.GetByKey(expected);
504
505			Mock.Assert(foo);
506		}
507
508		[TestMethod, TestCategory("Lite")]
509		public void ShouldNotInstantiatePropertyWhenSetExplicitly()
510		{
511			var foo = Mock.Create<NestedFoo>();
512			var actual = new FooThatFails(string.Empty);
513
514			Mock.Arrange(() => foo.FooThatFailsOnCtor).Returns(actual);
515
516			Assert.Equal(foo.FooThatFailsOnCtor, actual);
517		}
518
519
520		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
521		public void ShouldBeAbleToCreateMockWithInternalCtor()
522		{
523			var expected = "hello";
524
525			var foo = Mock.Create<FooInternal>(x =>
526			{
527				x.CallConstructor(() => new FooInternal("hello"));
528				x.SetBehavior(Behavior.CallOriginal);
529			});
530
531			Assert.Equal(foo.Name, expected);
532		}
533
534		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
535		public void ShouldExecuteEqualsDuringAssertWithMockArgument()
536		{
537			var foo = Mock.Create<FooAbstract>();
538			var fooWork = Mock.Create<FooWork>();
539
540			fooWork.DoWork(foo);
541
542			Mock.Assert(() => fooWork.DoWork(foo));
543		}
544
545		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
546		public void ShouldAssertMultipleOccurrencesSeparatelyForAssertAll()
547		{
548			IFileReader fileReader = Mock.Create<IFileReader>(Behavior.Strict);
549
550			Mock.Arrange(() => fileReader.FileExists(@"C:\Foo\Categories.txt")).Returns(false).OccursOnce();
551			Mock.Arrange(() => fileReader.ReadFile(@"C:\Foo\Categories.txt")).IgnoreArguments().OccursNever();
552
553			fileReader.FileExists(@"C:\Foo\Categories.txt");
554
555			Mock.Assert(fileReader);
556		}
557
558		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
559		public void ShouldAssertOccurenceWhenCombinedWithNoSetupCalls()
560		{
561			string userName = "Bob";
562			string password = "Password";
563
564			ILoginService service = Mock.Create<ILoginService>();
565			Mock.Arrange(() => service.ValidateUser(userName, password)).Returns(5).OccursOnce();
566			Mock.Arrange(() => service.ValidateUser("foo", "bar")).OccursNever();
567
568			SecurityHandler handler = new SecurityHandler(service);
569
570			bool loggedIn = handler.LoginUser(userName, password);
571
572			Assert.True(loggedIn);
573			Assert.Equal(handler.UserID, 5);
574
575			Mock.Assert(service);
576		}
577
578		public class NestedFoo
579		{
580			public virtual FooThatFails FooThatFailsOnCtor { get; set; }
581		}
582
583		public class FooThatFails
584		{
585			public FooThatFails(string message)
586			{
587
588			}
589
590			public FooThatFails()
591			{
592				throw new ArgumentException("Failed");
593			}
594		}
595
596		public class SecurityHandler
597		{
598			private readonly ILoginService _service;
599			public int UserID { get; internal set; }
600
601			public SecurityHandler(ILoginService service)
602			{
603				_service = service;
604				_service.DatabaseName = "NorthWind";
605			}
606
607
608			public bool LoginUser(string userName, string password)
609			{
610				UserID = _service.ValidateUser(userName, password);
611				return (UserID != 0);
612			}
613		}
614
615		public interface ILoginService
616		{
617			int ValidateUser(string userName, string password);
618
619
620			string DatabaseName { get; set; }
621
622			event EventHandler UserLoggedOnEvent;
623			event EventHandler DatabaseChangedEvent;
624		}
625
626		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
627		public void ShouldAssertCallOriginalOnOverloadsViaProxy()
628		{
629			var dummyExpression = Mock.Create<DummyExpression>(Behavior.CallOriginal);
630			dummyExpression.Evaluate(10);
631		}
632
633		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
634		public void ShouldAssertSetPropertyOccurenceForAnyValue()
635		{
636			var foo = Mock.Create<IFoo>();
637
638			Mock.ArrangeSet<IFoo>(() => foo.EffectiveFrom = DateTime.Now).IgnoreArguments();
639
640			foo.EffectiveFrom = DateTime.Now;
641
642			Assert.Throws<AssertionException>(() => Mock.AssertSet(() => foo.EffectiveFrom = Arg.IsAny<DateTime>(), Occurs.Never()));
643		}
644
645		[TestMethod, TestCategory("Lite")]
646		public void ShouldAssertWithByteArrayArguments()
647		{
648			ITestInterface ti = Mock.Create<ITestInterface>();
649
650			byte[] newimagebytes = new byte[1] { 4 };
651
652			ti.DoStuff(newimagebytes);
653
654			Mock.Assert(() => ti.DoStuff(newimagebytes), Occurs.AtLeastOnce());
655		}
656
657		[TestMethod, TestCategory("Lite"), TestCategory("Misc")]
658		public void UsingShouldNotInterfereWithPreOccurrence()
659		{
660			var fakereader = Mock.Create<IXmlReader>();
661
662			Mock.Arrange(() => fakereader.EOF).Returns(true).OccursOnce();
663			Mock.Arrange(() => fakereader.ReadOuterXml()).Returns("aaa").OccursNever();
664
665			using (fakereader)
666			{
667				if (!fakereader.EOF)
668				{
669					string s = fakereader.ReadOuterXml();
670				}
671			}
672
673			Mock.Assert(fakereader);
674		}
675
676		[TestMethod, TestCategory("Lite")]
677		public void ShouldAssertNewGuIdArgumentForSpecificValue()
678		{
679			var localPersister = Mock.Create<IProcessDataPersister>();
680
681			Mock.Arrange(() => localPersister.GetTaskWarnings(new Guid("{00000000-0000-0000-0001-000000000003}")))
682				.Returns(new List<TaskWarning>() { new TaskWarning(new Guid("{00000000-0000-0000-0001-000000000003}")) { EscalationLevel = 0 } })
683				.MustBeCalled();
684
685			var list = localPersister.GetTaskWarnings(new Guid("{00000000-0000-0000-0001-000000000003}"));
686
687			Assert.NotNull(list);
688			Mock.Assert(localPersister);
689		}
690
691		[TestMethod, TestCategory("Lite"),]
692		public void ShouldConfirmMockingClassWithMethodHidingItsVirtualBase()
693		{
694			var child = Mock.Create<ChildClass>();
695			Assert.NotNull(child);
696		}
697
698		public class ChildClass : ParentClass, IElement
699		{
700			public new bool CanWriteProperty(string propertyName)
701			{
702				throw new NotImplementedException();
703			}
704		}
705
706		public interface IElement
707		{
708			bool CanWriteProperty(string propertyName);
709		}
710
711		public class ParentClass
712		{
713			public virtual bool CanWriteProperty(string propertyName)
714			{
715				return false;
716			}
717		}
718
719		public class TaskWarning
720		{
721			private Guid guid;
722
723			public TaskWarning(Guid guid)
724			{
725				this.guid = guid;
726			}
727			public int EscalationLevel { get; set; }
728		}
729
730		public interface IProcessDataPersister
731		{
732			List<TaskWarning> GetTaskWarnings(Guid taskId);
733		}
734
735		public interface ITestInterface
736		{
737			void DoStuff(byte[] bytes);
738		}
739
740		public class Foo<TEntity>
741		{
742			public virtual TEntity GetByKey(params object[] keyValues)
743			{
744				return default(TEntity);
745			}
746		}
747
748		public class ContentFacade<TItem>
749		{
750			public virtual IContentManager ContentManager { get; set; }
751
752			internal virtual void LoadItem(Guid guid)
753			{
754				var product = this.ContentManager.GetItem(typeof(TItem), guid);
755
756				if (product == null)
757				{
758					throw new ArgumentException("Invalid object");
759				}
760			}
761		}
762
763		public class BlogFacade : ContentFacade<Product>
764		{
765
766		}
767
768		public interface IContentManager
769		{
770			object GetItem(Type itemType, Guid id);
771		}
772
773		public interface IXmlReader : IDisposable
774		{
775			bool EOF { get; }
776			string ReadOuterXml();
777		}
778
779		public class DummyExpression
780		{
781			public virtual object Evaluate(int arg1, string myString)
782			{
783				return null;
784			}
785
786			public virtual object Evaluate(int arg1)
787			{
788				return null;
789			}
790		}
791
792		public interface IFileReader
793		{
794			bool FileExists(string pathAndFile);
795			IList<string> ReadFile(string pathAndFile);
796		}
797
798		public enum FooWorkType
799		{
800			Go = 0,
801			Went
802		}
803
804		public class FooWork
805		{
806			public virtual void DoWork(FooAbstract foo)
807			{
808
809			}
810		}
811
812		public abstract class FooAbstract : IEquatable<FooAbstract>
813		{
814			public abstract FooWorkType Type { get; }
815
816			public override int GetHashCode()
817			{
818				return base.GetHashCode();
819			}
820
821			public override bool Equals(object obj)
822			{
823				return this.Equals(obj as FooAbstract);
824			}
825
826			public bool Equals(FooAbstract other)
827			{
828				if (object.ReferenceEquals(this, other))
829				{
830					return true;
831				}
832				return this.Type == other.Type;
833			}
834		}
835
836		public class FooInternal
837		{
838			internal FooInternal(string name)
839			{
840				this.name = name;
841			}
842
843			public string Name { get { return name; } }
844
845			private string name;
846		}
847
848		public interface IExampleInterface
849		{
850			IList<IFoo> GetMeAllFoos();
851		}
852
853		public interface IDataContext
854		{
855			T Get<T>();
856		}
857
858		public class FooOuter
859		{
860			public virtual FooInter GetInnerClass()
861			{
862				return null;
863			}
864		}
865
866		public class FooInter
867		{
868			public virtual int Value { get; set; }
869		}
870
871
872		public class Product : IContainer
873		{
874
875			#region IContainer Members
876
877			public void Resolve(object obj)
878			{
879				throw new NotImplementedException();
880			}
881
882			#endregion
883		}
884
885		public interface IDatabase
886		{
887
888		}
889
890		public interface IContainer
891		{
892			void Resolve(object obj);
893		}
894
895		public class FakeContainer<T> where T : class
896		{
897			public virtual void Do<TSub>() where TSub : IContainer
898			{
899				throw new NotImplementedException();
900			}
901		}
902
903
904		public interface IFooDispose : IDisposable
905		{
906			void Do();
907		}
908
909		public class Foo : IFoo
910		{
911			#region IFoo Members
912
913			public int Get(SomeClass<string> id)
914			{
915				throw new NotImplementedException();
916			}
917
918			public DateTime EffectiveFrom { get; set; }
919
920			public long Id
921			{
922				get
923				{
924					throw new NotImplementedException();
925				}
926				set
927				{
928					throw new NotImplementedException();
929				}
930			}
931
932			public void SetIt(long it)
933			{
934				throw new NotImplementedException();
935			}
936
937			#endregion
938
939		}
940
941		public interface IBar
942		{
943			void Do(IFoo foo);
944		}
945
946		public class Bar
947		{
948			public Bar(IBar bar)
949			{
950				this.bar = bar;
951			}
952
953			public void Do(IFoo foo)
954			{
955				bar.Do(foo);
956			}
957
958			private IBar bar;
959		}
960
961
962		public interface IDummy
963		{
964			// dummy interface.
965		}
966
967		public interface ISomething<T>
968		{
969			void DoSomething<U>() where U : T;
970		}
971
972
973		public struct SomeClass<T> // Struct just to avoid having to implement Equals/GetHashCode
974		{
975			public static implicit operator SomeClass<T>(T t)
976			{
977				return new SomeClass<T>();
978			}
979
980			public static SomeClass<T> From(T t)
981			{
982				return t;
983			}
984		}
985
986		public interface IFoo
987		{
988			int Get(SomeClass<string> id);
989			long Id { get; set; }
990			DateTime EffectiveFrom { get; set; }
991			void SetIt(long it);
992		}
993
994		public interface IFooPtr
995		{
996			IntPtr Get(string input);
997		}
998
999		public interface IMyClass
1000		{
1001			IEnumerable<string> GetValuesSince(DateTime since);
1002		}
1003	}
1004}
1005
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)