沙世明
2022-04-08 eeb7c0a2d6f037d515bb822d739036b69c4dc73a
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
/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditAddressControllerTest {
    static testMethod void testMethod1() {
     
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Address__c ad = TestDataUtility.CreateAddresses(1)[0];
 
        Test.startTest();
        ad.Using_Datetime__c = null;
        ApexPages.StandardController con =  new ApexPages.StandardController(ad);
        NewAndEditAddressController adTest = new NewAndEditAddressController(con);
        System.debug('adTest----'+adTest);
        Map<String,Object> mapTest = new Map<String,Object>();
        mapTest.put('Contacts__c',ad.Contacts__c);
        mapTest.put('Using_Datetime__c',ad.Using_Datetime__c);
        mapTest.put('Customer__c',ad.Customer__c);
        mapTest.put('Telephone__c',ad.Telephone__c);
        mapTest.put('Province__c',ad.Province__c);
        mapTest.put('City__c',ad.City__c);
        mapTest.put('Detailed_Address__c',ad.Detailed_Address__c);
        mapTest.put('Address_Classification__c',ad.Address_Classification__c);
        String addressJson = JSON.serialize(mapTest);
  
        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',True);
        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
 
    static testMethod void testMethod2() {
     
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Address__c ad = TestDataUtility.CreateAddresses(1)[0];
        ad.Using_Datetime__c = Datetime.now();
        ad.IsFromSPO__c = false;
        insert ad;
 
        Test.startTest();
        System.debug('ad' + ad);
        ApexPages.StandardController con =  new ApexPages.StandardController(ad);
        System.debug('con.Id' + con.getRecord().Id);
        NewAndEditAddressController adTest = new NewAndEditAddressController(con);
        System.debug('adTest----'+adTest);
        Map<String,Object> mapTest = new Map<String,Object>();
        mapTest.put('Contacts__c',ad.Contacts__c);
        mapTest.put('Using_Datetime__c',ad.Using_Datetime__c);
        mapTest.put('Customer__c',ad.Customer__c);
        mapTest.put('Telephone__c',ad.Telephone__c);
        mapTest.put('Province__c',ad.Province__c);
        mapTest.put('City__c',ad.City__c);
        mapTest.put('Detailed_Address__c',ad.Detailed_Address__c);
        mapTest.put('Address_Classification__c',ad.Address_Classification__c);
        mapTest.put('IsFromSPO__c',ad.IsFromSPO__c);
        String addressJson = JSON.serialize(mapTest);
        System.debug('addressJson:' + addressJson);
 
        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
}