Loosely Coupled , Test Driven Design and API Centric Application

I now have my Asp.net MVC WebAPI 2 implemented with Test Driven Design.

Loosely Coupled with the help of Unity and TDDed with Moq.

Now I can begin porting my Real Estate Billing Management System coded in PHP and Zend Framework

public class PeopleRepository<T> : IPeopleRepository<T> where T : class
{
   protected AppDBContext db;

   public PeopleRepository(IUnitOfWork unitOfWork)
   {
     db = unitOfWork.DbContext;
   }
}
   public interface IPeopleRepository<T> where T : class
   {
      IEnumerable<T> FindAll();
      T GetByID(int id);
      void Delete(int id);
      void SaveOrUpdate(T customer);
   }
   public interface IPeopleRepository<T> where T : class
   {
      IEnumerable<T> FindAll();
      T GetByID(int id);
      void Delete(int id);
      void SaveOrUpdate(T customer);
   }

I will have this Application front ended with AngularJs2 because of TypeScript.

I heard that ReactJs is becoming more popular. But just *7^&off!

Unity Dependency Injection, Test Driven Design and Entity Framework

Early Today I struggled on implementing Dependency Injection using Unity on a new Asp.net MVC 5 setup. I struggle so much that I move on to unit testing instead just to make some progress today using Moq.

So Unit Testing my Project right now is using only the Repository Pattern. I’ll be back on Dependency Injection Containers Maybe next week. I’ll use this Repository Pattern setup to finish my 2 projects this week.

Here are some code highlights

Instantiating your controller

private ICustomerRepository _customerRepository;

public CustomersController(ICustomerRepository customerRepository)
{
  _customerRepository = customerRepository;
}

public CustomersController()
{
  _customerRepository = new CustomerRepository();
}

Moq Unit Testing

 //arrange
 var customers = new List<Customer>();
 customers.Add(customer);
           
 repositoryMock.Setup(x => x.FindAll()).Returns(customers.AsQueryable());

 //act
 var result = controller.Lists() as ViewResult;
 var model = result.ViewData.Model as List<Customer>;

 //assert
 Assert.AreEqual(1, model.Count);
 Assert.AreEqual("Lists", result.ViewName);

Repository Interface for Customers Implementation

public interface ICustomerRepository : IDisposable
{
  IEnumerable<Customer> FindAll();
  Customer GetByID(int id);      
  void Delete(int id);
  void SaveOrUpdate(Customer customer);
}

This will now be my base code to implement by Billing and Payroll Applications.

Bye!