잊지 않겠습니다.

Sysprep 테스트

.NET Framework 2010. 8. 13. 15:31

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State (http://schemas.microsoft.com/WMIConfig/2002/State) " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance (http://www.w3.org/2001/XMLSchema-instance) ">
            <ProductKey>6HFGM-3KFJB-HFQJW-793WD-GKQHY</ProductKey>
        </component>
    </settings>
    <settings pass="generalize">
        <component name="Microsoft-Windows-Security-Licensing-SLC" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State (http://schemas.microsoft.com/WMIConfig/2002/State) " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance (http://www.w3.org/2001/XMLSchema-instance) ">
            <SkipRearm>1</SkipRearm>
        </component>
    </settings>
</unattend>
Posted by Y2K
,
javascript에서 자주 class화 시켰으면 좋을것 같은데.. 하는 일이 자주 벌어진다.
일단 기본 목적이 화면에 표시되는 방법을 제어하는 경우가 더 많기 때문에, 기존 WinForm의 객체들처럼 각각 만들어져있다면 사용하기에 정말 편할 것 같아서 class와 상속 들에 대해서 알아보게 되었다.

먼저, 기본적으로 javascript에서는 class라는 키워드는 존재하지 않는다. function 키워드를 이용해서 객체를 선언 하게 된다.

1. class의 선언

function Product() {    this.name = '';    this.price = 0;    this.SetValues = function(name, price) {        this.name = name;        this.price = price;    };            this.ShowName = function(id) {        this.ShowAlert();        $('#' + id).html('Product' + this.name);    };        this.ShowAlert = function() {        console.debug('this is product message ' + this.name);    };}

class의 선언은 매우 단순한것이. 일반적인 함수의 형태를 취하면서 만들어지게 된다. prototype을 선언해서 만드는 법도 가능하지만, 코드의 가독성이 이게 더 편한 것 같아서. 이 방법을 주로 사용하는 것이 더 나아보인다.
private method나 private property의 경우에는 var 키워드를 이용해서 만들어주고, public의 경우 this 키워드를 이용해서 선언할 수 있다.

2. class의 상속

function KrProduct() {    Product.call(this);    this.ShowAlert = function() {        console.debug('this is krProduct message ' + this.name);            };}

call method를 이용해서 class를 상속한다.
override 를 하고 싶은 경우, 기존의 method를 동일하게 재 선언해주면 된다.
주의점은 javascript의 객체를 만들때는 protected가 없다는 것이다. 상속된 객체에서 절대로 private method나 property는 사용하지 못한다. 이를 고려해서 만들어줘야지 된다. (객체의 캡슐화에는 매우 불리한 것 같다.)

3. 실행 결과.
$(function() {    $('#testButton').click(function() {        var product = new Product();        var product2 = new KrProduct();        var product3 = new KrProduct();        product.SetValues("Product Name", 0);        product2.SetValues("Product2 Name", 1);        product3.SetValues("Product3 Name", 2);         product.ShowName('testDisplay');        product2.ShowName('testDisplay2');        product3.ShowName('testDisplay3');    });})


override 시킨 method가 차례대로 실행되는 것을 알 수 있다.

Posted by Y2K
,
Controller 객체를 사용해서 각 method를 테스트하는 방법은 매우 뛰어난 테스팅 방법이지만, 불행하게도 Session 및 Identify에 대한 내용을 같이 테스팅 하는 것은 불가능하다. 특히, Session에 Wizard Data 또는 사용자에 따른 개인 정보를 저장하고 있는 경우에는 Controller 객체만을 사용하는 것은 불가능하다.

그래서, Mock을 이용해서 HttpContext를 구성하고, 구성된 HttpContext를 ControllerContext로 구성하여 Controller를 사용하게 되면 위와 같은 문제를 모두 해결 할 수 있다.


public class FakeSession : HttpSessionStateBase
{
    private readonly SessionStateItemCollection _sessionItems;
    public FakeSession(SessionStateItemCollection sessionItems)
    {
        _sessionItems = sessionItems;
    }

    public override void Add(string name, object value)
    {
        _sessionItems[name] = value;
    }

    public override int Count
    {
        get
        {
            return _sessionItems.Count;
        }
    }

    public override IEnumerator GetEnumerator()
    {
        return _sessionItems.GetEnumerator();
    }

    public override NameObjectCollectionBase.KeysCollection Keys
    {
        get
        {
            return _sessionItems.Keys;
        }
    }

    public override object this[string name]
    {
        get
        {
            return _sessionItems[name];
        }
        set
        {
            _sessionItems[name] = value;
        }
    }

    public override object this[int index]
    {
        get
        {
            return _sessionItems[index];
        }
        set
        {
            _sessionItems[index] = value;
        }
    }
    public override void Remove(string name)
    {
        _sessionItems.Remove(name);
        }
}

protected T GetContextedController(T controller, string userName, FakeSession sessionState) where T : ControllerBase
{
    //Register Route
    RouteCollection routes = new RouteCollection();
    MvcApplication.RegisterRoutes(routes);

    //Build Mock HttpContext, Request, Response
    var mockHttpContext = new Moq.Mock();
    var mockRequest = new Moq.Mock();
    var mockResponse = new Moq.Mock();

    //Setup Mock HttpContext 
    mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
    mockHttpContext.Setup(x => x.Response).Returns(mockResponse.Object);
    mockHttpContext.Setup(x => x.Session).Returns(sessionState);

    if(string.IsNullOrEmpty(userName))
    {
        mockHttpContext.Setup(x => x.User.Identity.IsAuthenticated).Returns(false);
        mockRequest.Setup(x => x.IsAuthenticated).Returns(false);
    }
    else
    {
        mockHttpContext.Setup(x => x.User.Identity.Name).Returns(userName);
        mockHttpContext.Setup(x => x.User.Identity.IsAuthenticated).Returns(true);
        mockRequest.Setup(x => x.IsAuthenticated).Returns(true);
    }
    mockRequest.Setup(x => x.ApplicationPath).Returns("/");

    // Build Request Context
    var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
    controller.ControllerContext = new ControllerContext(ctx, controller);
    return controller;
}


사용 방법은 다음과 같다.
[Test]
public void Start()
{
    _controller = new VirtualMachineController();
    SessionStateItemCollection sessionItemCollections = new SessionStateItemCollection();
    sessionItemCollections[SessionConstants.Account] = _account;
    sessionItemCollections[SessionConstants.ZoneList] = tempZoneList;

    _session = new FakeSession(sessionItemCollections);
    _controller = GetContextedController(_controller, LocalConf.AccountName, _session);
    _controller.Start("tempVmName");
}
Posted by Y2K
,