public void Can_Get()
        {
            //Prepare
            var       goalRepository = new GoalRepository();
            const int existedGoalId  = 1;
            var       goal           = new Goal
            {
                Id = existedGoalId
            };

            goalRepository.Add(goal);
            //Pre-Validate
            var existedGoal = goalRepository.Goals.First(e => e.Id == existedGoalId);

            Assert.Equal(existedGoalId, existedGoal.Id);
            //Perform
            var result = goalRepository.Get(goal.Id);

            //Post-Validate
            Assert.Equal(result, goal);
        }
Exemplo n.º 2
0
        public void GoalRepository()
        {
            Mock <IDbSetFactory> factory = new Mock <IDbSetFactory>();
            Mock <DbSet <Goal> > dbSet   = new Mock <DbSet <Goal> >();

            factory.Setup(m => m.CreateDbSet <Goal>()).Returns(dbSet.Object);

            GoalRepository repo = new GoalRepository(factory.Object);

            var Goal = new Goal();

            var sequence = new MockSequence();

            dbSet.InSequence(sequence).Setup(e => e.Add(Goal));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            repo.Create(Goal);
            repo.Get(Goal.Id);
            repo.Update(Goal);
            repo.Delete(Goal.Id);
        }
        public void GoalRepository()
        {
            Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>();
            Mock<DbSet<Goal>> dbSet = new Mock<DbSet<Goal>>();

            factory.Setup(m => m.CreateDbSet<Goal>()).Returns(dbSet.Object);

            GoalRepository repo = new GoalRepository(factory.Object);

            var Goal = new Goal();

            var sequence = new MockSequence();
            dbSet.InSequence(sequence).Setup(e => e.Add(Goal));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id));
            repo.Create(Goal);
            repo.Get(Goal.Id);
            repo.Update(Goal);
            repo.Delete(Goal.Id);
        }