예제 #1
0
        public void Delete(AutoPunishment autoPunishment)
        {
            var entity = new AutoPunishmentEntity();

            autoPunishment.CopyTo(entity);
            _entities.Remove(entity);
        }
예제 #2
0
        public void Add(AutoPunishment autoPunishment)
        {
            var entity = new AutoPunishmentEntity();

            autoPunishment.CopyTo(entity);
            _entities.Add(entity);
        }
        public void PunishedUserWithNoPriors_Increment_CountIs1()
        {
            var container            = new TestContainerManager().InitializeAndIsolateRepository();
            var id                   = TestHelper.RandomInt();
            var term                 = TestHelper.RandomString();
            var type                 = TestHelper.RandomAutoPunishmentType();
            var duration             = TestHelper.RandomInt();
            var nick                 = TestHelper.RandomString();
            var autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };

            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            repository.Command(r => r.AutoPunishments.Add(new AutoPunishment(autoPunishmentEntity)));

            repository.Command(db => db.PunishedUsers.Increment(nick, term));

            var user = repository.Query(db => db.PunishedUsers.GetUser(nick));

            Assert.AreEqual(1, user.Count);
        }
        public void ReadWriteUpdateAutoPunishment()
        {
            var container = new TestContainerManager().InitializeAndIsolateRepository();

            var id                   = TestHelper.RandomInt();
            var term                 = TestHelper.RandomString();
            var type                 = TestHelper.RandomAutoPunishmentType();
            var duration             = TestHelper.RandomInt();
            var nick                 = TestHelper.RandomString();
            var count                = TestHelper.RandomInt();
            var autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };
            var punishedUsersEntity = new List <PunishedUserEntity> {
                new PunishedUserEntity {
                    Nick = nick, Count = count, AutoPunishmentEntity = autoPunishmentEntity
                }
            };
            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            repository.Command(r => r.AutoPunishments.Add(new AutoPunishment(autoPunishmentEntity)));

            autoPunishmentEntity.Id       = TestHelper.RandomInt();
            autoPunishmentEntity.Term     = TestHelper.RandomString();
            autoPunishmentEntity.Type     = TestHelper.RandomAutoPunishmentType();
            autoPunishmentEntity.Duration = TestHelper.RandomInt();
            nick  = TestHelper.RandomString();
            count = TestHelper.RandomInt();
            autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };
            punishedUsersEntity = new List <PunishedUserEntity> {
                new PunishedUserEntity {
                    Nick = nick, Count = count, AutoPunishmentEntity = autoPunishmentEntity
                }
            };
            autoPunishmentEntity.PunishedUsers = punishedUsersEntity;

            repository.Command(r => r.AutoPunishments.Update(new AutoPunishment(autoPunishmentEntity)));

            var testRead = new List <AutoPunishment>();

            repository.Command(r => {
                testRead.AddRange(r.AutoPunishments.GetAllWithUser);
            });
            var dbAutoPunishment = testRead.Single();

            Assert.AreEqual(dbAutoPunishment.Id, id);
            Assert.AreEqual(dbAutoPunishment.Term, term);
            Assert.AreEqual(dbAutoPunishment.Type, type);
            Assert.AreEqual(dbAutoPunishment.Duration.TotalSeconds, duration);
            Assert.AreEqual(dbAutoPunishment.PunishedUsers.Single().Count, count);
            Assert.AreEqual(dbAutoPunishment.PunishedUsers.Single().Nick, nick);
        }
예제 #5
0
 public AutoPunishment(AutoPunishmentEntity entity)
 {
     Id            = entity.Id;
     Term          = entity.Term;
     Type          = entity.Type;
     Duration      = TimeSpan.FromSeconds(entity.Duration);
     PunishedUsers = entity.PunishedUsers.Select(x => new PunishedUser(x, this)).ToList();
 }
예제 #6
0
 public void CopyTo(AutoPunishmentEntity entity)
 {
     entity.Id       = Id;
     entity.Term     = Term;
     entity.Type     = Type;
     entity.Duration = Convert.ToInt32(Duration.TotalSeconds);
     entity.PunishedUsers.Merge(
         source: PunishedUsers.Select(x => x.ToEntity()),
         predicate: (a, b) => a.Id == b.Id,
         create: user => user,
         delete: person => entity.PunishedUsers.Remove(person),
         add: person => entity.PunishedUsers.Add(person),
         update: (d, s) => {
         d.Nick  = s.Nick;
         d.Count = s.Count;
     }
         );
 }