- MVC3Demo.zip
- MVC3Demo
- Library
- Microsoft.Practices.Unity.dll
- Local.testsettings
- MVC3Demo.sln
- MVC3Demo.Test
- MVC3Demo.vsmdi
- MVC3Demo
- TraceAndTestImpact.testsettings
|
using MVC3Demo.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Web.Mvc;
using MVC3Demo.Models;
using System.Collections;
using System.Collections.Generic;
namespace MVC3Demo.Test
{
/// <summary>
///This is a test class for ProductControllerTest and is intended
///to contain all ProductControllerTest Unit Tests
///</summary>
[TestClass()]
public class ProductControllerTest
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
[TestMethod]
public void ProductListTest()
{
ProductModel actualProductModel = new ProductModel();
ProductController target = new ProductController(actualProductModel);
string strPrdCode = string.Empty;
ActionResult actual;
actual = target.ProductList();
Assert.IsInstanceOfType(actual, typeof(PartialViewResult));
PartialViewResult result = (PartialViewResult)actual;
Assert.IsInstanceOfType(result.Model, typeof(IList<ProductModel>));
IList<ProductModel> expectedProduct = (IList<ProductModel>)result.Model;
IList<ProductModel> actualProduct = (IList<ProductModel>)actualProductModel.GetAllProducts();
Assert.AreEqual(actualProduct.Count, expectedProduct.Count);
}
[TestMethod]
public void ProductDetailTest()
{
ProductModel actualProductModel = new ProductModel();
ProductController target = new ProductController(actualProductModel);
ProductModel actualProduct = actualProductModel.GetAllProducts()[0];
string strPrdCode = string.Empty;
ActionResult actual;
actual = target.ProductDetail(strPrdCode);
Assert.IsInstanceOfType(actual, typeof(PartialViewResult));
PartialViewResult result = (PartialViewResult)actual;
Assert.IsInstanceOfType(result.Model, typeof(ProductModel));
ProductModel expectedProduct = (ProductModel)result.Model;
Assert.AreEqual(actualProduct.PrdCode, expectedProduct.PrdCode);
Assert.AreEqual(actualProduct.Name, expectedProduct.Name);
Assert.AreEqual(actualProduct.Price, expectedProduct.Price);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Artha is a Technical Lead in Windows Phone, WPF [MVVM, PRISM], ASP.NET [MVC 3.0 & 4.0], C#.NET, VB.NET and ASP.
Windows Phone
Microsoft Developer Network
Published Tools in Visual Studio Galleries
Published Source Codes in CodePlex
Microsoft Virtual Academy Profile
Published Articles in Code Project
Microsoft Certified Professional Developer (MCPD) Microsoft ASP.NET Developer 3.5 (070-564, 070-536, 070-562, 070 315)