SlideShare une entreprise Scribd logo
1  sur  28
SESSION DETAILS
• 10-15 MINUTES OF BACKGROUND • 50-55 MINUTES OF HANDS-ON CODING
SESSION DETAILS: YOU NEED THIS STUFF
• SEED CODE IS WRITTEN IN C#
• GET IT FROM GITHUB:
https://github.com/KatasForLegacy
Code/kCSharp/archive/Step0.zip
• OR FROM ONE OF THE FLASH DRIVES:
kCSharp-Step0.zip
• ANY VERSION OF VISUAL STUDIO 2012/2013
THAT CAN RUN CONSOLE APPS AND UNIT TESTS
• AN NUNIT TEST RUNNER OR THE ABILITY TO
QUICKLY SWITCH OUT NUNIT REFERENCE FOR
MSTEST. I RECOMMEND NCRUNCH.
• WHEN WE ARE DONE CODING, I’M HOPING WE
WILL HAVE 5-10 MINUTES FOR Q&A
• THE FIRST 5 SUGGESTIONS FOR ADDITIONS OR
IMPROVEMENTS TO THIS SESSION/CODE WILL
WIN THE FLASH DRIVES
LEGACY
EXPECTATION REALITY
LEGACY
PERCEPTION - COBOL
LEGACY
PERCEPTION - COBOL REALITY – CODE W/O UNIT TESTS
DEPENDENCY
EXPECTATION REALITY
DEPENDENCY – THE HORRID TRUTH
KILLER
EXPECTATION
“
”
I’VE COMPLETELY SLAUGHTERED ALL THE
LEGACY DEPENDENCIES IN OUR
CODEBASE.
NOW I’LL ENJOY SOME LUNCH.
KILLER
EXPECTATION REALITY
PUT IT ALL TOGETHER & WHADDAYA GET
•A CODE KATA
• A CODE KATA IS AN EXERCISE IN PROGRAMMING
WHICH HELPS A PROGRAMMER HONE THEIR
SKILLS THROUGH PRACTICE AND REPETITION
• THE WORD KATA IS TAKEN FROM JAPANESE ARTS
MOST TRADITIONALLY MARTIAL ARTS
• WHY? BECAUSE HUMANS LEARN BY DOING
DEPENDENCY KATA
• DEPENDENCY KATA: CODE CAMP EDITION
• WRITTEN IN C#
• NOW WITH LESS TOOL DEPENDENCIES AND RESTRUCTURED TO WORK WITHOUT THEM
• ORIGINAL SOURCE CODE AVAILABLE ON GITHUB AT HTTPS://GITHUB.COM/DUBMUN/DEPENDENCYKATA
DEPENDENCY KATA: INITIAL STRUCTURE
DEPENDENCY KATA: FIRST THINGS FIRST
• LET’S START BY GETTING THE EXISTING TEST
RUNNING
• RUNNING THE INTEGRATION TEST SHOWS THAT
IT HANGS
• WE NEED TO BEGIN BY ABSTRACTING AND
BREAKING THE DEPENDENCY ON
Console.Readline()
• CREATE AN INTERFACE FIRST
public interface IConsoleAdapter
{
string GetInput();
}
• CREATE A CLASS THAT IMPLEMENTS THE
INTERFACE
public class ConsoleAdapter :
IConsoleAdapter
DEPENDENCY KATA: FIRST THINGS FIRST
• IMPLEMENT METHOD TO HANDLE THE DEPENDENCY
public class ConsoleAdapter :
IConsoleAdapter
{
public string GetInput()
{
return Console.ReadLine();
}
}
• CREATE NEW CONSTRUCTOR FOR DOITALL THAT ACCEPTS
ICONSOLEADAPTER AND SET A PRIVATE VARIABLE
private IConsoleAdapter _consoleAdapter;
public doItAll(IConsoleAdapter
consoleAdapter)
{
_consoleAdapter = consoleAdapter;
}
• THEN REPLACE 6 CALLS TO Console.ReadLine()
WITH _consoleAdapter.GetInput()
DEPENDENCY KATA: FIRST THINGS FIRST
• NOW WE HAVE SOME BROKEN INSTANTIATIONS
• IN THE CONSOLE APP INSTANTIATE AND PASS IN
OUR NEW HANDLER
var doItAll = new DoItAll(
new ConsoleAdapter());
• IN THE INTEGRATION TEST WE NEED TO DO
SOMETHING DIFFERENT OR OUR TEST WILL STILL
FAIL.
• CREATE A NEW IMPLEMENTATION OF
IConsoleAdaper
public class FakeConsoleAdapter :
IConsoleAdapter
{
public string GetInput()
{
return string.Empty;
}
}
DEPENDENCY KATA: FIRST THINGS FIRST
• WHEN THE TEST IS RUN WE NOW GET A
MEANINGFUL EXCEPTION. ALL OF THE
DEPENDENCIES THAT CAUSED THE HANG ARE
GONE.
• THE TEST IS NOW FAILING BECAUSE THE
PASSWORD IS EMPTY. THIS IS A MEANINGFUL
CASE BUT LET’S JUST UPDATE OUR FAKE FOR
NOW.
return “fakeInput”;
• THE TEST SHOULD BE GREEN NOW!
DEPENDENCY KATA: FIRST THINGS FIRST
• WHEN THE TEST IS RUN WE NOW GET A
MEANINGFUL EXCEPTION. ALL OF THE
DEPENDENCIES THAT CAUSED THE HANG ARE
GONE.
• THE TEST IS NOW FAILING BECAUSE THE
PASSWORD IS EMPTY. THIS IS A MEANINGFUL
CASE BUT LET’S JUST UPDATE OUR FAKE FOR
NOW.
return “fakeInput”;
• THE TEST SHOULD BE GREEN NOW!
• LET’S ADD AN ASSERT FOR GOOD MEASURE
[Test, Category("Integration")]
public void DoItAll_Does_ItAll()
{
var doItAll = new DoItAll(new
FakeConsoleAdapter());
Assert.DoesNotThrow(() =>
doItAll.Do());
}
DEPENDENCY KATA: BETTER COVERAGE
• WE DON'T HAVE COVERAGE SOME OF THE CODE
STILL AND NO QUANTIFIABLE RESULTS TO TEST
• LET’S COPY OUR EXISTING TEST AND RENAME IT
DoItAll_Fails_ToWriteToDB
• THEN CHANGE THE ASSERT
StringAssert.Contains(
"Database.SaveToLog
Exception:", doItAll.Do());
• THIS WILL FAIL TO BUILD BECAUSE OUR METHOD IS
CURRENTLY VOID. LET’S CHANGE THAT
• CHANGE DO()’S RETURN TYPE TO STRING
• ADD A RETURN STATEMENT IN 2 LOCATIONS:
• AT THE END OF THE USING STATEMENT
• AT THE END OF THE METHOD
• NOW CREATE VARIABLES TO HOLD THE MESSAGES
AT VARIOUS POINTS FOR RETURN
private const string
_passwordsDontMatch =
"The passwords don't match.";
DEPENDENCY KATA: BETTER COVERAGE
• NOW CREATE VARIABLES TO HOLD THE MESSAGES
AT VARIOUS POINTS FOR RETURN
private const string
_passwordsDontMatch =
"The passwords don't match.";
AND
var errorMessage = string.Format(
"{0} - Database.SaveToLog
Exception: rn{1}",
message, ex.Message);
• RETURN THOSE VALUES AS APPROPRIATE
• OUR NEW TEST SHOULD NOW PASS
DEPENDENCY KATA: BETTER ABSTRACTION
• DO WORK TO ABSTRACT CONSOLE COMPLETELY
COMPLETELY
• ADD A NEW METHOD STUB TO
IConsoleAdapter:
Void SetOutput(string output);
• UPDATE ConsoleAdapter IMPLEMENTATION
public void SetOutput(string output)
{
Console.WriteLine(output);
}
• UPDATE FakeConsoleAdapter
IMPLEMENTATION
public void SetOutput(string
output)
{}
• UPDATE DoItAll IMPLEMENTATION REPLACING
6 INSTANCES OF Console.WriteLine WITH
_consoleAdapter.SetOutput
• OUR TESTS SHOULD STILL PASS
DEPENDENCY KATA: REFACTOR
• DoItAll.Do() IS TRYING TO DO TOO MUCH
• EXTRACT LOGGING FUNCTIONALITY BY CREATING
A NEW INTERFACE
public interface ILogger
{
string LogMessage(string message);
}
• NOW EXTRACT THE CODE IN THE TRY/CATCH
BLOCK IN DoItAll.Do() INTO THE
IMPLEMENTATION OF
ILogger.LogMessage()
• MAKE SURE ALL PATHS RETURN A MESSAGE
• NOW UPDATE THE CONSTRUCTOR OF DoItAll
WITH AN ILogger SAND REPLACE TRY/CATCH:
message =
_logger.LogMessage(message);
DEPENDENCY KATA: REFACTOR
• CLIENT NO LONGER BUILDS BECAUSE OF THE
UPDATED CONSTRUCTOR SO UPDATE IT
• NOW CREATE A NEW FAKE FOR TESTING:
public class FakeLogger : ILogger
{
public string LogMessage(
string message)
{
return string.Empty;
}
}
• UPDATE THE DoItAll MINSTANTIATIONS IN
THE TESTS TO INCLUDE new FakeLogger()
• THE FIRST TEST PASSES BUT THE OTHER FAILS
BECAUSE IT DEPENDS ON IMPLEMENTATION-
SPECIFIC DETAILS
DEPENDENCY KATA: REFACTOR
• COPY THE SECOND TEST AND RENAME THE COPY
DoItAll_Succeeds_WithMockLogging
• UPDATE THE ASSERT:
Assert.AreEqual(
string.Empty, doItAll.Do());
• TEST WILL PASS
• LET THE FORMER TEST DEPEND ON
DatabaseLogger AND IT WILL PASS AS WELL
DEPENDENCY KATA: WHAT’S NEXT?
• THERE ARE STILL PLENTY OF THING ABOUT THIS LEGACY CODE I WOULD CHANGE
• WHAT WOULD YOU DO NEXT?
THANKS TO OUR SPONSORS!
To connect to wireless
1. Choose Uguest in the wireless list
2. Open a browser. This will open a Uof U website
3. Choose Login
Legacy Dependency Killer - Utah Code Camp 2014

Contenu connexe

Tendances

Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMark Wragg
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomasintuit_india
 
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...DevOpsGroup
 
Setting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsSetting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsDaniel Stange
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleVodqaBLR
 
Vaugham Hong - Embedding JavaScript V8
Vaugham Hong - Embedding JavaScript V8Vaugham Hong - Embedding JavaScript V8
Vaugham Hong - Embedding JavaScript V8Allen Pike
 
Automate right start from API
Automate right start from APIAutomate right start from API
Automate right start from APIRoman Liubun
 
Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Bertrand Delacretaz
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
 
Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Ruby conf 2016 - Secrets of Testing Rails 5 AppsRuby conf 2016 - Secrets of Testing Rails 5 Apps
Ruby conf 2016 - Secrets of Testing Rails 5 AppsNascenia IT
 
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019Icinga
 
Learnings Building Alexa Skills with PHP
Learnings Building Alexa Skills with PHPLearnings Building Alexa Skills with PHP
Learnings Building Alexa Skills with PHPRalf Eggert
 
Axon Server went RAFTing
Axon Server went RAFTingAxon Server went RAFTing
Axon Server went RAFTingJ On The Beach
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina LanguageLynn Langit
 
Pretenders talk at PyconUK 2012
Pretenders talk at PyconUK 2012Pretenders talk at PyconUK 2012
Pretenders talk at PyconUK 2012txels
 
WordPress Development: Tracking Your Code With Version Control
WordPress Development: Tracking Your Code With Version ControlWordPress Development: Tracking Your Code With Version Control
WordPress Development: Tracking Your Code With Version ControlSterling Hamilton
 
A Deep Dive into the W3C WebDriver Specification
A Deep Dive into the W3C WebDriver SpecificationA Deep Dive into the W3C WebDriver Specification
A Deep Dive into the W3C WebDriver SpecificationPeter Thomas
 

Tendances (20)

Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
 
Come si applica l'OCP
Come si applica l'OCPCome si applica l'OCP
Come si applica l'OCP
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
 
Git Tutorial (Part 2: Git Merge)
Git Tutorial (Part 2: Git Merge)Git Tutorial (Part 2: Git Merge)
Git Tutorial (Part 2: Git Merge)
 
Setting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsSetting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce Apps
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
Vaugham Hong - Embedding JavaScript V8
Vaugham Hong - Embedding JavaScript V8Vaugham Hong - Embedding JavaScript V8
Vaugham Hong - Embedding JavaScript V8
 
Automate right start from API
Automate right start from APIAutomate right start from API
Automate right start from API
 
Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Ruby conf 2016 - Secrets of Testing Rails 5 Apps
Ruby conf 2016 - Secrets of Testing Rails 5 AppsRuby conf 2016 - Secrets of Testing Rails 5 Apps
Ruby conf 2016 - Secrets of Testing Rails 5 Apps
 
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019Discover the real user experience with Alyvix - Icinga Camp Milan 2019
Discover the real user experience with Alyvix - Icinga Camp Milan 2019
 
Learnings Building Alexa Skills with PHP
Learnings Building Alexa Skills with PHPLearnings Building Alexa Skills with PHP
Learnings Building Alexa Skills with PHP
 
Axon Server went RAFTing
Axon Server went RAFTingAxon Server went RAFTing
Axon Server went RAFTing
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina Language
 
Pretenders talk at PyconUK 2012
Pretenders talk at PyconUK 2012Pretenders talk at PyconUK 2012
Pretenders talk at PyconUK 2012
 
WordPress Development: Tracking Your Code With Version Control
WordPress Development: Tracking Your Code With Version ControlWordPress Development: Tracking Your Code With Version Control
WordPress Development: Tracking Your Code With Version Control
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
A Deep Dive into the W3C WebDriver Specification
A Deep Dive into the W3C WebDriver SpecificationA Deep Dive into the W3C WebDriver Specification
A Deep Dive into the W3C WebDriver Specification
 

Similaire à Legacy Dependency Killer - Utah Code Camp 2014

Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Eric Phan
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NETDoommaker
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumAlina Vilk
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaUgo Matrangolo
 
Code Quality Assurance with PMD (2004)
Code Quality Assurance with PMD (2004)Code Quality Assurance with PMD (2004)
Code Quality Assurance with PMD (2004)Peter Kofler
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsRoy van Rijn
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnNLJUG
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6Andy Butland
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiRan Mizrahi
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chhom Karath
 

Similaire à Legacy Dependency Killer - Utah Code Camp 2014 (20)

Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
2013-01-10 iOS testing
2013-01-10 iOS testing2013-01-10 iOS testing
2013-01-10 iOS testing
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Old code doesn't stink
Old code doesn't stinkOld code doesn't stink
Old code doesn't stink
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, Ciklum
 
iOS testing
iOS testingiOS testing
iOS testing
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
 
Code Quality Assurance with PMD (2004)
Code Quality Assurance with PMD (2004)Code Quality Assurance with PMD (2004)
Code Quality Assurance with PMD (2004)
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your tests
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van Rijn
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran Mizrahi
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)
 

Dernier

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Legacy Dependency Killer - Utah Code Camp 2014

  • 1.
  • 2. SESSION DETAILS • 10-15 MINUTES OF BACKGROUND • 50-55 MINUTES OF HANDS-ON CODING
  • 3. SESSION DETAILS: YOU NEED THIS STUFF • SEED CODE IS WRITTEN IN C# • GET IT FROM GITHUB: https://github.com/KatasForLegacy Code/kCSharp/archive/Step0.zip • OR FROM ONE OF THE FLASH DRIVES: kCSharp-Step0.zip • ANY VERSION OF VISUAL STUDIO 2012/2013 THAT CAN RUN CONSOLE APPS AND UNIT TESTS • AN NUNIT TEST RUNNER OR THE ABILITY TO QUICKLY SWITCH OUT NUNIT REFERENCE FOR MSTEST. I RECOMMEND NCRUNCH. • WHEN WE ARE DONE CODING, I’M HOPING WE WILL HAVE 5-10 MINUTES FOR Q&A • THE FIRST 5 SUGGESTIONS FOR ADDITIONS OR IMPROVEMENTS TO THIS SESSION/CODE WILL WIN THE FLASH DRIVES
  • 6. LEGACY PERCEPTION - COBOL REALITY – CODE W/O UNIT TESTS
  • 8. DEPENDENCY – THE HORRID TRUTH
  • 10. “ ” I’VE COMPLETELY SLAUGHTERED ALL THE LEGACY DEPENDENCIES IN OUR CODEBASE. NOW I’LL ENJOY SOME LUNCH.
  • 12. PUT IT ALL TOGETHER & WHADDAYA GET •A CODE KATA • A CODE KATA IS AN EXERCISE IN PROGRAMMING WHICH HELPS A PROGRAMMER HONE THEIR SKILLS THROUGH PRACTICE AND REPETITION • THE WORD KATA IS TAKEN FROM JAPANESE ARTS MOST TRADITIONALLY MARTIAL ARTS • WHY? BECAUSE HUMANS LEARN BY DOING
  • 13. DEPENDENCY KATA • DEPENDENCY KATA: CODE CAMP EDITION • WRITTEN IN C# • NOW WITH LESS TOOL DEPENDENCIES AND RESTRUCTURED TO WORK WITHOUT THEM • ORIGINAL SOURCE CODE AVAILABLE ON GITHUB AT HTTPS://GITHUB.COM/DUBMUN/DEPENDENCYKATA
  • 15. DEPENDENCY KATA: FIRST THINGS FIRST • LET’S START BY GETTING THE EXISTING TEST RUNNING • RUNNING THE INTEGRATION TEST SHOWS THAT IT HANGS • WE NEED TO BEGIN BY ABSTRACTING AND BREAKING THE DEPENDENCY ON Console.Readline() • CREATE AN INTERFACE FIRST public interface IConsoleAdapter { string GetInput(); } • CREATE A CLASS THAT IMPLEMENTS THE INTERFACE public class ConsoleAdapter : IConsoleAdapter
  • 16. DEPENDENCY KATA: FIRST THINGS FIRST • IMPLEMENT METHOD TO HANDLE THE DEPENDENCY public class ConsoleAdapter : IConsoleAdapter { public string GetInput() { return Console.ReadLine(); } } • CREATE NEW CONSTRUCTOR FOR DOITALL THAT ACCEPTS ICONSOLEADAPTER AND SET A PRIVATE VARIABLE private IConsoleAdapter _consoleAdapter; public doItAll(IConsoleAdapter consoleAdapter) { _consoleAdapter = consoleAdapter; } • THEN REPLACE 6 CALLS TO Console.ReadLine() WITH _consoleAdapter.GetInput()
  • 17. DEPENDENCY KATA: FIRST THINGS FIRST • NOW WE HAVE SOME BROKEN INSTANTIATIONS • IN THE CONSOLE APP INSTANTIATE AND PASS IN OUR NEW HANDLER var doItAll = new DoItAll( new ConsoleAdapter()); • IN THE INTEGRATION TEST WE NEED TO DO SOMETHING DIFFERENT OR OUR TEST WILL STILL FAIL. • CREATE A NEW IMPLEMENTATION OF IConsoleAdaper public class FakeConsoleAdapter : IConsoleAdapter { public string GetInput() { return string.Empty; } }
  • 18. DEPENDENCY KATA: FIRST THINGS FIRST • WHEN THE TEST IS RUN WE NOW GET A MEANINGFUL EXCEPTION. ALL OF THE DEPENDENCIES THAT CAUSED THE HANG ARE GONE. • THE TEST IS NOW FAILING BECAUSE THE PASSWORD IS EMPTY. THIS IS A MEANINGFUL CASE BUT LET’S JUST UPDATE OUR FAKE FOR NOW. return “fakeInput”; • THE TEST SHOULD BE GREEN NOW!
  • 19. DEPENDENCY KATA: FIRST THINGS FIRST • WHEN THE TEST IS RUN WE NOW GET A MEANINGFUL EXCEPTION. ALL OF THE DEPENDENCIES THAT CAUSED THE HANG ARE GONE. • THE TEST IS NOW FAILING BECAUSE THE PASSWORD IS EMPTY. THIS IS A MEANINGFUL CASE BUT LET’S JUST UPDATE OUR FAKE FOR NOW. return “fakeInput”; • THE TEST SHOULD BE GREEN NOW! • LET’S ADD AN ASSERT FOR GOOD MEASURE [Test, Category("Integration")] public void DoItAll_Does_ItAll() { var doItAll = new DoItAll(new FakeConsoleAdapter()); Assert.DoesNotThrow(() => doItAll.Do()); }
  • 20. DEPENDENCY KATA: BETTER COVERAGE • WE DON'T HAVE COVERAGE SOME OF THE CODE STILL AND NO QUANTIFIABLE RESULTS TO TEST • LET’S COPY OUR EXISTING TEST AND RENAME IT DoItAll_Fails_ToWriteToDB • THEN CHANGE THE ASSERT StringAssert.Contains( "Database.SaveToLog Exception:", doItAll.Do()); • THIS WILL FAIL TO BUILD BECAUSE OUR METHOD IS CURRENTLY VOID. LET’S CHANGE THAT • CHANGE DO()’S RETURN TYPE TO STRING • ADD A RETURN STATEMENT IN 2 LOCATIONS: • AT THE END OF THE USING STATEMENT • AT THE END OF THE METHOD • NOW CREATE VARIABLES TO HOLD THE MESSAGES AT VARIOUS POINTS FOR RETURN private const string _passwordsDontMatch = "The passwords don't match.";
  • 21. DEPENDENCY KATA: BETTER COVERAGE • NOW CREATE VARIABLES TO HOLD THE MESSAGES AT VARIOUS POINTS FOR RETURN private const string _passwordsDontMatch = "The passwords don't match."; AND var errorMessage = string.Format( "{0} - Database.SaveToLog Exception: rn{1}", message, ex.Message); • RETURN THOSE VALUES AS APPROPRIATE • OUR NEW TEST SHOULD NOW PASS
  • 22. DEPENDENCY KATA: BETTER ABSTRACTION • DO WORK TO ABSTRACT CONSOLE COMPLETELY COMPLETELY • ADD A NEW METHOD STUB TO IConsoleAdapter: Void SetOutput(string output); • UPDATE ConsoleAdapter IMPLEMENTATION public void SetOutput(string output) { Console.WriteLine(output); } • UPDATE FakeConsoleAdapter IMPLEMENTATION public void SetOutput(string output) {} • UPDATE DoItAll IMPLEMENTATION REPLACING 6 INSTANCES OF Console.WriteLine WITH _consoleAdapter.SetOutput • OUR TESTS SHOULD STILL PASS
  • 23. DEPENDENCY KATA: REFACTOR • DoItAll.Do() IS TRYING TO DO TOO MUCH • EXTRACT LOGGING FUNCTIONALITY BY CREATING A NEW INTERFACE public interface ILogger { string LogMessage(string message); } • NOW EXTRACT THE CODE IN THE TRY/CATCH BLOCK IN DoItAll.Do() INTO THE IMPLEMENTATION OF ILogger.LogMessage() • MAKE SURE ALL PATHS RETURN A MESSAGE • NOW UPDATE THE CONSTRUCTOR OF DoItAll WITH AN ILogger SAND REPLACE TRY/CATCH: message = _logger.LogMessage(message);
  • 24. DEPENDENCY KATA: REFACTOR • CLIENT NO LONGER BUILDS BECAUSE OF THE UPDATED CONSTRUCTOR SO UPDATE IT • NOW CREATE A NEW FAKE FOR TESTING: public class FakeLogger : ILogger { public string LogMessage( string message) { return string.Empty; } } • UPDATE THE DoItAll MINSTANTIATIONS IN THE TESTS TO INCLUDE new FakeLogger() • THE FIRST TEST PASSES BUT THE OTHER FAILS BECAUSE IT DEPENDS ON IMPLEMENTATION- SPECIFIC DETAILS
  • 25. DEPENDENCY KATA: REFACTOR • COPY THE SECOND TEST AND RENAME THE COPY DoItAll_Succeeds_WithMockLogging • UPDATE THE ASSERT: Assert.AreEqual( string.Empty, doItAll.Do()); • TEST WILL PASS • LET THE FORMER TEST DEPEND ON DatabaseLogger AND IT WILL PASS AS WELL
  • 26. DEPENDENCY KATA: WHAT’S NEXT? • THERE ARE STILL PLENTY OF THING ABOUT THIS LEGACY CODE I WOULD CHANGE • WHAT WOULD YOU DO NEXT?
  • 27. THANKS TO OUR SPONSORS! To connect to wireless 1. Choose Uguest in the wireless list 2. Open a browser. This will open a Uof U website 3. Choose Login