Guest User

Untitled

a guest
Aug 20th, 2018
3,954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. @isTest(seeAllData=true)
  2.  
  3.  
  4. private class BuyTest {
  5. @isTest
  6.  
  7. static void adding() {
  8.  
  9. PageReference pageRef = Page.Buy;
  10. system.test.setCurrentPageReference(pageRef);
  11. Product_Table__c product = [SELECT Id, Name, Units_Available__c FROM Product_Table__c LIMIT 1];
  12. ApexPages.currentPage().getParameters().put('id', product.id);
  13.  
  14. Buy test = new Buy();
  15. test.unitsAvailable = product.Units_Available__c;
  16. test.units = 1000;
  17. test.adding();
  18. System.assertEquals('This amount of items are not available now', ApexPages.getMessages().get(0).getSummary());
  19. test.units = 1;
  20. test.firstName ='vasya';
  21. test.lastName='asd';
  22. test.email= 'weregon7@gmail.com';
  23. test.adding();
  24. Contact contact = [SELECT FirstName, LastName, Email FROM Contact WHERE Email = :test.email limit 1];
  25. System.assertEquals('vasya', contact.FirstName);
  26. test.email = 'ookljkflf@mail.ru';
  27. test.adding();
  28. Contact newContact = [SELECT FirstName, Email FROM Contact WHERE Email = :test.email limit 1];
  29. System.assertEquals('ookljkflf@mail.ru', newContact.Email);
  30. System.assertEquals('vasya', contact.FirstName);
  31. Order_Table__c table = [SELECT Id, Product__c FROM Order_Table__c WHERE Product__c =: ApexPages.currentPage().getParameters().get('id') LIMIT 1];
  32. System.assertEquals(table.Product__c, product.id);
  33. System.assertEquals('Thanks for your order', ApexPages.getMessages().get(1).getSummary());
  34.  
  35. }
  36. }
Add Comment
Please, Sign In to add comment