コード例 #1
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanInsert()
        {
            var flyRepository = new Mock<IFlyRepository>();
            var flyService = new FlyService(flyRepository.Object);

            var fly = new Fly { DateOfFly = DateTime.Now, Description = "First fly", Owner = new FlyOwner { Id = 1, Name = "Owner 1" } };

            flyService.Insert(fly);

            flyRepository.Verify(v => v.Insert(It.IsAny<Fly>()), Times.Once());
        }
コード例 #2
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        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());
        }
コード例 #3
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanDelete()
        {
            var flyRepository = new Mock<IFlyRepository>();

            flyRepository.Setup(s => s.GetById(It.IsAny<int>())).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);

            flyService.Delete(1);

            flyRepository.Verify(v => v.Delete(It.IsAny<int>()), Times.Once());
        }
コード例 #4
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanNotInsertWithNullFly()
        {
            var flyRepository = new Mock<IFlyRepository>();
            var flyService = new FlyService(flyRepository.Object);

            try
            {
                flyService.Insert(null);
                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argex)
            {
                Assert.AreEqual(argex.Message, "Fly is required!");
                flyRepository.Verify(v => v.Insert(It.IsAny<Fly>()), Times.Never());
            }
        }
コード例 #5
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanGetAll()
        {
            var flyRepository = new Mock<IFlyRepository>();

            flyRepository.Setup(s => s.GetAll()).Returns(new List<Fly>
                {
                    new Fly { Id = 1, DateOfFly = DateTime.Now },
                    new Fly { Id = 2, DateOfFly = DateTime.Now }
                }.AsQueryable());

            var flyService = new FlyService(flyRepository.Object);

            var flys = flyService.GetAll();

            Assert.AreEqual(flys.Count(), 2);
            Assert.AreEqual(flys.First().Id, 1);
            flyRepository.Verify(v => v.GetAll(), Times.Once());
        }
コード例 #6
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanNotUpdateWithoutOwner()
        {
            var flyRepository = new Mock<IFlyRepository>();
            var flyService = new FlyService(flyRepository.Object);

            try
            {
                flyService.Update(new Fly { Id = 1 });
                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argex)
            {
                Assert.AreEqual("Fly not exists!", argex.Message);
                flyRepository.Verify(v => v.Update(It.IsAny<Fly>()), Times.Never());
            }

            flyRepository.Verify(v => v.GetById(It.IsAny<int>()), Times.Once());
        }
コード例 #7
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        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());
        }
コード例 #8
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanNotUpdateAbsentFly()
        {
            var flyRepository = new Mock<IFlyRepository>();

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

            var flyService = new FlyService(flyRepository.Object);

            try
            {
                flyService.Update(new Fly { Id = 0 });
                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argex)
            {
                Assert.AreEqual("Fly not exists!", argex.Message);
                flyRepository.Verify(v => v.Update(It.IsAny<Fly>()), Times.Never());
            }

            flyRepository.Verify(v => v.GetById(It.IsAny<int>()), Times.Once());
        }
コード例 #9
0
ファイル: FlyServiceTest.cs プロジェクト: pasena/FlyanDo
        public void CanNotInsertWithoutOwner()
        {
            var flyRepository = new Mock<IFlyRepository>();
            var flyService = new FlyService(flyRepository.Object);

            var fly = new Fly { DateOfFly = DateTime.Now, Description = "First fly" };

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