高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
@isTest
    private class PowerBIBaseHandlerTest {
        @isTest
        private static void test1(){
            PowerBIBaseHandler controller = new PowerBIBaseHandler();
            controller.test1();
       
        }
/*
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    //data setup
    private static void setuserset(){
        PowerBISyncDefine__c Product2 = new PowerBISyncDefine__c();
        Product2.Name = 'Product2';
        Product2.To_Table__c = 'BI_Product2__c';
        insert(Product2);
    }
    private static void setuserseterr(){
        PowerBISyncDefine__c Product2 = new PowerBISyncDefine__c();
        Product2.Name = 'Product2';
        Product2.To_Table__c = 'BI_Product2__c';
        Product2.Delete_Flag__c = true;
        insert(Product2);
    }
 
    //test
    private static testMethod void insertcase() {
        setuserset();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'zzjtestuse02';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct02);
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c,CurrencyIsoCode
                    FROM BI_Product2__c
                    WHERE Name = :testproduct02.Name];
 
            System.assertEquals(1,testBIproduct.size());
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_Id__c);
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_LookUp_Id__c);
            System.assertEquals(testproduct02.Name, testBIproduct[0].Name);
            System.assertEquals(testproduct02.CurrencyIsoCode, testBIproduct[0].CurrencyIsoCode);
        Test.stopTest();
    }
 
    private static testMethod void upsertcase() {
        setuserset();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'zzjtestuse02';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct02);
            testproduct02.CurrencyIsoCode = 'USD';
            upsert(testproduct02);
 
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c
                    WHERE Name = :testproduct02.Name];
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_Id__c);
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_LookUp_Id__c);
            System.assertEquals(testproduct02.Name, testBIproduct[0].Name);
            System.assertEquals(testproduct02.CurrencyIsoCode, testBIproduct[0].CurrencyIsoCode);
        Test.stopTest();
    }
 
    private static testMethod void deletecase() {
        setuserset();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        Product2 testproduct01 = new Product2();
        testproduct01.Name = 'zzjtestuse01';
        testproduct01.CurrencyIsoCode = 'CNY';
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'zzjtestuse02';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct01);
            Insert(testproduct02);
            delete(testproduct02);
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c
                    ORDER BY Name];
 
            System.assertEquals(1,testBIproduct.size());
            System.assertEquals(testproduct01.Id, testBIproduct[0].PowerBI_Source_Id__c);
            System.assertEquals(testproduct01.Id, testBIproduct[0].PowerBI_Source_LookUp_Id__c);
            System.assertEquals(testproduct01.Name, testBIproduct[0].Name);
            System.assertEquals(testproduct01.CurrencyIsoCode, testBIproduct[0].CurrencyIsoCode);
        Test.stopTest();
    }
 
    private static testMethod void undeletecase() {
        setuserset();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        list<Product2> testproduct = new list<Product2>();
        Product2 testproduct01 = new Product2();
        testproduct01.Name = 'zzjtestuse01';
        testproduct01.CurrencyIsoCode = 'CNY';
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'zzjtestuse02';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct01);
            Insert(testproduct02);
 
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c
                    ORDER BY Name];
 
            System.assertEquals(2,testBIproduct.size());
 
            delete(testproduct02);
 
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c
                    ORDER BY Name];
 
            System.assertEquals(1,testBIproduct.size());
 
 
            testproduct = [SELECT Name, Id, CurrencyIsoCode
                    FROM Product2
                    WHERE Name = 'zzjtestuse02'
                    ORDER BY Name
                    ALL ROWS];
 
            undelete(testproduct);
 
 
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c
                    ORDER BY Name];
 
            System.assertEquals(2,testBIproduct.size());
            System.assertEquals(testproduct01.Id, testBIproduct[0].PowerBI_Source_Id__c);
            System.assertEquals(testproduct01.Id, testBIproduct[0].PowerBI_Source_LookUp_Id__c);
            System.assertEquals(testproduct01.Name, testBIproduct[0].Name);
            System.assertEquals(testproduct01.CurrencyIsoCode, testBIproduct[0].CurrencyIsoCode);
            System.assertEquals(testproduct02.Id, testBIproduct[1].PowerBI_Source_Id__c);
            System.assertEquals(testproduct02.Id, testBIproduct[1].PowerBI_Source_LookUp_Id__c);
            System.assertEquals(testproduct02.Name, testBIproduct[1].Name);
            System.assertEquals(testproduct02.CurrencyIsoCode, testBIproduct[1].CurrencyIsoCode);
        Test.stopTest();
    }
 
    private static testMethod void longnamecase() {
        setuserset();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct02);
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c, CurrencyIsoCode
                    FROM BI_Product2__c];
            System.assertEquals(1,testBIproduct.size());
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_Id__c);
            System.assertEquals(testproduct02.Id, testBIproduct[0].PowerBI_Source_LookUp_Id__c);
            System.assertEquals('aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrsssstttt', testBIproduct[0].Name);
            System.assertEquals(testproduct02.CurrencyIsoCode, testBIproduct[0].CurrencyIsoCode);
        Test.stopTest();
 
    }
 
    private static testMethod void deleteflagtruecase() {
        setuserseterr();
 
        list<BI_Product2__c> testBIproduct = new list<BI_Product2__c>();
        Product2 testproduct02 = new Product2();
        testproduct02.Name = 'zzjtestuse02';
        testproduct02.CurrencyIsoCode = 'CNY';
 
        Test.startTest();
            Insert(testproduct02);
            testBIproduct = [SELECT Name, PowerBI_Source_Id__c, PowerBI_Source_LookUp_Id__c,CurrencyIsoCode
                    FROM BI_Product2__c
                    WHERE Name = :testproduct02.Name];
 
            System.assertEquals(0,testBIproduct.size());
        Test.stopTest();
 
    }
 
    private static testMethod void triggertest() {
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        System.Test.startTest();
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        System.Test.stopTest();
 
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = date.newinstance(2022, 11, 30);
        insert opp;
 
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        product.Category3__c = '主机';
        product.MDM_Model_No__c = 'dsfdf_USG-400_jfoewf';
        product.ProductCode_Ext__c = 'dsfad';
        insert product;
 
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert(oppli);
 
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            ContractAmount__c = 10,
            DeliveryDate__c = Date.today());
        //System.Test.startTest();
        insert (Sac);
        //System.Test.stopTest();
    }
    */
}