public void CanUpdate() { var ownerRepository = new Mock<IFlyOwnerRepository>(); ownerRepository.Setup(s => s.GetById(1)).Returns(new FlyOwner { Id = 1, Name = "First Owner", NickName = "Nick" }); var ownerService = new FlyOwnerService(ownerRepository.Object); var owner = new FlyOwner { Id = 1, Name = "Second Owner", NickName = "Nick" }; ownerService.Update(owner); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Once()); }
public void CanNotUpdateWithNullOwner() { var ownerRepository = new Mock<IFlyOwnerRepository>(); var ownerService = new FlyOwnerService(ownerRepository.Object); try { ownerService.Update(null); Assert.Fail("Validation not implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Owner is required!", argex.Message); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Never()); } }
public void CanNotUpdateWithoutNickName() { var ownerRepository = new Mock<IFlyOwnerRepository>(); var ownerService = new FlyOwnerService(ownerRepository.Object); try { ownerService.Update(new FlyOwner { Name = "Firt Owner", NickName = string.Empty }); Assert.Fail("Validation not implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Nick is required!", argex.Message); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Never()); } }
public void CanNotUpdateAbsentOwner() { var ownerRepository = new Mock<IFlyOwnerRepository>(); ownerRepository.Setup(s => s.GetById(1)).Returns(new FlyOwner { Id = 1, Name = "First Owner", NickName = "Nick" }); var ownerService = new FlyOwnerService(ownerRepository.Object); try { var owner = new FlyOwner { Id = 2, Name = "Second Owner", NickName = "Nick" }; ownerService.Update(owner); Assert.Fail("Validation not Implemented!"); } catch (ArgumentException argex) { Assert.AreEqual("Owner not exists!", argex.Message); ownerRepository.Verify(v => v.Update(It.IsAny<FlyOwner>()), Times.Never()); } }