The original Code gave me a good starting point. Yes, these codes are all jade. I just want to think about them again. Even so, the refactoring process is still very cumbersome, and the article may be very long. Every refactoring requires displaying all the code. It is difficult to understand and implement. refactoring is a dynamic process, which is not so easy to present. You need to be patient and take a look. 1-convert to C # code and add the first test. Yes, this is not necessary. It can be said that it is my own reason and it will not be Java. However, you can also think of it as a reconstruction scenario, right? The changed code is no longer put. It is relatively simple. It is related to the difference between C # and Java, leaving a connection to SocialID. cs. However, my test code is very important. Many may criticize my testing framework (Machine. Specification) and Code style. The former, I think we will introduce MSpec and BDD in the future to familiarize everyone with it. The latter can only be applied to everyone. ==> Write the first test code www.2cto.com: when you enter the correct ID card, you should be able to get the correct birthday. [C #] namespace Skight. eLiteWeb. domain. specs {public class when_create_social_id_with_proper_input {private Because of = () => subject = new SocialID ("43010319801120753"); private It should_get_birth_date_correctly = () => subject. getBirthDate (). shouldEqual (new DateTime (1980, 11, 20); private static SocialID subject ;}=> run the first test, failed :) interestingly, after resolving the C # syntax translation, my first test failed.
==> Refactor the original, seemingly identical syntax Substring, but the second parameter has different meanings. The test can streamline this process. [Java] private String getBirthDayPart () {return this. cardNumber. change substring (6, 14);} to [c #] private String getBirthDayPart () {return this. cardNumber. substring (6, 8) ;}=> test again
==> The first iteration ends, rest. well, the results of the phase can be marked as a milestone for a test/behavior. Today is the end of the process. Your support will allow me to continue tomorrow. Oh, Shao et. the last step is indeed the most important step. to our customers (in this case, my customers are other developers, and yes, the customers of senior programmers are other intermediate and junior programmers. Change your mind) the test/function report of is as follows: