public void TestGetCustomerById() { CustomerBusinessComponent service = new CustomerBusinessComponent(this.context); Customer customer = new Customer() {CustomerId = 123}; Expect.Once.On(context).Method("GetById").Will(Return.Value(customer)); Customer resultCustomer = service.GetCustomerById(123); Assert.AreEqual<decimal>(customer.CustomerId, resultCustomer.CustomerId); mockBuilder.VerifyAllExpectationsHaveBeenMet(); }
public void TestGetCustomerByCriteria() { CustomerBusinessComponent service = new CustomerBusinessComponent(this.context); Address address = new Address {AddressId = 12345, City = "FakeCity"}; Customer customer = new Customer {CustomerId = 456, Name = "FakeName", Addresses = new List<Address> {address}.AsQueryable()}; IList<Customer> customers = new List<Customer>(); customers.Add(customer); foreach (CustomerSearchType type in Enum.GetValues(typeof (CustomerSearchType))) { Expect.Once.On(context).Method("GetAll").Will(Return.Value(customers.AsQueryable())); IQueryable<Customer> resultCustomers = service.GetCustomersByCriteria(type, "FakeCity", "FakeName"); Assert.AreEqual<decimal>(1, resultCustomers.Count()); Assert.AreEqual<decimal>(customer.CustomerId, resultCustomers.First().CustomerId); } mockBuilder.VerifyAllExpectationsHaveBeenMet(); }
public void TestDeleteCustomer() { CustomerBusinessComponent service = new CustomerBusinessComponent(this.context); Expect.Once.On(context).Method("DeleteCustomer").With(1); service.DeleteCustomer(1); mockBuilder.VerifyAllExpectationsHaveBeenMet(); }
public void TestStoreCustomer() { int customerId = 123; CustomerBusinessComponent service = new CustomerBusinessComponent(this.context); Customer customer = new Customer() {CustomerId = customerId}; List<ChangeItem> changeItems = new List<ChangeItem> { new ChangeItem(ChangeType.ChildInsert, new Address()), new ChangeItem(ChangeType.ChildUpate, new Address()), new ChangeItem(ChangeType.ChildDelete, new Address()) }; Expect.Once.On(context).Method("SaveCustomer").Will(Return.Value(customerId)); Expect.Once.On(context).Method("SaveAddress").Will(Return.Value(1)); Expect.Once.On(context).Method("SaveAddress").Will(Return.Value(1)); Expect.Once.On(context).Method("DeleteAddress"); int resultCustomerId = service.StoreCustomer(customer, changeItems); Assert.AreEqual<int>(customerId, resultCustomerId); mockBuilder.VerifyAllExpectationsHaveBeenMet(); }