Ejemplo n.º 1
0
        public void CanGetById()
        {
            var flyRepository = new Mock<IFlyRepository>();

            flyRepository.Setup(s => s.GetById(It.IsAny<int>())).Returns(
                    new Fly { Id = 1, DateOfFly = DateTime.Now });

            var flyService = new FlyService(flyRepository.Object);

            Assert.AreEqual(flyService.GetById(1).Id, 1);
            flyRepository.Verify(v => v.GetById(It.IsAny<int>()), Times.Once());
        }
Ejemplo n.º 2
0
        public void CanNotUpdateWithoutDescription()
        {
            var flyRepository = new Mock<IFlyRepository>();

            flyRepository.Setup(s => s.GetById(1)).Returns(new Fly { Id = 1, DateOfFly = DateTime.Now, Description="First Fly", Owner = new FlyOwner { Id = 1, Name = "Owner 1" } });

            var flyService = new FlyService(flyRepository.Object);

            try
            {
                var fly = flyService.GetById(1);

                fly.Description = string.Empty;

                flyService.Update(fly);

                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argex)
            {
                Assert.AreEqual("Description is required!", argex.Message);
                flyRepository.Verify(v => v.Update(It.IsAny<Fly>()), Times.Never());
            }

            flyRepository.Verify(v => v.GetById(It.IsAny<int>()), Times.AtLeastOnce());
        }