public void CallingAddShouldPushTheObjectToTheRepository() { var mockRepo = new Mock <IMyObjectRepository>(); var mockDAO = new Mock <IMyObjectDAO>(); var mockAuditLog = new Mock <IAuditLogger>(); var myBLL = new MyObjectLogic(mockRepo.Object, mockDAO.Object, mockAuditLog.Object); // // Note that we're not setting CreatedDate // var myObject = new MyObject { Id = Guid.NewGuid(), Name = "UnitTest" }; myBLL.AddMyObject(myObject); // // Compare the received object with what we expected // mockRepo.Verify(repo => repo.Add(It.Is <MyObject>(item => item.Id == myObject.Id && item.Name == myObject.Name && item.Created != default(DateTime) ))); }
public void CallingAddWithANullShouldThrow() { var mockRepo = new Mock <IMyObjectRepository>(); var mockDAO = new Mock <IMyObjectDAO>(); var mockAuditLog = new Mock <IAuditLogger>(); var myBLL = new MyObjectLogic(mockRepo.Object, mockDAO.Object, mockAuditLog.Object); Assert.Throws <ArgumentNullException>(() => myBLL.AddMyObject(null)); }
public void CallingAddShouldBeAudited() { var mockRepo = new Mock <IMyObjectRepository>(); var mockDAO = new Mock <IMyObjectDAO>(); var mockAuditLog = new Mock <IAuditLogger>(); var myBLL = new MyObjectLogic(mockRepo.Object, mockDAO.Object, mockAuditLog.Object); myBLL.AddMyObject(new MyObject { Id = Guid.NewGuid(), Name = "UnitTest", Created = new DateTime(2015, 2, 21) }); // We expect a message that starts with "Adding item " mockAuditLog.Verify(auditLog => auditLog.Log(It.Is <String>(s => s == "Adding item {0}"), It.IsAny <Guid>())); }
public void CallingAddWithAnInvalidObjectShouldThrow() { var mockRepo = new Mock <IMyObjectRepository>(); var mockDAO = new Mock <IMyObjectDAO>(); var mockAuditLog = new Mock <IAuditLogger>(); var myBLL = new MyObjectLogic(mockRepo.Object, mockDAO.Object, mockAuditLog.Object); Assert.Throws <ValidationException>(() => myBLL.AddMyObject( new MyObject { Id = Guid.NewGuid(), Name = null, Created = new DateTime(2015, 2, 21) } )); }