TechNet
Products
IT Resources
Downloads
Training
Support
Products
Windows
Windows Server
System Center
Microsoft Edge
Office
Office 365
Exchange Server
SQL Server
SharePoint Products
Skype for Business
See all products »
Resources
Channel 9 Video
Evaluation Center
Learning Resources
Microsoft Tech Companion App
Microsoft Technical Communities
Microsoft Virtual Academy
Script Center
Server and Tools Blogs
TechNet Blogs
TechNet Flash Newsletter
TechNet Gallery
TechNet Library
TechNet Magazine
TechNet Wiki
Windows Sysinternals
Virtual Labs
Solutions
Networking
Cloud and Datacenter
Security
Virtualization
Updates
Service Packs
Security Bulletins
Windows Update
Trials
Windows Server 2016
System Center 2016
Windows 10 Enterprise
SQL Server 2016
See all trials »
Related Sites
Microsoft Download Center
Microsoft Evaluation Center
Drivers
Windows Sysinternals
TechNet Gallery
Training
Expert-led, virtual classes
Training Catalog
Class Locator
Microsoft Virtual Academy
Free Windows Server 2012 courses
Free Windows 8 courses
SQL Server training
Microsoft Official Courses On-Demand
Certifications
Certification overview
Special offers
MCSE Cloud Platform and Infrastructure
MCSE: Mobility
MCSE: Data Management and Analytics
MCSE Productivity
Other resources
Microsoft Events
Exam Replay
Born To Learn blog
Find technical communities in your area
Azure training
Official Practice Tests
Support options
For business
For developers
For IT professionals
For technical support
Support offerings
More support
Microsoft Premier Online
TechNet Forums
MSDN Forums
Security Bulletins & Advisories
Not an IT pro?
Microsoft Customer Support
Microsoft Community Forums
Sign in
Home
Library
Wiki
Learn
Gallery
Downloads
Support
Forums
Blogs
Resources For IT Professionals
United States (English)
Россия (Pусский)
中国(简体中文)
Brasil (Português)
Skip to locale bar
Post an article
Translate this page
Powered by
Microsoft® Translator
Wikis - Page Details
First published by
Veysel Ugur KIZMAZ
When:
4 Jun 2013 1:56 AM
Last revision by
Veysel Ugur KIZMAZ
When:
4 Jun 2013 11:19 AM
Revisions:
3
Comments:
0
Options
Subscribe to Article (RSS)
Share this
Can You Improve This Article?
Positively!
Click Sign In to add the tip, solution, correction or comment that will help other users.
Report inappropriate content using
these instructions
.
Wiki
>
TechNet Articles
>
Asp.Net MVC Unit Test Kullanımı (tr-TR)
Asp.Net MVC Unit Test Kullanımı (tr-TR)
Article
History
Asp.Net MVC Unit Test Kullanımı (tr-TR)
Bu yazımızda Asp.Net MVC’de Unit Test’lerin nasıl kullanıldığını inceleyelim.
Unit testlerle ilgili ön bilgi için bu linkteki makalemizi inceleyebilirsiniz.
Bu konuyu bir örnek ile inceleyelim.
Yeni bir Asp.Net MVC projesi oluşturalım ve yeni bir Controller ekleyelim.
MakaleController’ı oluşturduktan sonra içine MakaleGoster isimli bir Action ekleyelim.
public
class
MakaleController
:
Controller
{
public
ActionResult
Index()
{
return
View();
}
public
ActionResult
MakaleGoster(
int
makaleId)
{
return
View(
"Makale"
);
}
}
Şimdi MakaleGoster methodumuzun testi için MakaleGoster’e sağ tıklayıp önce Add View ile bir View ekleyelim, sonra Create Unit Tests diyelim.
Eğer bir test projemiz varsa o proje üzerinden devam edebiliriz. Yoksa yeni bir test projesi oluşturma ekranından devam edebiliriz.
Create dediğimizde test projemizi ve test methodumuzu oluşturdu. Test methodunun ilk oluştuğu anki kodları aşağıdaki gibi olacaktır (port farklı olabilir)
[
TestMethod
()]
[
HostType
(
"ASP.NET"
)]
[
AspNetDevelopmentServerHost
(
"c:\\documents and settings\\ugur\\belgelerim\\visual studio 2010\\Projects\\Mvc2_Makale\\Mvc2_Makale"
,
"/"
)]
[
UrlToTest
(
"http://localhost:3861/"
)]
public
void
MakaleGosterTest()
{
MakaleController
target =
new
MakaleController
();
int
makaleId = 2;
ActionResult
expected =
null
;
ActionResult
actual;
actual = target.MakaleGoster(makaleId);
Assert
.AreEqual(expected, actual);
Assert
.Inconclusive(
"Verify the correctness of this test method."
);
}
target.MakaleGoster() methodumuz bir ActionResult döndürecektir. Bu ActionResult’ın değerinin ne olacağına bir göz atalım.
Kodumuzu aşağıdaki gibi düzenleyelim.
[
TestMethod
()]
public
void
MakaleGosterTest()
{
MakaleController
target =
new
MakaleController
();
// TODO: Initialize to an appropriate value
int
makaleId = 0;
// TODO: Initialize to an appropriate value
ActionResult
expected =
null
;
// TODO: Initialize to an appropriate value
var
actual = target.MakaleGoster(makaleId);
Assert
.AreEqual(expected, actual);
}
Öncesinde, bizim MakaleGoster View’ımıza “Makale” string ifadesini gönderdiğimizi hatırlayalım ve
actual = target.MakaleGoster(makaleId);
satırına breakpoint koyup debug modda inceleyelim.
Kodumuzu çalıştırdığımızda aşağıdaki örnekteki şekilde gelen veriyi inceleyebiliriz.
ViewName’in Makale olduğunu görebilmekteyiz. Bu şekilde oluşturduğumuz ve ViewData ile göndermek istediğimiz verilerin View’a ulaşıp ulaşmayacağını Unit Testler ile tespit edebiliriz.
Veysel Uğur KIZMAZ
Bilgisayar Mühendisi
www.ugurkizmaz.com
ASP.NET MVC
,
asp.net unit test
,
mvc unit test
,
tr-TR
,
Unit Test
[Edit tags]
Leave a Comment
Please add 4 and 7 and type the answer here:
Post
Wiki - Revision Comment List(Revision Comment)
Wikis - Comment List