public decimal CustomerBalance(Customer customer) { //assume Dictionary <Account, Role> accounts = new Dictionary <Account, Role>(); accounts.Add(new Account { Id = 1, Balance = 100 }, new Role()); accounts.Add(new Account { Id = 2, Balance = -200 }, new Role()); PexAssume.Implies(customer != null, () => customer.RelatedAccounts = accounts); //arrange SIRepository repository = new SIRepository(); SICustomerRepository customerRepository = new SICustomerRepository(); SIAccountServices accountServices = new SIAccountServices(); IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator(); accountServices.BalanceAccount = (x) => x.Balance; CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator); var result = services.CustomerBalance(customer); PexAssert.Case(customer.RelatedAccounts == accounts).Implies(() => result == -100); return(result); }
public decimal ComputeInterest(Account account, double annualRate, int months) { PexAssume.Implies(account != null, () => account.Balance = 1000); PexAssume.IsTrue(annualRate != 0); PexAssume.IsTrue(months != 0); SIAccountRepository accountRepository = new SIAccountRepository(); SIOperationRepository operationRepository = new SIOperationRepository(); AccountService service = new AccountService(accountRepository, operationRepository); decimal result = service.ComputeInterest(account, annualRate, months); return(result); }