public static TestAdd() { BasicMath bm = new BasicMath(); double res = bm.Add(10, 10); Assert.AreEqual(res, 20); }
public void AddNumbers(double a, double b, double expected) { // action BasicMath cal1 = new BasicMath(); double actual = cal1.Add(a, b); // assertion Assert.Equal(expected, actual); //Assert.Eq }
public void AddNumbers() { //arrange int expected = 5; //action BasicMath calc1 = new BasicMath(); int actual = calc1.Add(2, 3); //assertion Assert.Equal(expected, actual); }
static void Main(string[] args) { BasicMath m = new BasicMath(); Console.WriteLine("1 + 1 = {0}", m.Add(1, 1)); }
static void Main(string[] args) { Console.WriteLine(Fname); BasicMath bm = new BasicMath(); Console.WriteLine("sum = {0}", bm.Add(10.45, 243.39)); //different ways to create type instance //System.Object Type t = bm.GetType(); System.Reflection.MethodInfo mtInfo = t.GetMethod("Add"); Console.WriteLine("is Add public {0}", mtInfo.IsPublic); //typeof Type typo = typeof(BasicMath); //you don't need compile time info about the type //System.Type.GetType (static method) try { // Obtain type information for a type within an external assembly. //fully qualified name of the type, friendly name of the assembly Type sysType = System.Type.GetType("MathLibrary.BasicMath, MathLibrary", true, false); //Obtain type information for a nested class (add + for nested types) System.Type.GetType("MathLibrary.BasicMath+Trigonometry, MathLibrary", true, false); } catch(Exception e) { Console.WriteLine(e.Message); } /*“back tick” character (`) followed by a numerical value that represents the number of type parameters*/ //System.Collections.Generic.List<T> Type tInfo = System.Type.GetType("System.Collections.Generic.List`1, mscorlib", true, false); RedReflector rdr = new RedReflector(); rdr.ListMethods(tInfo); //rdr.ListProperties(tInfo); rdr.ListInterfaces(tInfo); rdr.ListStats(tInfo); //dynamically loading assembly ExternalAssemblyReflector ear = new ExternalAssemblyReflector(); //ear.DisplayTypesInAsm(Assembly.LoadFrom(@"G:\naynish\Pro C# 2010 and the .NET 4 Platform\ReflectionLateBindingAttributeBased\ConsoleApplication1\MathLibrary\bin\Debug\MathLibrary.dll")); String extPath = @"G:\naynish\Pro C# 2010 and the .NET 4 Platform\ReflectionLateBindingAttributeBased\ConsoleApplication1\SimpleEmployee\bin\Debug\SimpleEmployee.dll"; AssemblyName asmName = new AssemblyName(); //path including the extension asmName.Name = extPath; //LoadFrom because the assembly is not in the bin directory of ConsoleApplication1 ear.DisplayTypesInAsm(Assembly.LoadFrom(asmName.ToString())); //loading shared assemblies Assembly myAssembly = Assembly.Load(@"System.Windows.Forms, Version = 4.0.0.0, PublicKeyToken = b77a5c561934e089, Culture = """); ear.DisplayTypesInSharedAsm(myAssembly); AssemblyName customMyAssembly = new AssemblyName(); customMyAssembly.Name = "CustomLibrary"; Version v = new Version("1.0.0.0"); customMyAssembly.Version = v; Assembly a = Assembly.Load(customMyAssembly); ear.DisplayTypesInAsm(a); AttributeBased ab = new AttributeBased(); //ab.salary; (error on reflecting over this type using C# compiler) //reflect over an attributed type AssemblyName name = new AssemblyName(); name.Name = "AttributedEmployeeLibrary"; Assembly myAttr = Assembly.Load(name); Type tp = myAttr.GetType("AttributedEmployeeLibrary.VicePresident"); Object myInstance = Activator.CreateInstance(tp); MethodInfo info = tp.GetMethod("GetFname"); Console.WriteLine(info.Invoke(myInstance, null)); Object[] custAttr = tp.GetCustomAttributes(false); foreach (var item in custAttr) { Console.WriteLine(item); } foreach (Type item in myAttr.GetTypes()) { foreach (object item1 in item.GetCustomAttributes(myAttr.GetType("AttributedEmployeeLibrary.EmployeeDescriptionAttribute"), false)) { Console.WriteLine((myAttr.GetType("AttributedEmployeeLibrary.EmployeeDescriptionAttribute").GetProperty("Description")).GetValue(item1,null)); } } Console.ReadLine(); }
public void EqualsButtonClick() { /* Method invoked when the "Equals" button is pressed. */ // If the calculator is in an error state, then don't do anything. if (errorState == ErrorState.None) { // Variable to store the number currently being displayed. double number; // Parse and store the number currently being displayed. if (double.TryParse(DisplayString, out number)) { // If the current number is the first number in the current computation (ie. the selected operator is undefined), then store this number in "result". if (selectedOperator == Operator.Undefined) { result = number; } // Otherwise, perform the selected operation and store the result in the "result" member. else { switch (selectedOperator) { case Operator.Addition: result = BasicMath.Add(result, number); break; case Operator.Subtraction: result = BasicMath.Subtract(result, number); break; case Operator.Multiplication: result = BasicMath.Multiply(result, number); break; case Operator.Division: // If dividing by 0, set the calculator to error state if (number == 0) { errorState = ErrorState.DivisionByZero; } else { result = BasicMath.Divide(result, number); } break; } // Set the display accordingly if (errorState != ErrorState.None) { DisplayString = "Error"; } else { DisplayString = $"{result}"; } } } // Reset the selected operator to "Undefined" and update last button pressed and last dependency button pressed. selectedOperator = Operator.Undefined; lastDepButtonPressed = ButtonType.Equals; lastDepButtonPressed2 = ButtonType.Equals; } }
protected void AddButton_Click(object sender, EventArgs e) { var basicMath = new BasicMath(); SumLabel.Text = "" + BasicMath.Add(double.Parse(Value1Box.Text), double.Parse(Value2Box.Text)); }