Download: Personal_study_assistant.zip
Background
In reality, we may often have to be unsure about Some APIs or small core code, so we write some small test code, such as regular expression testing. After a long time, all these small projects are scattered, and searching and sorting are time-consuming.
"To do well, you must first sharpen your tools." Let's solve this problem.
The idea of the program is: 1. All test files are classified and stored in different projects; 2. When a project is started, a list of all test codes is automatically generated, run the test by entering the list serial number and selecting the corresponding test. You do not need to change the main method of the program.
(Currently, the file name corresponding to the test case cannot be displayed ).
Effect
Description
We recommend that you download the demo before proceeding.
1 CP. Core
There is currently only one class and one interface in the core layer. The interface itest describes the attributes and methods that should be available as a test instance. Casecontainer is used to scan test cases in the current project and generate the preceding menu.
The main knowledge point used in the Code is reflection.
2 CP. emitstudy
With the core layer, we will start to store test instances by category based on our needs. In the demo, taking emit learning as an example, a new project is of the console type.
The main function of program. CS for the new project has only one line of code:
static void Main(string[] args) { CaseContainer.ShowCases(); }
The rest is to write our test or learning cases. In the demo, Test2 simulates a piece of code written by automapper for copying attributes between two objects:
Class Test2: itest {class model {public string name {Get; Set ;}} class viewmodel {public string name {Get; Set ;}} public string name {get {return "LINQ assign expression test" ;}} Public String description {get {return "this demo demenstrates how to use LINQ expression to mapping properties between two object. "; // return" This example shows how to map the attributes of two objects using LINQ expression ";}} public void test () {expression <func <model, string> exp1 = m => M. name; expression <func <viewmodel, string> exp2 = Vm => VM. name; var assignexp = expression. assign (exp2.body, exp1.body); var MapAction = expression. lambda <action <model, viewmodel> (assignexp, exp1.parameters [0], exp2.parameters [0]). compile (); var M1 = new model () {name = "model's name"}; var m2 = new viewmodel (); MapAction (M1, M2); console. writeline (m2.name );}}
3. Follow-up
The rest is to write a new use case, put it under the current project, and then F5. Both viewing and starting are convenient.
Sometimes we can write some test demos to learn a framework or some code, so we can create a new study project.
We can set up a shortcut for this project to the desktop. Just click it when you want to write a program ~
[Tools] Small test and learning project configuration framework