public void Can_delete_group()
        {
            #region Arrange
            var group = new GroupModel {
                GroupName = "delete test", GroupType = TestGroupType
            };
            int id = -1;
            DataAccess.InTransaction(session =>
            {
                id = (int)session.Save(group);
            });
            #endregion

            #region Act
            var groupDto = GroupModelDto.Map(group);
            groupDto.ID = id;
            bool deleteOk = new GroupService().DeleteGroup(groupDto);

            IList <GroupModel> groups = null;

            DataAccess.InTransaction(session =>
            {
                groups = session.CreateCriteria(typeof(GroupModel)).List <GroupModel>();
            });

            #endregion

            #region Assert
            Assert.That(deleteOk, Is.True);
            Assert.That(groups.Count, Is.EqualTo(1));
            #endregion
        }
        public void Can_update_group()
        {
            #region Arrange
            GroupModel group = null;
            DataAccess.InTransaction(session =>
            {
                group = session.Get <GroupModel>(1);
            });
            group.GroupName = "update test";
            #endregion

            #region Act

            bool updateOk = new GroupService().UpdateGroup(GroupModelDto.Map(group));

            #endregion
            GroupModel testGroup = null;
            DataAccess.InTransaction(session =>
            {
                testGroup = session.Get <GroupModel>(1);
            });

            #region Assert
            Assert.That(updateOk, Is.True);
            Assert.That(testGroup.GroupName, Is.EqualTo("update test"));
            #endregion
        }
 public List <GroupModelDto> GetAllGroups()
 {
     try
     {
         var groups = new Repository <GroupModel>().GetAll().ToList();
         return(GroupModelDto.Map(groups));
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.GetAllGroups - {0}", ex.Message);
         return(new List <GroupModelDto>());
     }
 }
 public bool UpdateGroup(GroupModelDto groupModelDto)
 {
     try
     {
         DataAccess.InTransaction(session =>
                                  session.Update(GroupModelDto.UnMap(groupModelDto)));
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.UpdateGroup - {0}", ex.Message);
         return(false);
     }
 }
        public void SetUp()
        {
            Mock = new MockRepository();
            GroupService = Mock.DynamicMock<IGroupService>();
            ProfileService = Mock.DynamicMock<IProfileService>();
            GroupController = new GroupController(GroupService, JournalService);

            SampleGroup = new GroupModelDto { ID = 1, GroupName = "test" };
            SampleProfile = new ProfileModelDto { ID = 1, LoginName = "test" };
            SampleGroupList = new List<GroupModelDto>
                                  {
                                      new GroupModelDto(),
                                      new GroupModelDto()
                                  };
        }
 public GroupModelDto GetGroup(int id)
 {
     try
     {
         GroupModel group;
         using (var session = DataAccess.OpenSession())
         {
             group = session.Get <GroupModel>(id);
         }
         return(GroupModelDto.Map(group));
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.GetGroup - {0}", ex.Message);
         return(null);
     }
 }
 public int AddGroup(GroupModelDto groupModelDto)
 {
     try
     {
         var groupModel = GroupModelDto.UnMap(groupModelDto);
         int id = -1;
         DataAccess.InTransaction(session =>
         {
             id = (int)session.Save(groupModel);
         });
         return id;
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.AddGroup - {0}", ex.Message);
         return -1;
     }
 }
 public int AddGroup(GroupModelDto groupModelDto)
 {
     try
     {
         var groupModel = GroupModelDto.UnMap(groupModelDto);
         int id         = -1;
         DataAccess.InTransaction(session =>
         {
             id = (int)session.Save(groupModel);
         });
         return(id);
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.AddGroup - {0}", ex.Message);
         return(-1);
     }
 }
Esempio n. 9
0
        public void SetUp()
        {
            Mock            = new MockRepository();
            GroupService    = Mock.DynamicMock <IGroupService>();
            ProfileService  = Mock.DynamicMock <IProfileService>();
            GroupController = new GroupController(GroupService, JournalService);

            SampleGroup = new GroupModelDto {
                ID = 1, GroupName = "test"
            };
            SampleProfile = new ProfileModelDto {
                ID = 1, LoginName = "test"
            };
            SampleGroupList = new List <GroupModelDto>
            {
                new GroupModelDto(),
                new GroupModelDto()
            };
        }
        public void Can_add_group()
        {
            #region Arrange
            var group = new GroupModel {
                GroupName = "new group", GroupType = TestGroupType
            };
            #endregion

            #region Act

            int        id         = new GroupService().AddGroup(GroupModelDto.Map(group));
            GroupModel groupModel = null;
            DataAccess.InTransaction(session =>
            {
                groupModel = session.Get <GroupModel>(id);
            });
            #endregion

            #region Assert
            Assert.That(groupModel, Is.Not.Null);
            Assert.That(groupModel.GroupName, Is.EqualTo("new group"));
            #endregion
        }
 public bool DeleteGroup(GroupModelDto groupDto)
 {
     try
     {
         DataAccess.InTransaction(session =>
             session.Delete(GroupModelDto.UnMap(groupDto)));
         return true;
     }
     catch (Exception ex)
     {
         Logger.Error("Error : CourseService.DeleteGroup - {0}", ex.Message);
         return false;
     }
 }