Wednesday, October 27, 2010

DDD IoC Moq MVC ... Time to catch up

After I joined HP, I hadn't realistically had the time to keep up with the changes to the .NET platform in regards to frameworks, design patterns, etc. I'm between development cycles right now (going to be doing a custom SharePoint 2010 project that I'm looking forward to), so I figured this was the best time to get back up to speed. My current interest is in learning more about Domain Driven Design (DDD), the Repository Pattern, Inversion of Control (IoC), Microsoft ASP.NET MVC2, Microsoft Unity2, Microsoft Entity Framework 4 (EF4) and Moq. Just some quick links for myself ... Just some quick code for myself ...

    [TestClass]
public class ContactTest
{
#region Private Variables
private Mock<icontactrepository> mockRepository;
private IContactService service;
#endregion

#region Test Initializations
[TestInitialize]
public void Initialize()
{
this.mockRepository = new Mock<icontactrepository>();
this.service = new ContactService(this.mockRepository.Object);
}
#endregion

[TestMethod]
public void UserCanGetListOfContacts()
{
// Arrange
Contact mockContact = new Contact() { ID = 1, LastUpdated = DateTime.Now, LastUpdatedBy = "Brandon", Name = "Brandon Lind", Ranking = 1 };
this.mockRepository.Setup(m =&gt; m.GetAll()).Returns(new List<contact>() { mockContact });

// Act
var result = service.GetAll();

// Assert
Assert.IsInstanceOfType(result, typeof(ICollection<contact>));
}
}

No comments:

Post a Comment