1
MVC 단위 테스트를 이해하는 데 약간의 문제가 있습니다. 나는 내 모델을 가지고 있는데,이 모양은 다음과 같다.MVC 3 테스트 모드 및 컨트롤 단위 테스트
namespace UnifiedLibrary.Models
{
public class SCPublisherModel
{
[Display(Name = "Title")]
public string Title { get; set; }
[DataType(DataType.MultilineText)]
[Display(Name = "Description")]
public string Description { get; set; }
public bool Conform()
{
if (String.IsNullOrEmpty(Title))
Title = Resources.ULResLocal.Sou.locDefaultTitle;
if (String.IsNullOrEmpty(Description))
{
Description = Resources.ULResLocal.Sou.locDefaultDesc;
}
return true;
}
public bool Validate()
{
if (String.IsNullOrEmpty(Title))
Title = Resources.ULResLocal.Sou.locDefaultTitle;
return true;
}
}
}
public ActionResult Sou(string productID, string locale, string clienttoken, string Title, string Description)
{
ProviderID = (int)Providers.SoundCloud;
locale = Utilities.SetApplicationLocale(locale);
if (String.IsNullOrEmpty(clienttoken))
return RedirectToAction("../Shared/Error");
HttpCookie cookieAuthToken = this.ControllerContext.HttpContext.Request.Cookies[strCookieSoundCloudAuthToken];
if (cookieAuthToken == null)
{
return RedirectToAction("../Login/LoginSoundCloud", new { productID = productID, locale = locale, clienttoken = clienttoken,
Title = Title, Description = Description});
}
// create a model for soundcloud and store all known information
Models.SCPublisherModel model = new Models.SCPublisherModel();
model.Title = Title;
model.Description = Description;
model.Conform();
// create a view based on the updated model
return View(model);
}
나는이 컨트롤도 점검해야한다. 그러나 나는 어떻게 확신 할 수 없다. 이 단위 테스트를 사용했지만 잘못되었습니다.
[TestMethod]
public void SoundCloudTest()
{
// Controllers that rely on App_GlobalResources or App_Local_Resources cannot be unit tested with rewriting these dependencies.
var controller = new PublishController();
// Act
var SCModelTest = new SCPublisherModel()
{
Title = "Test 100",
};
var result = controller.SoundCloud(SCModelTest) as ViewResult;
Assert.AreEqual(result.View, SCModelTest);
}
당신이 어떤 기사를 알고 있다면. 너 나에게 그것을 줄 수 있니? 감사합니다.