public void ThrowNullReferenceExceptionWhithCorrectMessage_WhenPassedArgumentIsNull()
        {
            // Arrange
            var mockedDbContext = new Mock <ICarAdvertsSystemDbContext>();
            var mockedSet       = new Mock <DbSet <IAdvert> >();

            mockedDbContext.Setup(set => set.Set <IAdvert>()).Returns(mockedSet.Object);
            var     repository = new EfGenericRepository <IAdvert>(mockedDbContext.Object);
            IAdvert entity     = null;

            // Act and Assert
            Assert.That(() => repository.Delete(entity),
                        Throws.ArgumentNullException.With.Message.Contains
                            (nameof(entity)));
        }
        public void CallMethod_GetByIdOnce()
        {
            // Arrange
            var mockedDbContext = new Mock <ICarAdvertsSystemDbContext>();
            var mockedSet       = new Mock <DbSet <IAdvert> >();

            mockedDbContext.Setup(set => set.Set <IAdvert>()).Returns(mockedSet.Object);
            var repository = new EfGenericRepository <IAdvert>(mockedDbContext.Object);
            int id         = 1;

            // Act
            repository.Delete(id);

            // Assert
            //Assert.That(() => repository.GetById(1), Times.Once());
        }
コード例 #3
0
        public ActionResult NormalizeParticipantsWithDuplicatedParticipantScores()
        {
            var result = new StringBuilder("<p>Done! Deleted Participant scores:</p><ol>");

            var problemIds = this.Data.Problems.AllWithDeleted().Select(pr => pr.Id).ToList();

            foreach (var problemId in problemIds)
            {
                var participantScoresRepository = new EfGenericRepository <ParticipantScore>(new OjsDbContext());
                var scoresMarkedForDeletion     = new List <ParticipantScore>();

                participantScoresRepository
                .All()
                .Where(ps => ps.ProblemId == problemId)
                .GroupBy(p => new { p.ProblemId, p.ParticipantId })
                .Where(participantScoreGroup => participantScoreGroup.Count() > 1)
                .ForEach(participantScoreGroup =>
                {
                    participantScoreGroup
                    .OrderByDescending(ps => ps.Points)
                    .ThenByDescending(ps => ps.Id)
                    .Skip(1)
                    .ForEach(ps => scoresMarkedForDeletion.Add(ps));
                });

                if (scoresMarkedForDeletion.Any())
                {
                    foreach (var participantScoreForDeletion in scoresMarkedForDeletion)
                    {
                        participantScoresRepository.Delete(participantScoreForDeletion);
                        result.Append($@"<li>ParticipantScore with
                            ParticipantId: {participantScoreForDeletion.ParticipantId} and
                            ProblemId: {participantScoreForDeletion.ProblemId}</li>");
                    }

                    participantScoresRepository.SaveChanges();
                }
            }

            result.Append("</ol>");
            return(this.Content(result.ToString()));
        }
コード例 #4
0
 public int Delete(T obj)
 {
     return(efGenericRepository.Delete(obj));
 }