开发者

Unit Test Friendly way of using membership details inside the controller

开发者 https://www.devze.com 2023-04-10 09:54 出处:网络
Here is a piece of code from one of the controller inside my ASP.NET MVC 3 App : _destinationdetailRepository.Add(new DestinationDetail {

Here is a piece of code from one of the controller inside my ASP.NET MVC 3 App :

_destinationdetailRepository.Add(new DestinationDetail { 

    DestinationID = destination.DestinationID,
    CreatedOn = DateTime.Now,
    CreatedBy = User.Identity.Name
});

What is important here is the CreatedBy property value which is User.Identity.Name. It works great and I use this on another parts of my app as well. But, I guess this is not a unit test firendly way of doing things.

So, what is the way of using Membership data inside the controller so that I will be happy when I am unit testing m开发者_运维百科y app.


But, I guess this is not a unit test firendly way of doing things.

No, it's unit test friendly and it is correct code. The User property is an IPrincipal interface that can be mocked in an unit test.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号