@isTest
private class AssetNumberChangeControllerTest {
	@isTest static void test_method_one() {
		List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
        //样机客户
        Account acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;

		// 产品
        Product2 prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;

        Product2 prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};

        // 保有设备 (数量管理)
        Asset asset = new Asset();
        asset.RecordTypeId = loa_number[0].Id;
        asset.SerialNumber = 'asset';
        asset.Name = 'asset';
        asset.AccountId = acc.Id;
        asset.Product2Id = prd2.Id;
        asset.Quantity = 1;
        asset.Status = '在库';
        asset.Equipment_Type__c = 'IE';
        asset.loaner_place__c = '广州办';
        asset.total_number__c = 20;
        asset.Remarks2__c = 'asset';

        insert asset;

        PageReference page = new PageReference('/apex/AssetNumberChange?id=' + asset.Id);
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
        AssetNumberChangeController loanerApplyCon = new AssetNumberChangeController();
        loanerApplyCon.init();
        System.assertEquals('asset', loanerApplyCon.ast.Name);
        loanerApplyCon.saveBtn();
        loanerApplyCon.lch.change_content__c= '追加';
        loanerApplyCon.saveBtn();
        loanerApplyCon.lch.change_number__c= 30;
        loanerApplyCon.saveBtn();
        asset = [select Id,total_number__c from asset where Id = :asset.Id];
        System.assertEquals(50, asset.total_number__c);

        loanerApplyCon.cancelBtn();
	}
}