Exemple #1
0
        public void GetById()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);

                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentTypeRepository(db);
                    var item       = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));

                    Assert.DoesNotThrow(() => item = repository.GetById(item.Id));
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    Assert.NotNull(item);
                    Assert.Greater(item.Id, 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Exemple #2
0
        public void GetAttachmentTypeExtentions()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);
                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentTypeRepository(db);
                    var item       = db.AttachmentTypes.First();
                    IEnumerable <Extension> result = null;
                    Assert.DoesNotThrow(() => result = repository.GetAttachmentTypeExtentions(item.Id));

                    Assert.NotNull(result);
                    Assert.Greater(result.Count(), 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Exemple #3
0
        public void GetAttachmentTypes()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);

                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentTypeRepository(db);
                    IEnumerable <AttachmentType> result = null;
                    Assert.DoesNotThrow(() => result = repository.Get(new AttachmentTypeFilter <int>
                    {
                        IsOnlyActive = false,
                        Name         = "Passport",
                        Ids          = new List <int>()
                    }));
                    //Удаляем созданный объект
                    Assert.NotNull(result);
                    //проверяем, что он сохранился(присвоился новый идентификатор в базе)
                    Assert.Greater(result.Count(), 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Exemple #4
0
        public void ActivateById()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);
                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);

                    var repository = new SecureAttachmentTypeRepository(db);
                    var item       = GenerateModel();
                    item.IsActive = false;
                    //сохраняем генерированный объект
                    Assert.DoesNotThrow(() => repository.Save(item));
                    //вызов активации серверного объекта
                    Assert.DoesNotThrow(() => item = repository.Activate(item.Id));
                    //Удаляем созданный объект
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    //Проверка, что активация сработала
                    Assert.IsTrue(item.IsActive);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
Exemple #5
0
        public void DeleteById()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);

                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentTypeRepository(db);
                    var item       = GenerateModel();
                    //сохраняем генерированный объект
                    Assert.DoesNotThrow(() => repository.Save(item));
                    //Удаляем созданный объект
                    Assert.DoesNotThrow(() => repository.Delete(item.Id));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void Get_Attachments()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);

                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentRepository(db);
                    IEnumerable <AttachmentN> result = null;
                    var passPortAT = db.Set <AttachmentType>().Single(it => it.Code == "PASSPORT");
                    var extention  = db.Set <Extension>().Single(it => it.Code == "JPEG");
                    Assert.DoesNotThrow(() => result = repository.Get(new AttachmentFilter <int?>
                    {
                        ExtensionId      = extention.Id,
                        IsOnlyActive     = true,
                        AttachmentTypeId = passPortAT.Id
                    }));
                    //Удаляем созданный объект
                    Assert.NotNull(result);
                    //проверяем, что он сохранился(присвоился новый идентификатор в базе)
                    Assert.Greater(result.Count(), 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void Save()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);
                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                    //сохраняем генерированный объект
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    //var repository = IocHelper.GetObject<ISecureRepo>(db);
                    var repository = new SecureAttachmentRepository(db);

                    var item = GenerateModel();
                    //сохраняем генерированный объект
                    Assert.DoesNotThrow(() => repository.Save(item));
                    //Удаляем созданный объект
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    //проверяем, что он сохранился(присвоился новый идентификатор в базе)
                    Assert.Greater(item.Id, 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void RemoveAttachment()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentRepository(db);
                    var item       = db.Attachments.First();
                    var user       = db.Users.First();
                    var result     = db.Set <AttachmentPermission>().ToList();
                    ICollection <Permission> permissions = db.Set <Permission>().Take(4).ToList();
                    db.Set <AttachmentPermission>().RemoveRange(result);
                    db.SaveChanges();
                    Assert.DoesNotThrow(() => repository.LinkAttachment(user, item));
                    result = db.Set <AttachmentPermission>().Where(it => it.AttachmentId == item.Id && it.UserId == user.Id && it.IsOwner).ToList();
                    Assert.NotNull(result);
                    Assert.Greater(result.Count, 0);
                    Assert.DoesNotThrow(() => repository.RemoveAttachment(user, item));
                    result = db.Set <AttachmentPermission>().Where(it => it.AttachmentId == item.Id && it.UserId == user.Id).ToList();
                    Assert.True(result.Count == 0);
                    Assert.DoesNotThrow(() => repository.LinkAttachment(user, item, permissions));
                    Assert.DoesNotThrow(() => repository.RemoveAttachment(user, item, new List <Permission> {
                        permissions.First()
                    }));
                    result = db.Set <AttachmentPermission>().Where(it => it.AttachmentId == item.Id && it.UserId == user.Id).ToList();
                    Assert.NotNull(result);
                    Assert.True(result.Count == 3);


                    Assert.NotNull(permissions);
                    Assert.Greater(permissions.Count(), 0);
                }
                //var repository = IocHelper.GetObject<ISecureRepo>(db);
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void GetAttachmentPermissions()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new SecureAttachmentContext(options))
                {
                    AttachmentTestHelper.PopulateSecurityAttachmentCtx(db);
                }
                //var repository = IocHelper.GetObject<ISecureRepo>(db);
                using (var db = new SecureAttachmentContext(options))
                {
                    var repository = new SecureAttachmentRepository(db);

                    var item = db.Attachments.First();
                    var user = db.Users.First();
                    IEnumerable <odec.Server.Model.Secure.Attachment.Permission> permissions = null;
                    Assert.DoesNotThrow(
                        () =>
                        permissions =
                            repository.GetAttachmentPermissions(new AttachmentPermissionFilter <int, int?, int?>
                    {
                        UserId       = user.Id,
                        IsOnlyActive = false,

                        AttachmentId = item.Id
                    }));

                    Assert.NotNull(permissions);
                    Assert.Greater(permissions.Count(), 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }