static void Main(string[] args) { QualityThought.Samples.DotNetBatch1.NamespaceLibrary.Sub1.Test1 test1 = new NamespaceLibrary.Sub1.Test1(); Test2 test2 = new Test2(); QualityThought.Samples.DotNetBatch1.NamespaceLibrary1.Test2 test2FromOtherAssembly = new QualityThought.Samples.DotNetBatch1.NamespaceLibrary1.Test2(); NamespaceLibrary1.Test2 testUsingAlias = new NamespaceLibrary1.Test2(); }
public static void Main() { object test1 = new Test1(); object test2 = new Test2(); // Test valid casts System.Console.WriteLine((Test1)test1 != null); System.Console.WriteLine((Test1)test2 != null); System.Console.WriteLine((Test2)test2 != null); System.Console.WriteLine((ITest)test2 != null); try { System.Console.WriteLine((Test2)test1 != null); } catch (System.InvalidCastException e) { System.Console.WriteLine("InvalidCast"); } try { System.Console.WriteLine((ITest)test1 != null); } catch (System.InvalidCastException e) { System.Console.WriteLine("InvalidCast"); } }
static void Main(string[] args) { //System.Globalization.CultureInfo. Test1 t1 = new Test1(); Test2 t2 = new Test2(); t1.a = new List<List<float>>(); t1.a.Add(new List<float>()); t1.a.Add(new List<float>()); t1.a[0].Add(1); t1.a[1].Add(2); t2.a = t1.a; t1.a.Clear(); t1.a.Add(new List<float>()); t1.a.Add(new List<float>()); t1.a[0].Add(11); t1.a[1].Add(22); //t1.a.Add(2); foreach (var t in new Sample()) Console.WriteLine(t); //Console.ReadKey(); pmClasses.Collection cc = new pmClasses.Collection(5); cc.File.Load_TextFile("E:\\#Shared#\\43-219_pasha.exp(002)_s_pr_SF(T).txt" , null); cc.File.Save_TextFile("E:\\#Shared#\\43-219_pasha.exp(002)_s_pr_SF(T)_text.txt", null); }
private static void TestArgumentNullCheckSpeed(int numberOfCalls) { var test1 = new Test1(); var test2 = new Test2(); var normalNullParameterCheckingTesting = new NormalNullParameterCheckingTesting(); var stopWatch = new Stopwatch(); stopWatch.Start(); for (var i = 0; i < numberOfCalls; i++) { normalNullParameterCheckingTesting.TestWith1(test1); } Console.WriteLine("Normal null checking speed with 1 Test parameter: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); for (var i = 0; i < numberOfCalls; i++) { normalNullParameterCheckingTesting.TestWith2(test1, test2); } Console.WriteLine("Normal null checking speed with 2 Test parameter: " + stopWatch.ElapsedMilliseconds); }
public static void Main() { Test1 test1 = new Test1(); Test1 test2 = new Test2(); System.Console.WriteLine(test1.A()); System.Console.WriteLine(test2.A()); }
public static void Main() { var test = new Test2(); test.A = "Test"; test.B = 32; System.Console.WriteLine(test.A); System.Console.WriteLine(test.B); }
public static void Main() { //Force static initialization order var test1 = new Test1(); var test2 = new Test2(); Test1.Method1(); //C# and D have different order of static initialization ... D initializes all statics at once, C# does on demand (Mono) // Test1.Method1(); //var test2 = new Test2(); }
public static void Main() { ITest test1 = new Test1(); ITest test2 = new Test2(); ITest test3 = new Test3(); ITest test4 = new Test4(); System.Console.WriteLine(test1.A()); System.Console.WriteLine(test2.A()); System.Console.WriteLine(test3.A()); System.Console.WriteLine(test4.A()); }
public void Test() { var t1 = new Test2(); var t2 = new Test2(); Container.Bind<FactoryUntyped<Test1>>().ToSingle(); Assert.That(Container.ValidateResolve<FactoryUntyped<Test1>>().IsEmpty()); var factory = Container.Resolve<FactoryUntyped<Test1>>(); var test = factory.Create(t1, 5.0f, t2); Assert.That(ReferenceEquals(test.t1, t1)); Assert.That(ReferenceEquals(test.t2, t2)); }
protected override void Init() { _IJSOBuilder = new CefV8_Factory(_WebView); _ICSharpMapper = Substitute.For<IJSCBridgeCache>(); _ICSharpMapper.GetCached(Arg.Any<object>()).Returns((IJSCSGlue)null); _ConverTOJSO = new CSharpToJavascriptMapper(_WebView, new TestIUIDispatcher(), _ICSharpMapper); _Test = new TestClass { S1 = "string", I1 = 25 }; _Tests = new List<TestClass>(); _Tests.Add(new TestClass() { S1 = "string1", I1 = 1 }); _Tests.Add(new TestClass() { S1 = "string2", I1 = 2 }); _Test2 = new Test2() { T1 = _Test, T2 = _Test }; _Tests_NG = new ArrayList(); _Tests_NG.Add(_Tests[0]); _Tests_NG.Add(_Tests[0]); }
static void Main() { Test1 a = new Test1(); Test2 a1 = new Test2(); Test3 a2 = new Test3(); Mutex wait = new Mutex(false); MyThreadPool pool = new MyThreadPool(5, wait); for (int I = 0; I < 20; I++) pool.PutInQueue(new Test1()); // pool.PutInQueue(a); //pool.PutInQueue(a1); //pool.PutInQueue(a2); Thread.Sleep(100); Console.ReadKey(); pool.EndMyThreadPool(); Console.ReadKey(); }
public Test_ConvertToJSO() { _WebView = WebCore.CreateWebView(500, 500, WebViewType.Offscreen); _IJSOBuilder = new LocalBuilder(_WebView); _ICSharpMapper = Substitute.For<IJSCBridgeCache>(); _ICSharpMapper.GetCached(Arg.Any<object>()).Returns((IJSCSGlue)null); _ConverTOJSO = new CSharpToJavascriptMapper(_IJSOBuilder, _ICSharpMapper); _Test = new Test { S1 = "string", I1 = 25 }; _Tests = new List<Test>(); _Tests.Add(new Test() { S1 = "string1", I1 = 1 }); _Tests.Add(new Test() { S1 = "string2", I1 = 2 }); _Test2 = new Test2() { T1 = _Test, T2 = _Test }; _Tests_NG = new ArrayList(); _Tests_NG.Add(_Tests[0]); _Tests_NG.Add(_Tests[0]); }
public void Get_ClassWithMixpanelPropertyAttr_Parsed() { var test = new Test2 { Property1 = 1M, Property2 = "val", Property3 = _now }; var outDic = _digger.Get(test); Assert.That(outDic.Count, Is.EqualTo(3)); Assert.That(outDic["property_1"].PropertyNameSource, Is.EqualTo(PropertyNameSource.MixpanelName)); Assert.That(outDic["property_1"].Value, Is.EqualTo(1M)); Assert.That(outDic["Property2"].PropertyNameSource, Is.EqualTo(PropertyNameSource.Default)); Assert.That(outDic["Property2"].Value, Is.EqualTo("val")); Assert.That(outDic["property_3"].PropertyNameSource, Is.EqualTo(PropertyNameSource.MixpanelName)); Assert.That(outDic["property_3"].Value, Is.EqualTo(_now)); }
public static void Main() { object test1 = new Test1(); object test2 = new Test2(); System.Console.WriteLine(test1 is Test1 ? "True" : "False"); System.Console.WriteLine(test1 is Test2); System.Console.WriteLine(test1 is ITest); System.Console.WriteLine(test2 is Test1); System.Console.WriteLine(test2 is Test2); System.Console.WriteLine(test2 is ITest); System.Console.WriteLine(test1 as Test1 != null ? "True" : "False"); System.Console.WriteLine(test1 as Test2 != null); System.Console.WriteLine(test1 as ITest != null); System.Console.WriteLine(test2 as Test1 != null); System.Console.WriteLine(test2 as Test2 != null); System.Console.WriteLine(test2 as ITest != null); }
public void InsertMulitFor(List <Test2> itemList) { using (var db = GetConnection()) { ////var ecount = db.Query<Test2>().ToList().Count; for (var i = 0; i < itemList.Count; i++) { var item = new Test2() { Name = itemList[i] + i.ToString() }; db.Insert(item); } } }
protected override void Init() { _ICSharpMapper = Substitute.For <IJavascriptSessionCache>(); _GlueFactory = new GlueFactory(null, null); _ICSharpMapper.GetCached(Arg.Any <object>()).Returns((IJSCSGlue)null); _javascriptFrameworkManager = Substitute.For <IJavascriptFrameworkManager>(); _HTMLViewContext = new HTMLViewContext(WebBrowserWindow, GetTestUIDispacther(), _javascriptFrameworkManager, null, _Logger); _ConverTOJSO = new CSharpToJavascriptConverter(WebBrowserWindow, _ICSharpMapper, _GlueFactory, _Logger); _Test = new TestClass { S1 = "string", I1 = 25 }; _Tests = new List <TestClass> { new TestClass() { S1 = "string1", I1 = 1 }, new TestClass() { S1 = "string2", I1 = 2 } }; _Test2 = new Test2() { T1 = _Test, T2 = _Test }; _Tests_NG = new ArrayList(); _Tests_NG.Add(_Tests[0]); _Tests_NG.Add(_Tests[0]); _CircularSimple = new Circular1(); _CircularSimple.Reference = _CircularSimple; _CircularComplex = new Circular2(); var circularChild = new Circular2 { Reference = _CircularComplex }; _CircularComplex.List.Add(circularChild); }
public void when_out_of_order() { Init(); var singletonType2 = typeof(Test2); var singleton2 = new Test2(); InitTestSingleton(singletonType2, singleton2); var singletonType1 = typeof(Test1); var singleton1 = new Test1(); InitTestSingleton(singletonType1, singleton1, typeof(ITest1).Name); testObject.InstantiateSingletons(mockFactory.Object); Assert.Equal(2, testObject.Singletons.Length); Assert.Equal(singleton1, testObject.Singletons[0]); Assert.Equal(singleton2, testObject.Singletons[1]); }
public string TestInsert() { var test1Model = new Test1() { Name = "product1", Test2s = new List <Test2>() }; for (int i = 0; i < 3; i++) { var test2Model = new Test2() { Name = "product Variant ." + i }; test1Model.Test2s.Add(test2Model); } _dataContext.Add(test1Model); _dataContext.SaveChanges(); return("test"); }
public string TestUpdate() { var test1Model = _dataContext.Test1s.Find(1); _dataContext.Entry(test1Model).Collection(s => s.Test2s).Load(); test1Model.Name = "update test"; foreach (var item in test1Model.Test2s) { item.Name = "update test 1"; } var test2NewModel = new Test2 { Name = "new Inserted row 2" }; test1Model.Test2s.Add(test2NewModel); _dataContext.Update(test1Model); _dataContext.SaveChanges(); return("test"); }
public void PrintAFew() { Assert(test.Print().Equals("ANOTHER PRINT"), "Test wasn't equal to \"ANOTHER PRINT\""); Test2.PrintName(); test3.PrintName(); test4.Print(); test5.Print(); test6.Print(); Debug.Log(myString); Debug.Log(myString2); Debug.Log(this.num); Debug.Log(FloatTest); Debug.Log(aString); test3.ChangeName("CHANGED"); signal.Dispatch(); }
public void Test() { //协变:让ITest<Fruit> list = new Test<Apple>();这类代码成立! ITest <Fruit> list = new Test <Apple>(); PrintFruit(list); IEnumerable <Fruit> fruits = new List <Apple>() { new Apple() }; //List<Fruit> f = new List<Apple>(); Print(fruits); //逆变:让ITest<Apple> test = new Test<Fruit>();这类代码成立! ITest2 <Apple> test = new Test2 <Fruit>(); test.Set(new Apple()); }
private static void Main(string[] args) { Test1 t1 = new Test1(100); Console.Write("初始"); t1.DisplayValue(); Console.Write("修改后"); int x = t1.value; x = 200; t1.DisplayValue(); Test2 t2 = new Test2(100); Console.Write("初始"); t2.DisplayValue(); Console.Write("修改后"); ref int y = ref t2.value;
protected override void Init() { _ICSharpMapper = Substitute.For<IJavascriptSessionCache>(); _JSCommandFactory = Substitute.For<IJSCommandFactory>(); _ICSharpMapper.GetCached(Arg.Any<object>()).Returns((IJSCSGlue)null); _javascriptFrameworkManager = Substitute.For<IJavascriptFrameworkManager>(); _HTMLViewContext = new HTMLViewContext(_WebView, GetTestUIDispacther(), _javascriptFrameworkManager, null, _Logger); _ConverTOJSO = new CSharpToJavascriptConverter(_HTMLViewContext, _ICSharpMapper, _JSCommandFactory, _Logger); _Test = new TestClass { S1 = "string", I1 = 25 }; _Tests = new List<TestClass> { new TestClass() { S1 = "string1", I1 = 1 }, new TestClass() { S1 = "string2", I1 = 2 } }; _Test2 = new Test2() { T1 = _Test, T2 = _Test }; _Tests_NG = new ArrayList(); _Tests_NG.Add(_Tests[0]); _Tests_NG.Add(_Tests[0]); }
static void Main(string[] args) { Test1 t1 = new Test1(); t1.Name = "alexi"; t1.Number = 100; Serialize(t1, "t1.txt"); Test2 t2 = new Test2(); t2.name = "jonno"; t2.Name = "jonno"; t2.Serialized = false; Serialize(t2, "t2.txt"); Test1 t3 = new Test1(); t3 = Deserialize <Test1>("t1.txt"); //??? Serialize(t3, "t3.txt"); }
public void GetHandler_TargetInheritedByBase_ReturnsHandler() { // ARRANGE var testHandlerMock = new Mock <IActUsageHandler>(); testHandlerMock.SetupGet(x => x.TargetType).Returns(typeof(ITest1)); var testHandler = testHandlerMock.Object; var selector = new ActUsageHandlerSelector(new IActUsageHandler[] { testHandler }); var targetObject = new Test2(); // ACT var factHandler = selector.GetHandler(targetObject); // ASSERT factHandler.Should().Be(testHandler); }
public void TestDuplexChannels() { string pipeName = "Vkm.TestPipe3"; var service = new Test1(); var callback = new Test2(); var master = new IntercomDuplexChannel <Test1, Test2>(service, pipeName, true); var slave = new IntercomDuplexChannel <Test2, Test1>(callback, pipeName, false); Assert.AreEqual(0, service.MethodCallCount); var r = slave.Execute(nameof(Test1.Do), 5, 1); Assert.AreEqual(1, service.MethodCallCount); Assert.AreEqual(5, r); Assert.AreEqual(0, callback.MethodCallCount); r = master.Execute(nameof(Test2.Do)); Assert.AreEqual(1, callback.MethodCallCount); Assert.AreEqual(string.Empty, r); }
static void Test1() { var temp = new Test(Matts); var temp2 = new Test2(Matts); Console.WriteLine(temp2("test")); Test2 temp3 = Matts; Console.WriteLine(temp3("test")); Test2 temp4 = (string whatever) => whatever; Console.WriteLine(temp4("test11")); Test3 temp5 = () => { Console.WriteLine("first"); }; temp5 += delegate { Console.WriteLine("ehh1"); }; { Console.WriteLine("ehh2"); }; { Console.WriteLine("ehh3"); }; temp5 += () => { Console.WriteLine("ehhh6"); }; temp5(); Test4 temp6 = delegate { Console.WriteLine("test4"); }; temp6(1, "dfdf"); }
public void when_out_of_order() { Init(); var singletonType2 = typeof(Test2); var singleton2 = new Test2(); InitTestSingleton(singletonType2, singleton2); var singletonType1 = typeof(Test1); var singleton1 = new Test1(); InitTestSingleton(singletonType1, singleton1, typeof(ITest1).Name); testObject.InstantiateSingletons(mockFactory.Object); singleton2.Test1 = singleton1; testObject.Shutdown(); Assert.True(singleton2.ShutdownPerformedCorrectly); }
public void Clone_Deep_Clone_Deep_Nested_Mixed_Objects_Clones_Array_With_Mutual_Ref_Object() { var obj = new Test2 { a = 1 }; var list = new object[] { new { b = obj }, new { b = obj } }; var clone = R.Clone(list); var dynamicList = (dynamic)list; var excpected = new { a = 1 }.ToExpando(); Assert.AreEqual(dynamicList[0].b, dynamicList[1].b); Assert.AreEqual(clone[0].b, clone[1].b); Assert.AreNotEqual(clone[0].b, dynamicList[0].b); Assert.AreNotEqual(clone[1].b, dynamicList[1].b); DynamicAssert.AreEqual(clone[0].b, excpected); DynamicAssert.AreEqual(clone[1].b, excpected); obj.a = 2; DynamicAssert.AreEqual(clone[0].b, excpected); DynamicAssert.AreEqual(clone[1].b, excpected); }
public void BoxedPrimitives() { var x = new Test2 { a = byte.MaxValue, b = sbyte.MaxValue, c = short.MaxValue, d = ushort.MaxValue, e = char.MaxValue, f = int.MaxValue, g = uint.MaxValue, h = long.MaxValue, i = ulong.MaxValue, j = true, k = float.Epsilon, l = double.Epsilon, m = decimal.MaxValue, n = Guid.Parse("12341234-1234-1234-1234-123412341234") }; RoundTrip(x); }
// This overload of AccessPrivateMethod emits a dynamic method that takes // a string and returns the first character, using a private field of the // String class. The dynamic method skips JIT visiblity checks. public void AccessPrivateMethod() { //<Snippet16> DynamicMethod meth = new DynamicMethod("", typeof(char), new Type[] { typeof(String) }, true); //</Snippet16> // Get a MethodInfo for the 'get' accessor of the private property. PropertyInfo pi = typeof(System.String).GetProperty( "FirstChar", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo pvtMeth = pi.GetGetMethod(true); // Get an ILGenerator and emit a body for the dynamic method. ILGenerator il = meth.GetILGenerator(); // Load the first argument, which is the target string, onto the // execution stack, call the 'get' accessor to put the result onto // the execution stack, and return. il.Emit(OpCodes.Ldarg_0); il.EmitCall(OpCodes.Call, pvtMeth, null); il.Emit(OpCodes.Ret); // Create a delegate that represents the dynamic method, and // invoke it. try { Test2 t = (Test2)meth.CreateDelegate(typeof(Test2)); char first = t("Hello, World!"); Console.WriteLine("{0} is the first character.", first); } catch (Exception ex) { Console.WriteLine("{0} was thrown when the delegate was compiled.", ex.GetType().Name); } }
public void InsertIfNot(int count, string prefix) { using (var db = GetConnection()) { var ecount = DapperLambdaExt.Query <Test2>(db, null).ToList().Count; if (count > ecount) { var waitInsertcount = count - ecount; for (var i = 0; i < waitInsertcount; i++) { var item = new Test2() { Name = prefix + i.ToString() }; DapperLambdaExt.Insert(db, item); } } } }
void m1() { int i1; X x1; Color c1; Test2 t2; Object o1; // Value type creation using default constructors. i1 = new int(); x1 = new X(); c1 = new Color(); // Value type creation using explicit constructors. x1 = new X(3); // Object creation. t2 = new Test2(); t2 = new Test2(3); t2 = new Test2(3L); o1 = new Object(); }
public static void DoTestWithSerialization() { Console.WriteLine("----- JsonConvertTest.DoTestWithSerialization -----"); Test1 t1 = new Test1() { A = 1, B = 2, C = 3 }; Test2 t2 = new Test2() { A = 2, B = 4, C = 6 }; Test3 t3 = new Test3() { A = 3, B = 6, C = 9 }; string jsonString1 = JsonConvert.SerializeObject(t1); Console.WriteLine("Test1 对象转换为 Json 字符串:\n{0}", jsonString1); string jsonString2 = JsonConvert.SerializeObject(t2); Console.WriteLine("Test2 对象转换为 Json 字符串:\n{0}", jsonString2); string jsonString3 = JsonConvert.SerializeObject(t3); Console.WriteLine("Test3 对象转换为 Json 字符串:\n{0}", jsonString3); }
static void Main(string[] args) { for (int j = 0; j < 100; j++) { GC.Collect(); Stopwatch dtStart = new Stopwatch (); dtStart.Start(); Test[] pTest = new Test[1000000]; for (int i = 0; i < 1000000; i++) { pTest[i].array = new object[10]; } dtStart.Stop(); GC.Collect(); Console.Out.WriteLine("Struct = " + dtStart.ElapsedMilliseconds); dtStart = new Stopwatch(); dtStart.Start(); Test2[] pTest2 = new Test2[1000000]; for (int i = 0; i < 1000000; i++) { pTest2[i] = new Test2(); } dtStart.Stop(); GC.Collect(); Console.Out.WriteLine("Class int = " + dtStart.ElapsedMilliseconds); dtStart = new Stopwatch(); dtStart.Start(); Test3[] pTest3 = new Test3[1000000]; for (int i = 0; i < 1000000; i++) { pTest3[i] = new Test3(); } dtStart.Stop(); GC.Collect(); Console.Out.WriteLine("Class no int = " + dtStart.ElapsedMilliseconds); Console.Out.WriteLine("============================="); } }
public static void Main() { object test1 = new Test1(); object test2 = new Test2(); System.Console.WriteLine(test1 is Test1 ? "True" : "False"); System.Console.WriteLine(test1 is Test2); System.Console.WriteLine(test1 is ITest); System.Console.WriteLine(test1 is ITest2); System.Console.WriteLine(test2 is Test1); System.Console.WriteLine(test2 is Test2); System.Console.WriteLine(test2 is ITest); System.Console.WriteLine(test2 is ITest2); System.Console.WriteLine(test1 as Test1 != null ? "True" : "False"); System.Console.WriteLine(test1 as Test2 != null); System.Console.WriteLine(test1 as ITest != null); System.Console.WriteLine(test1 as ITest2 != null); System.Console.WriteLine(test2 as Test1 != null); System.Console.WriteLine(test2 as Test2 != null); System.Console.WriteLine(test2 as ITest != null); System.Console.WriteLine(test2 as ITest2 != null); }
public static void Main() { object obj1 = new Test1(); object obj2 = new Test1(); // Case 1: reference type Test(obj1, obj1); Test(obj1, obj2); // Case2: value type that implements the method Test(32, 32); Test(32, 48); // Case3: value type that doesn't implement the method Test2 value1 = new Test2 { I = 16 }; Test2 value2 = new Test2 { I = 32 }; Test(value1, value1); Test(value1, value2); }
public Test6(Test2 test2) { }
public void TestException() { TypeAccessor ta = TypeAccessor.GetAccessor(typeof(Test2)); Test2 t = (Test2)ta.CreateInstance(); }
static void Init() { Test2 window = (Test2)EditorWindow.GetWindow(typeof(Test2)); window.Show(); }
public void HashPerformanceTest2() { int count = 10000; List<Test2> list = new List<Test2>(); HashSet<Test2> hs = new HashSet<Test2>(); Stopwatch sw = new Stopwatch(); Test2 f1 = null; Test2 f2 = null; sw.Start(); for (int i = 1; i <= count; i++) { Test2 tc = new Test2() { A = i + 1, B = "Petersburg" + i, ID = i }; hs.Add(tc); if (i == 5000) f1 = tc; } sw.Stop(); long r1 = sw.ElapsedTicks; sw.Reset(); sw.Start(); for (int i = 1; i <= count; i++) { Test2 tc = new Test2() { A = i + 1, B = "Petersburg" + i, ID = i }; list.Add(tc); if (i == 5000) f2 = tc; } sw.Stop(); long r2 = sw.ElapsedTicks; sw.Reset(); Assert.IsTrue(r1 > r2); sw.Start(); if (!hs.Contains(f1)) { Assert.Fail(); } sw.Stop(); r1 = sw.ElapsedTicks; sw.Reset(); sw.Start(); if (!list.Contains(f2)) { Assert.Fail(); } sw.Stop(); r2 = sw.ElapsedTicks; sw.Reset(); Assert.IsTrue(r1 < r2); }
public Bar (Test2.Foo baseArg4) { }
private void Start() { test2 = GameObject.FindObjectOfType <Test2>(); }
public void InstanceTest() { SimpleContainer sc = new SimpleContainer(); ITest1 ti = new Test1(); sc.Instance<ITest1, Test1>(ti); var result = sc.GetInstance<ITest1>(); Assert.AreEqual(result, ti); var result2 = sc.GetInstance<Test1>(); Assert.AreEqual(result2, ti); Test2 t2 = new Test2(); sc.Instance(t2); var result3 = sc.GetInstance<Test2>(); Assert.AreEqual(result3, t2); Test3 t3 = new Tests.Test3(); sc.Instance<ITest3>(t3); var result4 = sc.GetInstance<ITest3>(); Assert.AreEqual(result4, t3); }
static void Main(string[] args) { Test1 t1 = new Test1(); Test2 t2 = new Test2(); Test3 t3 = new Test3(); }
public void HandlerTest() { SimpleContainer sc = new SimpleContainer(); ITest1 t1 = null; sc.Handler<ITest1>((i) => { Assert.AreEqual(sc, i); t1 = new Test1(); return t1; }); var result1 = sc.GetInstance<ITest1>(); Assert.IsNotNull(t1); Assert.IsNotNull(result1); Assert.AreEqual(t1, result1); Test2 t2 = null; sc.Handler<ITest2, Test2>(i => { Assert.AreEqual(sc, i); t2 = new Test2(); return t2; }); var result2 = sc.GetInstance<ITest2>(); Assert.IsNotNull(t2); Assert.IsNotNull(result2); Assert.AreEqual(t2, result2); result2 = sc.GetInstance<Test2>(); Assert.IsNotNull(result2); Assert.AreEqual(t2, result2); }
public Test1(Test2 t1, float f, Test2 t2) { this.t1 = t1; this.f = f; this.t2 = t2; }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; ObjectManager objmgr1 = null; ISurrogateSelector isur = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; bool fFirstTime; MemberInfo[] members = null; Test1 tst1; A a1; Int32 iOurMan; Boolean fChildFound; Test2 tst2; Test3 tst3; B b1; try { do { tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); objmgr1.RegisterObject(tstfxp1, iRootID); objmgr1.RegisterObject(strValue, iChildID); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } objmgr1.DoFixups(); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_90342ddvs! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } tst1 = new Test1(); a1 = new A(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.DoFixups(); Console.WriteLine("Loc_0283! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04523cd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); try{ iCountTestcases++; objmgr1.DoFixups(); iCountErrors++; Console.WriteLine("Err_7453fd! exception not thrown"); }catch(SerializationException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1204cd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); objmgr1.DoFixups(); Console.WriteLine("Loc_02843cd! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0438fd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342fsd! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.DoFixups(); Console.WriteLine("Loc_94523fsd! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0348dcs! Unexpected exception, " + ex.ToString()); } tst2 = new Test2(); tst3 = new Test3(); b1 = new B(); b1.StrValue = "Hello World"; tst3.Set_B=b1; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst2, out fFirstTime); iChildID = objid1.GetId(tst3, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test2)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("tst3")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_024fd! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); objmgr1.RegisterObject(tst2, iRootID); objmgr1.RegisterObject(tst3, iChildID); iCountTestcases++; Console.WriteLine("Loc_4523vfd! we hve, " + tst2.StrValue); if(!tst2.StrValue.Equals("Hello World")) { iCountErrors++; Console.WriteLine("Err_038qm! Expected value not returned, " + tst2.StrValue); } tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordFixup(iRootID, members[0], iRootID); try{ iCountTestcases++; objmgr1.RegisterObject(tstfxp1, iRootID); iCountErrors++; Console.WriteLine("Err_753cd! exception not thrown"); }catch(ArgumentException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04523cd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(-1, members[0], iChildID); iCountErrors++; Console.WriteLine("Err_034cd! exception not thrown"); } catch(ArgumentOutOfRangeException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_034cd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(iRootID, members[0], -5); iCountErrors++; Console.WriteLine("Err_037csd! exception not thrown"); } catch(ArgumentOutOfRangeException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_710ca! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(iRootID, null, iChildID); iCountErrors++; Console.WriteLine("Err_048cs! exception not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_079cd! Unexpected exception, " + ex.ToString()); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
/* Pass an object. Now, ob.a and ob.b in object * used in the call will be changed. */ public void Change(Test2 oba) { oba.a = oba.a + oba.b; oba.b = -oba.b; }
public void TestWith2(Test1 test1, Test2 test2) { if (test1 == null) throw new ArgumentNullException("test1"); if (test2 == null) throw new ArgumentNullException("test2"); }
public static int Main() { Test1.Test(); if (Utils.failures == 0) { Console.WriteLine("Test1 OK"); } Test2.Test(); if (Utils.failures == 0) { Console.WriteLine("Test2 OK"); } Test3.Test(); if (Utils.failures == 0) { Console.WriteLine("Test3 OK"); } Test4.Test(); if (Utils.failures == 0) { Console.WriteLine("Test4 OK"); } Test5.Test(); if (Utils.failures == 0) { Console.WriteLine("Test5 OK"); } Test6.Test(); if (Utils.failures == 0) { Console.WriteLine("Test6 OK"); } Test7.Test(); if (Utils.failures == 0) { Console.WriteLine("Test7 OK"); } Test8.Test(); if (Utils.failures == 0) { Console.WriteLine("Test8 OK"); } Test9.Test(); if (Utils.failures == 0) { Console.WriteLine("Test9 OK"); } Test10.Test(); if (Utils.failures == 0) { Console.WriteLine("Test10 OK"); } Test11.Test(); if (Utils.failures == 0) { Console.WriteLine("Test11 OK"); } Test12.Test(); if (Utils.failures == 0) { Console.WriteLine("Test12 OK"); } Test13.Test(); if (Utils.failures == 0) { Console.WriteLine("Test13 OK"); } Test14.Test(); if (Utils.failures == 0) { Console.WriteLine("Test14 OK"); } Test15.Test(); if (Utils.failures == 0) { Console.WriteLine("Test15 OK"); } Test16.Test(); if (Utils.failures == 0) { Console.WriteLine("Test16 OK"); } Test17.Test(); if (Utils.failures == 0) { Console.WriteLine("Test17 OK"); } Test18.Test(); if (Utils.failures == 0) { Console.WriteLine("Test18 OK"); } Test19.Test(); if (Utils.failures == 0) { Console.WriteLine("Test19 OK"); } Test20.Test(); if (Utils.failures == 0) { Console.WriteLine("Test20 OK"); } Test21.Test(); if (Utils.failures == 0) { Console.WriteLine("Test21 OK"); } Test22.Test(); if (Utils.failures == 0) { Console.WriteLine("Test22 OK"); } Test23.Test(); if (Utils.failures == 0) { Console.WriteLine("Test23 OK"); } if (Utils.failures > 0) { return(101); } else { Console.WriteLine("PASS"); return(100); } }
public Test3(Test2 test2) { _test2 = test2; }
public void TestContrainedOnGenericField() { var a = new Test2 <DateTime>(DateTime.UtcNow); Assert.AssertEquals(typeof(DateTime), a.element.GetType()); }
public void TestWith2AndValue(Test1 test1, Test2 test2) { ParameterValidator.ParameterValidator.EnsureParametersAreValid(new NullValidatorWithValue<Test1>(() => test1, test1), new NullValidatorWithValue<Test2>(() => test2, test2)); }
//逆变 // public void SetValue<T>(T t); public void Test2() { ITest2 <Apple> test = new Test2 <Fruit>(); PrintFruits2(test); }
private static void TestParameterValidatorSpeed(int numberOfCalls) { var test1 = new Test1(); var test2 = new Test2(); var parameterValidatorTesting = new ParameterValidatorTesting(); var stopWatch = new Stopwatch(); stopWatch.Start(); for (var i = 0; i < numberOfCalls; i++) { parameterValidatorTesting.TestWith1(test1); } Console.WriteLine("Parameter Validator speed with 1 Test parameter: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); for (var i = 0; i < numberOfCalls; i++) { parameterValidatorTesting.TestWith2(test1, test2); } Console.WriteLine("Parameter Validator speed with 2 Test parameter: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); for (var i = 0; i < numberOfCalls; i++) { parameterValidatorTesting.TestWith1AndValue(test1); } Console.WriteLine("Parameter Validator speed with 2 Test parameter and specifying values (No expression compilation): " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); for (var i = 0; i < numberOfCalls; i++) { parameterValidatorTesting.TestWith2AndValue(test1, test2); } Console.WriteLine("Parameter Validator speed with 2 Test parameter and specifying values (No expression compilation): " + stopWatch.ElapsedMilliseconds); }
public static void Main() { Test1.Method1(); var test2 = new Test2(); }