public void Why_Need_Event_When_Delegate_Can_Do_What_Event_Do() { MyConsolWrite myConsolWrite = MyTest.ConsoleWrite; //Event version var test1 = new MyTest(); test1.DummyEvent += myConsolWrite; test1.OnDummyEventHappened("I am event"); //Event version with field var test1_1 = new MyTest(); test1_1.DummyEventProperty += myConsolWrite; test1_1.OnDummyEventHappened("I am event"); //delegate version var test2 = new MyTest(); test2.DummyDelegate = myConsolWrite; test2.OnDummyDelegateHappened("I am delegate"); test2.DummyDelegate = null; TestDelegate testDelegate = () => test2.OnDummyDelegateHappened("I will have exception, that's why i should not be a public property/field. danger to be easily override"); Assert.Throws <NullReferenceException>(testDelegate); }
public void TestEvent() { MyTest myTest = new MyTest(); myTest.MyEvent += myTest_MyEvent; myTest.MyEvent -= myTest_MyEvent; }
public static void GetTwoNearRepeat(int[,] redBall, int input, int i, ref int near, ref int repeat, ref int near_22, ref int repeat_22) { //int repeat0 = 0; if (MyTest.ISRepeat(redBall, input, i + 1) == 0) { if (MyTest.ISNear(redBall, input, i + 1) == 0) { if (MyTest.ISRepeat(redBall, input, i + 2) == 0) { near_22 += MyTest.ISNear(redBall, input, i + 2); } else { repeat_22 += MyTest.ISRepeat(redBall, input, i + 2); } } else { near += MyTest.ISNear(redBall, input, i + 1); } } else { repeat += MyTest.ISRepeat(redBall, input, i + 1); } }
static void Main(string[] args) { var mytest = new MyTest(); ((ITest1)mytest).Execute(); //hello ((ITest2)mytest).Execute(); //world }
static void Main(string[] args) { var mytest = new MyTest(); // note that mytest.Get() does not exist when interfaces are explicit var v1 = ((ITest1)mytest).Get(); //hello var v2 = ((ITest2)mytest).Get(); //world }
private void Start() { if (instance == null) { instance = this; } }
protected void Page_Load(object sender, EventArgs e) { _DT = CreateTable(); MyTest.ReadFile(_ArrRound, _ArrGoal, _RedBall, _MiniRedBall, _BlueBall, _SixSum, "ball"); ArrayList al = new ArrayList(); al = GetSixGoalRound(_ArrRound, _MiniRedBall, _RedBall); int upDown = 8; Random random = new Random(); int ii = random.Next(0, al.Count); int select = int.Parse(al[ii].ToString()); if (txtInput.Text == "") { if (select + upDown >= _ArrRound.Count || select - upDown < 1) { haha.InnerHtml = "Select= " + select.ToString() + " 再来一遍!"; } else { DisplaySelect(select, upDown, ""); } } }
public void ValueOrDefault_returns_value_when_not_default() { var myTestValue = new MyTest().ValueOrDefault(false); Assert.IsNotType <bool>(myTestValue); Assert.IsType <MyTest>(myTestValue); }
public override bool Equals(object obj) { MyTest myt = obj as MyTest; return(myt.Name.Equals(this.Name) && myt.RollNo.Equals(this.RollNo)); }
public static string HandInput(string str, ArrayList arrRound, int[,] miniRedBall, int[,] redBall, hangzhou hz) { string[] strNew = str.Trim().Split(' '); int[] input = new int[strNew.Length]; int sum = 0; int nearRepeat = 0; int prime = 0; int two = 0; int leftRight = 0; int upup = 0; for (int i = 0; i < strNew.Length; i++) { input[i] = int.Parse(strNew[i]); sum += input[i]; upup += MyTest.FindUpNumber(0, input[i] - 1, arrRound.Count - 1, redBall); two += MyTest.ISTwo(input[i]); prime += MyTest.ISPrime(input[i]); nearRepeat += MyTest.ISNearRepeat(redBall, input[i], 1); } leftRight = input[strNew.Length - 1] - input[0]; string returnStr = "sum=" + sum.ToString() + "_" + hz.Sum.ToString() + "|leftRight=" + leftRight.ToString() + "_" + hz.LeftRight.ToString() + "|upup=" + upup.ToString() + "_" + hz.UpUp.ToString() + "|two=" + two.ToString() + "_" + hz.Two.ToString() + "|prime=" + prime.ToString() + "_" + hz.Prime.ToString() + "|nearRepeat=" + nearRepeat.ToString() + "_" + hz.NearRepeat.ToString(); return(returnStr); }
public void Test() { bool y = true; MyTest z = new MyTest(); MyTest w = new MyTest(); var x = y ? z?.Invoke() : w?.Invoke(); }
/// <summary> /// Issue 960 - The compiler creates unusual IL with a conditional branches that only has nop instructions, /// no obvious ways to exercise the path and has then inserted a sequence point to boot /// </summary> public static string MapMyTest(this MyTest myTest) { return(myTest switch { MyTest.A => "a", MyTest.B => "b", _ => string.Empty, });
public static void Main() { Derived objDerived = new Derived(); MyTest objMyTest = new MyTest(); objDerived.DoSomething(objMyTest); System.Console.ReadLine(); }
private void ChangeSelectionChildsAndParent(MyTest test) { if (test.Selected) { if (test.Type == typeof(NUnit.Framework.Internal.TestAssembly)) { foreach (var test2 in EditorConfiguration.MyTests) { test2.Selected = true; } } else { if (test.IsSuite) { var index = EditorConfiguration.MyTests.IndexOf(test); for (int i = index + 1; i <= index + test.TestCaseCount; i++) { EditorConfiguration.MyTests[i].Selected = true; } } } } else { if (test.Type == typeof(NUnit.Framework.Internal.TestAssembly)) { foreach (var test2 in EditorConfiguration.MyTests) { test2.Selected = false; } } else { var dummy = test; if (test.Type == typeof(NUnit.Framework.Internal.TestFixture)) { var index = EditorConfiguration.MyTests.IndexOf(test); for (int i = index + 1; i <= index + test.TestCaseCount; i++) { EditorConfiguration.MyTests[i].Selected = false; } } while (dummy.ParentName != null) { dummy = EditorConfiguration.MyTests.FirstOrDefault(a => a.TestName.Equals(dummy.ParentName)); if (dummy != null) { dummy.Selected = false; } else { return; } } } } }
public static void TestGenericAlias() { MyTest test = new MyTest(); test.SetValue("Hello world!"); var val = test.GetValue(); Assert.AreEqual("Hello world!", val, "Generics by alias, member value set, is correctly fetched."); }
protected void btnOK_Click(object sender, EventArgs e) { string str = txtInput.Text.Trim(); // str = "1 2 3 4 5"; MyGoal.InnerHtml = MyTest.HandInput(str, _ArrRound, _MiniRedBall, _RedBall, _HangZhou); }
static void Main(string[] args) { int x = 2; MyTest mt = new MyTest(); mt.Test(); Console.WriteLine("Hello World!" + x); }
static void Main(string[] args) { var mytest = new MyTest(); // note that if mytest.Get() does not exist if all of the // interfaces are explicit var v0 = mytest.Get(); //local var v1 = ((ITest1)mytest).Get(); //hello var v2 = ((ITest2)mytest).Get(); //world var v3 = ((ITest3)mytest).Get(); //hi }
public static void Main(string[] args) { Client.Instance.MyEvent += delegate { Console.WriteLine("MY EVENT handled from Main"); }; MyTest mt = new MyTest(); Type mType = typeof(MyTest); object reflectedMT = Activator.CreateInstance(mType); Client.Instance.FireEvent(); }
static void Main(string[] args) { JITInterceptor.RegisterModule(typeof(MyTest).Module); JITInterceptor.Initialize(); MyTest.TestStatic(); var c = new MyTest(); c.TestInstance(); JITInterceptor.UnInitialize(); Console.ReadLine(); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); Program test = new MyTest(); test.testSign(); test.testvalidateSign(); Console.ReadLine(); }
static unsafe void Main(string[] args) { MyTest t = new MyTest(); t.SetId(Guid.NewGuid()); var output = JsonSerializer.ToJsonString(t, StandardResolver.AllowPrivateExcludeNull); var input = JsonSerializer.Deserialize <MyTest>(output, StandardResolver.AllowPrivateExcludeNull); Console.WriteLine(input.Id); }
public void TestMethod1() { string firstname = "Kaur "; string lastname = "Usai"; string fullname = "Kaur Usai"; MyTest n = new MyTest(); string nimi = n.Name(firstname, lastname); Assert.AreEqual(fullname, nimi); }
public void ObjectAsKeyTest() { Dictionary <object, object> dict = new Dictionary <object, object> (); MyTest key1, key2, key3; dict.Add((key1 = new MyTest("key1", 234)), "value1"); dict.Add((key2 = new MyTest("key2", 444)), "value2"); dict.Add((key3 = new MyTest("key3", 5655)), "value3"); Assert.AreEqual("value2", dict [key2], "value is not returned!"); Assert.AreEqual("value3", dict [key3], "neg: exception should not be thrown!"); }
public void TestExplicit() { int foo = 0; Shim shim = Shim.Replace(() => Is.A <MyTest>().ExplicitMethod()).With((MyTest t) => 42); var r = new MyTest(); PoseContext.Isolate(() => { foo = r.Explicitly(); }, shim); Assert.AreEqual(42, foo); }
public void Should_serialize_and_deserialize_in_object() { var obj = new MyTest { Id0 = DomainId.NewGuid(), Id1 = NamedId.Of(DomainId.NewGuid(), "1"), Id2 = NamedId.Of(DomainId.NewGuid(), "2") }; var serialized = obj.SerializeAndDeserialize(); serialized.Should().BeEquivalentTo(obj); }
public async void What_Is_The_Behavior_Of_Observable_FromEvent() { //Arrange var testTarget = new MyTest(); //testTarget.TestStarted += HandleTestStarted; //testTarget.OnTestStart(); var observableTarget = Observable.FromEventPattern(h => testTarget.TestStarted += h, h => testTarget.TestStarted -= h); IObserver <EventPattern <object> > testObserver = new TestObserver(HandleTestStarted); //observableTarget.Subscribe(testObserver); var myTask = observableTarget.Timeout(TimeSpan.FromSeconds(1)).ToTask(); await myTask; testTarget.OnTestStart(); }
static void Main(string[] args) { Array results = new[] { new { RoomCount = "2", Cover = "5", Space = "5", Floor = "5", FloorCount = "5", NameHouse = "5", Price = "5", NameStreet = "5" } }; //with this line not cpmmented does not compile Array.Resize(ref results, results.Length + 5); String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" }; Array.Resize(ref myArr, myArr.Length + 5); MyTest[] resultsMyTest = new MyTest[] { new MyTest { RoomCount = 3, Cover = "Red" } }; //here it will work as the compiler know how to infer it Array.Resize(ref resultsMyTest, results.Length + 5); }
protected void Page_Load(object sender, EventArgs e) { int maxCount = 10000; //string dataBase = "Test"; MyTest.ReadFile(_ArrRound, _ArrGoal, _RedBall, _MiniRedBall, _BlueBall, _SixSum, maxCount, "ball"); List <Exam_Mod> exModList = Exam_Analyze(_RedBall, _MiniRedBall, _ArrRound); using (SqlConnection conn = new SqlConnection("server=.;uid='sa';password='******';database='TestNew';enlist=true")) { conn.BulkCopy(exModList, 20000, "EXAM"); } }
public void TestNoCommandManager() { int CanExecuteCalls = 0; CommandListener listener = new CommandListener(() => CanExecuteCalls++); MyTest test = new MyTest(); DelegateCommand command = new DelegateCommand(test.DoWork, test.CanExecute, false); command.CanExecuteChanged += listener.OnCanExecuteChanged; CommandManager.InvalidateRequerySuggested(); Dispatcher.CurrentDispatcher.DoEvents(); command.Execute(null); Assert.AreEqual(1, test.ExecuteCalls); Assert.AreEqual(0, CanExecuteCalls); command.RaiseCanExecuteChanged(); Assert.AreEqual(1, CanExecuteCalls); }
public void Fix() { MyTest client = null; var myServer = new MyServer(new ServerConfiguration(), () => { client = new MyTest(); return client; }); myServer.Start(new IPEndPoint(IPAddress.Any, 0)); myServer.Stop(); myServer.Start(new IPEndPoint(IPAddress.Any, 0)); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(IPAddress.Loopback, myServer.LocalPort); Thread.Sleep(500); myServer.Stop(); client.Should().NotBeNull(); myServer.Stop(); }
public void Bson_SupportMultipleContent() { MemoryStream myStream = new MemoryStream(); BsonWriter writer = new BsonWriter(myStream); JsonSerializer serializer = new JsonSerializer(); MyTest tst1 = new MyTest { TimeStamp = new DateTime(2000, 12, 20, 12, 59, 59, DateTimeKind.Utc), UserName = "******" }; MyTest tst2 = new MyTest { TimeStamp = new DateTime(2010, 12, 20, 12, 59, 59, DateTimeKind.Utc), UserName = "******" }; serializer.Serialize(writer, tst1); serializer.Serialize(writer, tst2); myStream.Seek(0, SeekOrigin.Begin); BsonReader reader = new BsonReader(myStream) { SupportMultipleContent = true, DateTimeKindHandling = DateTimeKind.Utc }; MyTest tst1A = serializer.Deserialize<MyTest>(reader); reader.Read(); MyTest tst2A = serializer.Deserialize<MyTest>(reader); Assert.Equal(tst1.UserName, tst1A.UserName); Assert.Equal(tst1.TimeStamp, tst1A.TimeStamp); Assert.Equal(tst2.UserName, tst2A.UserName); Assert.Equal(tst2.TimeStamp, tst2A.TimeStamp); }
public bool PosTest2() { bool retVal = true; bool ActualResult; TestLibrary.TestFramework.BeginScenario("PosTest2: object value is declaring class"); try { UInt16 uintA = (UInt16)this.GetInt32(0, UInt16.MaxValue); object comValue = new MyTest(); ActualResult = uintA.Equals(comValue); if (ActualResult) { TestLibrary.TestFramework.LogError("003", "the ActualResult is not the ExpectResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e); retVal = false; } return retVal; }
public AnonymousClassAC1(MyTest enclosingInstance) { this.enclosingInstance = enclosingInstance; }
public void ObjectAsKeyTest () { Dictionary <object, object> dict = new Dictionary <object, object> (); MyTest key1, key2, key3; dict.Add ( (key1 = new MyTest ("key1", 234)), "value1"); dict.Add ( (key2 = new MyTest ("key2", 444)), "value2"); dict.Add ( (key3 = new MyTest ("key3", 5655)), "value3"); Assert.AreEqual ("value2", dict [key2], "value is not returned!"); Assert.AreEqual ("value3", dict [key3], "neg: exception should not be thrown!"); }
public static bool testMethod() { int intI = 1; int intJ = 2; int intK = 3; MyTest mc = new MyTest(); if ((mc.MyMeth1(intI, intJ, intK) == 6) && (MyTest.MyMeth2(intI, intJ, intK) == 6)) { return true; } else { return false; } }