Beispiel #1
0
        public static ContributionTypeDTO SampleContributionTypeDTO(int id = 1)
        {
            ContributionTypeDTO contributionType = new ContributionTypeDTO();

            // int
            contributionType.ContributionTypeId = id;
            // string
            contributionType.Name = "NameTestValue";
            // string
            contributionType.Description = "DescriptionTestValue";
            // bool
            contributionType.Active = false;
            // bool
            contributionType.IsDeleted = false;
            // int?
            contributionType.CreateBy = 1;
            // System.DateTime?
            contributionType.CreateOn = new System.DateTime();
            // int?
            contributionType.UpdateBy = 1;
            // System.DateTime?
            contributionType.UpdateOn = new System.DateTime();

            return(contributionType);
        }
Beispiel #2
0
        public ContributionTypeDTO GetContributionType(int contributionTypeId)
        {
            try
            {
                //Requires.NotNegative("contributionTypeId", contributionTypeId);

                log.Debug("contributionTypeId: " + contributionTypeId + " ");

                // get
                R_ContributionType t = Repository.GetContributionType(contributionTypeId);

                ContributionTypeDTO dto = new ContributionTypeDTO(t);

                log.Debug(ContributionTypeDTO.FormatContributionTypeDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #3
0
        public int AddContributionType(ContributionTypeDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(ContributionTypeDTO.FormatContributionTypeDTO(dto));

                R_ContributionType t = ContributionTypeDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddContributionType(t);
                dto.ContributionTypeId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
Beispiel #4
0
        public void GetContributionTypesPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

            // list
            IList <R_ContributionType> list = new List <R_ContributionType>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleContributionType(i));
            }

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.GetContributionTypes(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list);

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            var resultList             = contributionTypeService.GetContributionTypes(searchTerm, pageIndex, pageSize);
            ContributionTypeDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionTypeId);
            Assert.AreEqual(10, resultList.Count);
        }
Beispiel #5
0
        public void GetContributionTypes_Success_Test()
        {
            // Arrange
            R_ContributionType contributionType = SampleContributionType(1);

            IList <R_ContributionType> list = new List <R_ContributionType>();

            list.Add(contributionType);

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.GetContributionTypes()).Returns(list);

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            var resultList             = contributionTypeService.GetContributionTypes();
            ContributionTypeDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionTypeId);
        }
Beispiel #6
0
        private ContributionTypeDTO Create(ContributionTypeViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionTypeViewModel.FormatContributionTypeViewModel(viewModel));

                ContributionTypeDTO contributionType = new ContributionTypeDTO();

                // copy values
                viewModel.UpdateDTO(contributionType, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                contributionType.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                contributionType.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_contributionTypeService.AddContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(contributionType));

                int id = _contributionTypeService.AddContributionType(contributionType);

                contributionType.ContributionTypeId = id;

                log.Debug("result: 'success', id: " + id);

                return(contributionType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #7
0
 public ContributionTypeViewModel(ContributionTypeDTO t)
 {
     ContributionTypeId = t.ContributionTypeId;
     Name        = t.Name;
     Description = t.Description;
     Active      = t.Active;
     IsDeleted   = t.IsDeleted;
     CreateBy    = t.CreateBy;
     CreateOn    = t.CreateOn;
     UpdateBy    = t.UpdateBy;
     UpdateOn    = t.UpdateOn;
 }
Beispiel #8
0
        public ContributionTypeDTO UpdateDTO(ContributionTypeDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.ContributionTypeId = this.ContributionTypeId;
                dto.Name        = this.Name;
                dto.Description = this.Description;
                dto.Active      = this.Active;
                dto.IsDeleted   = this.IsDeleted;

                dto.UpdateBy = updateBy;
                dto.UpdateOn = System.DateTime.UtcNow;
            }

            return(dto);
        }
Beispiel #9
0
        public void GetContributionTypeListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name        = null;
            string description = null;
            bool?  active      = null;

            //int pageIndex = 0;
            int pageSize = 10;

            // list
            IList <R_ContributionType> list = new List <R_ContributionType>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleContributionType(i));
            }

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.GetContributionTypeListAdvancedSearch(
                           Moq.It.IsAny <string>()   // name
                           , Moq.It.IsAny <string>() // description
                           , Moq.It.IsAny <bool?>()  // active
                           )).Returns(list);

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            var resultList = contributionTypeService.GetContributionTypeListAdvancedSearch(
                name
                , description
                , active
                );

            ContributionTypeDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionTypeId);
        }
Beispiel #10
0
        public void UpdateContributionType_Success_Test()
        {
            // Arrange
            ContributionTypeDTO dto = SampleContributionTypeDTO(1);

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.UpdateContributionType(Moq.It.IsAny <R_ContributionType>())).Verifiable();

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            contributionTypeService.UpdateContributionType(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
Beispiel #11
0
        private ContributionTypeDTO Update(ContributionTypeViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionTypeViewModel.FormatContributionTypeViewModel(viewModel));

                // get
                log.Debug("_contributionTypeService.GetContributionType - contributionTypeId: " + viewModel.ContributionTypeId + " ");

                var existingContributionType = _contributionTypeService.GetContributionType(viewModel.ContributionTypeId);

                log.Debug("_contributionTypeService.GetContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(existingContributionType));

                if (existingContributionType != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingContributionType, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_contributionTypeService.UpdateContributionType - " + ContributionTypeDTO.FormatContributionTypeDTO(existingContributionType));

                    _contributionTypeService.UpdateContributionType(existingContributionType);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingContributionType: null, ContributionTypeId: " + viewModel.ContributionTypeId);
                }

                return(existingContributionType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #12
0
        public void DeleteContributionType(ContributionTypeDTO dto)
        {
            try
            {
                log.Debug(ContributionTypeDTO.FormatContributionTypeDTO(dto));

                R_ContributionType t = ContributionTypeDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteContributionType(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Beispiel #13
0
        public void AddContributionType_Success_Test()
        {
            // Arrange
            ContributionTypeDTO dto = SampleContributionTypeDTO(1);

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.AddContributionType(Moq.It.IsAny <R_ContributionType>())).Returns(1);

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            int id = contributionTypeService.AddContributionType(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.ContributionTypeId);
        }
Beispiel #14
0
        public void GetContributionType_Success_Test()
        {
            // Arrange
            int id = 1;
            R_ContributionType contributionType = SampleContributionType(id);

            // create mock for repository
            var mock = new Mock <IContributionTypeRepository>();

            mock.Setup(s => s.GetContributionType(Moq.It.IsAny <int>())).Returns(contributionType);

            // service
            ContributionTypeService contributionTypeService = new ContributionTypeService();

            ContributionTypeService.Repository = mock.Object;

            // Act
            ContributionTypeDTO result = contributionTypeService.GetContributionType(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionTypeId);
        }
Beispiel #15
0
        public void UpdateContributionType(ContributionTypeDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "ContributionTypeId");

                log.Debug(ContributionTypeDTO.FormatContributionTypeDTO(dto));

                R_ContributionType t = ContributionTypeDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateContributionType(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }