예제 #1
0
        public static ContributionChannelDTO SampleContributionChannelDTO(int id = 1)
        {
            ContributionChannelDTO contributionChannel = new ContributionChannelDTO();

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

            return(contributionChannel);
        }
예제 #2
0
        public void GetContributionChannelsPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

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

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

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

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

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            var resultList = contributionChannelService.GetContributionChannels(searchTerm, pageIndex, pageSize);
            ContributionChannelDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionChannelId);
            Assert.AreEqual(10, resultList.Count);
        }
예제 #3
0
        private ContributionChannelDTO Create(ContributionChannelViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionChannelViewModel.FormatContributionChannelViewModel(viewModel));

                ContributionChannelDTO contributionChannel = new ContributionChannelDTO();

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

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

                // add
                log.Debug("_contributionChannelService.AddContributionChannel - " + ContributionChannelDTO.FormatContributionChannelDTO(contributionChannel));

                int id = _contributionChannelService.AddContributionChannel(contributionChannel);

                contributionChannel.ContributionChannelId = id;

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

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

                throw;
            }
        }
예제 #4
0
        public void GetContributionChannels_Success_Test()
        {
            // Arrange
            R_ContributionChannel contributionChannel = SampleContributionChannel(1);

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

            list.Add(contributionChannel);

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

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

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            var resultList = contributionChannelService.GetContributionChannels();
            ContributionChannelDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionChannelId);
        }
예제 #5
0
        public ContributionChannelDTO GetContributionChannel(int contributionChannelId)
        {
            try
            {
                //Requires.NotNegative("contributionChannelId", contributionChannelId);

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

                // get
                R_ContributionChannel t = Repository.GetContributionChannel(contributionChannelId);

                ContributionChannelDTO dto = new ContributionChannelDTO(t);

                log.Debug(ContributionChannelDTO.FormatContributionChannelDTO(dto));

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

                throw;
            }
        }
예제 #6
0
        public int AddContributionChannel(ContributionChannelDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(ContributionChannelDTO.FormatContributionChannelDTO(dto));

                R_ContributionChannel t = ContributionChannelDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddContributionChannel(t);
                dto.ContributionChannelId = id;

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

                throw;
            }

            return(id);
        }
예제 #7
0
 public ContributionChannelViewModel(ContributionChannelDTO t)
 {
     ContributionChannelId = t.ContributionChannelId;
     Name        = t.Name;
     Description = t.Description;
     Active      = t.Active;
     IsDeleted   = t.IsDeleted;
     CreateBy    = t.CreateBy;
     CreateOn    = t.CreateOn;
     UpdateBy    = t.UpdateBy;
     UpdateOn    = t.UpdateOn;
 }
예제 #8
0
        public ContributionChannelDTO UpdateDTO(ContributionChannelDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.ContributionChannelId = this.ContributionChannelId;
                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);
        }
예제 #9
0
        public void GetContributionChannelListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name        = null;
            string description = null;
            bool?  active      = null;

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

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

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

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

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

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            var resultList = contributionChannelService.GetContributionChannelListAdvancedSearch(
                name
                , description
                , active
                );

            ContributionChannelDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionChannelId);
        }
예제 #10
0
        public void UpdateContributionChannel_Success_Test()
        {
            // Arrange
            ContributionChannelDTO dto = SampleContributionChannelDTO(1);

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

            mock.Setup(s => s.UpdateContributionChannel(Moq.It.IsAny <R_ContributionChannel>())).Verifiable();

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            contributionChannelService.UpdateContributionChannel(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
예제 #11
0
        private ContributionChannelDTO Update(ContributionChannelViewModel viewModel)
        {
            try
            {
                log.Debug(ContributionChannelViewModel.FormatContributionChannelViewModel(viewModel));

                // get
                log.Debug("_contributionChannelService.GetContributionChannel - contributionChannelId: " + viewModel.ContributionChannelId + " ");

                var existingContributionChannel = _contributionChannelService.GetContributionChannel(viewModel.ContributionChannelId);

                log.Debug("_contributionChannelService.GetContributionChannel - " + ContributionChannelDTO.FormatContributionChannelDTO(existingContributionChannel));

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

                    // update
                    log.Debug("_contributionChannelService.UpdateContributionChannel - " + ContributionChannelDTO.FormatContributionChannelDTO(existingContributionChannel));

                    _contributionChannelService.UpdateContributionChannel(existingContributionChannel);

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

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

                throw;
            }
        }
예제 #12
0
        public void AddContributionChannel_Success_Test()
        {
            // Arrange
            ContributionChannelDTO dto = SampleContributionChannelDTO(1);

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

            mock.Setup(s => s.AddContributionChannel(Moq.It.IsAny <R_ContributionChannel>())).Returns(1);

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            int id = contributionChannelService.AddContributionChannel(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.ContributionChannelId);
        }
예제 #13
0
        public void DeleteContributionChannel(ContributionChannelDTO dto)
        {
            try
            {
                log.Debug(ContributionChannelDTO.FormatContributionChannelDTO(dto));

                R_ContributionChannel t = ContributionChannelDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
예제 #14
0
        public void GetContributionChannel_Success_Test()
        {
            // Arrange
            int id = 1;
            R_ContributionChannel contributionChannel = SampleContributionChannel(id);

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

            mock.Setup(s => s.GetContributionChannel(Moq.It.IsAny <int>())).Returns(contributionChannel);

            // service
            ContributionChannelService contributionChannelService = new ContributionChannelService();

            ContributionChannelService.Repository = mock.Object;

            // Act
            ContributionChannelDTO result = contributionChannelService.GetContributionChannel(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ContributionChannelId);
        }
예제 #15
0
        public void UpdateContributionChannel(ContributionChannelDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "ContributionChannelId");

                log.Debug(ContributionChannelDTO.FormatContributionChannelDTO(dto));

                R_ContributionChannel t = ContributionChannelDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateContributionChannel(t);

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

                throw;
            }
        }