SASUnit Examples  Version 1.5.0
database_test.sas
Go to the documentation of this file.
1 
32 /*-- Creation of base datasets -----------------------------------------*/
33 %initTestcase(i_object=basedatasets.sas, i_desc=Creation of base datasets)
34 %basedatasets
35 %endTestCall()
36 
37 %assertTableExists (i_libref =work
38  ,i_memname=Customer
39  ,i_desc =Table was successfuly created?
40  )
41 %assertRecordCount (i_libref =work
42  ,i_memname =Customer
43  ,i_recordsExp=5
44  ,i_desc =Does table contain all expected Rows?
45  )
46 %assertPrimaryKey (i_library =work
47  ,i_dataset =Customer
48  ,i_variables=CustomerNumber
49  ,i_desc =Is the generated key unique?
50  )
51 
52 %assertTableExists (i_libref =work
53  ,i_memname=Contracts
54  ,i_desc =Table was successfuly created?
55  )
56 %assertRecordCount (i_libref =work
57  ,i_memname =Contracts
58  ,i_recordsExp=8
59  ,i_desc =Does table contain all expected Rows?
60  )
61 %assertPrimaryKey (i_library =work
62  ,i_dataset =Contracts
63  ,i_variables=ContractNumber)
64 
65 %assertRecordExists (i_dataset =work.Contracts
66  ,i_whereExpr=%str(ContractType=1)
67  ,i_desc =Do we have at least one record per contract type 1?
68  );
69 %assertRecordExists (i_dataset =work.Contracts
70  ,i_whereExpr=%str(ContractType=2)
71  ,i_desc =Do we have at least one record per contract type 2?
72  );
73 %assertRecordExists (i_dataset =work.Contracts
74  ,i_whereExpr=%str(ContractType=3)
75  ,i_desc =Do we have at least one record per contract type 3?
76  );
77 
78 %assertTableExists (i_libref =work
79  ,i_memname=CustomerContracts
80  ,i_desc =Table was successfuly created?
81  )
82 %assertRecordCount (i_libref =work
83  ,i_memname =CustomerContracts
84  ,i_recordsExp=8
85  ,i_desc =Does table contain all expected Rows?
86  )
87 %assertPrimaryKey (i_library =work
88  ,i_dataset =CustomerContracts
89  ,i_variables=ContractNumber CustomerNumber)
90 
91 %assertForeignKey (i_mstrLib =work
92  ,i_mstMem =CustomerContracts
93  ,i_mstKey =ContractNumber
94  ,i_lookupLib=work
95  ,i_lookupMem=Contracts
96  ,i_lookupKey=ContractNumber
97  ,i_desc =Check ContractNumber
98  );
99 
100 %assertForeignKey (i_mstrLib =work
101  ,i_mstMem =CustomerContracts
102  ,i_mstKey =CustomerNumber
103  ,i_lookupLib=work
104  ,i_lookupMem=Customer
105  ,i_lookupKey=CustomerNumber
106  ,i_desc =Check CustomerNumber
107  );
108 
109 %assertLog (i_errors=0, i_warnings=0)
110 %endTestCase()
111 
112 /*-- Creation of combined table --------------------------------------------*/
113 %initTestcase(i_object=combineddataset.sas, i_desc=Creating combined dataset)
114 %combineddataset
115 %endTestCall()
116 
117 %assertTableExists (i_libref =work
118  ,i_memname=CombinedDataset
119  ,i_desc =Table was successfuly created?
120  )
121 %assertRecordCount (i_libref =work
122  ,i_memname =CombinedDataset
123  ,i_recordsExp=8
124  ,i_desc =Does table contain all expected Rows?
125  )
126 %assertPrimaryKey (i_library =work
127  ,i_dataset =CombinedDataset
128  ,i_variables=ContractNumber CustomerNumber)
129 
130 %assertRowExpression(i_libref =work
131  ,i_memname =CustomerContracts
132  ,i_where =%str(not missing %(ContractNumber%))
133  ,i_desc =There should be no customers without contracts
134  );
135 
136 %assertRowExpression(i_libref =work
137  ,i_memname =CustomerContracts
138  ,i_where =%str(not missing %(CustomerNumber%))
139  ,i_desc =There should be no contracts without customer
140  );
141 
142 %assertLog (i_errors=0, i_warnings=0)
143 %endTestCase()