Example #1
0
        public void DeleteOneAccessGroupShouldCallRepository()
        {
            var acc     = new AccessGroupDTO();
            var accView = new AccessGroup();

            _accessGroupRepositoryMock.Setup(x => x.DeleteOne(acc)).Returns(StorageResult.Success);
            var result = _subject.DeleteOneAccessGroup(accView);

            Assert.That(result, Is.EqualTo(StorageResult.Success));
        }
Example #2
0
 private static bool IsInCollection(AccessGroupDTO u, IEnumerable <AccessGroupDTO> fromDb)
 {
     foreach (var d in fromDb)
     {
         if (d.Id == u.Id && d.Name == u.Name && d.Type == u.Type && d.Description == u.Description && d.RolesThatHaveAccess == u.RolesThatHaveAccess)
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
 public AccessGroup ToViewModel(AccessGroupDTO dto)
 {
     return(new AccessGroup
     {
         Id = dto.Id,
         Name = dto.Name,
         Type = dto.Type,
         Description = dto.Description,
         RolesThatHaveAccess = MapRolesInDto(dto.RolesThatHaveAccess)
     });
 }
Example #4
0
 private void SetUp()
 {
     _subject = new AccessGroupRepository();
     _ag1     = new AccessGroupDTO {
         Name = "Test1", Type = "Testgruppe", Description = "Første testgruppe"
     };
     _ag2 = new AccessGroupDTO {
         Name = "Test1", Type = "Testgruppe", Description = "Andre testgruppe"
     };
     _ag3 = new AccessGroupDTO {
         Name = "Test3", Type = "Testgruppe", Description = "Tredje testgruppe"
     };
 }
Example #5
0
        public void GetOneAccessGroupShouldCallRepository()
        {
            var id  = new Guid();
            var acc = new AccessGroupDTO
            {
                Id   = id,
                Name = "Test"
            };

            _accessGroupRepositoryMock.Setup(x => x.GetOne(id)).Returns(acc);
            _accessGroupMapper.Setup(x => x.ToViewModel(acc)).Returns(new AccessGroup {
                Id = id, Name = "Test"
            });
            var result = _subject.GetOneAccessGroup(id);

            Assert.That(result.Name, Is.EqualTo("Test"));
        }
Example #6
0
 public StorageResult DeleteOne(AccessGroupDTO acc)
 {
     try
     {
         using (ISession session = NHibernateHelper.OpenSession())
             using (ITransaction transaction = session.BeginTransaction())
             {
                 session.Delete(acc);
                 transaction.Commit();
             }
         return(StorageResult.Success);
     }
     catch (Exception)
     {
         return(StorageResult.Failed);
     }
 }
Example #7
0
 public void UpdateOne(AccessGroupDTO acc)
 {
     try
     {
         using (ISession session = NHibernateHelper.OpenSession())
             using (ITransaction transaction = session.BeginTransaction())
             {
                 session.Update(acc);
                 transaction.Commit();
             }
         //return StorageResult.Success;
     }
     catch (Exception)
     {
         //return StorageResult.Failed;
     }
 }
Example #8
0
        public void CanMapToViewModelWithOneRole()
        {
            var dto = new AccessGroupDTO
            {
                Id                  = new Guid(),
                Name                = "AccessTets",
                Type                = "TestGroup",
                Description         = "Bare en test",
                RolesThatHaveAccess = "0"
            };
            var result = _subject.ToViewModel(dto);

            Assert.That(result.Id, Is.EqualTo(dto.Id));
            Assert.That(result.Name, Is.EqualTo(dto.Name));
            Assert.That(result.Type, Is.EqualTo(dto.Type));
            Assert.That(result.Description, Is.EqualTo(dto.Description));
            Assert.That(result.RolesThatHaveAccess.First(), Is.EqualTo("Administrator"));
        }
Example #9
0
 public StorageResult SaveOne(AccessGroupDTO acc)
 {
     try
     {
         if (NameAllreadyInUse(acc.Name))
         {
             return(StorageResult.AllreadyExsists);
         }
         using (ISession session = NHibernateHelper.OpenSession())
             using (ITransaction transaction = session.BeginTransaction())
             {
                 session.Save(acc);
                 transaction.Commit();
             }
         return(StorageResult.Success);
     }
     catch (Exception)
     {
         return(StorageResult.Failed);
     }
 }