public void CanInsertOwner() { var ownerRepository = new Mock<IFlyOwnerRepository>(); var ownerService = new FlyOwnerService(ownerRepository.Object); ownerService.Insert(new FlyOwner { Name = "Firt Owner", NickName = "Nick" }); ownerRepository.Verify(v => v.Insert(It.IsAny<FlyOwner>()), Times.Once()); }
public void CanNotInsertWithoutName() { var ownerRepository = new Mock<IFlyOwnerRepository>(); var ownerService = new FlyOwnerService(ownerRepository.Object); try { ownerService.Insert(new FlyOwner { Name = string.Empty }); Assert.Fail("Validation not implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Name is required!", argex.Message); ownerRepository.Verify(v => v.Insert(It.IsAny<FlyOwner>()), Times.Never()); } }