Beispiel #1
0
        private NucleoDTO Create(NucleoViewModel viewModel)
        {
            try
            {
                log.Debug(NucleoViewModel.FormatNucleoViewModel(viewModel));

                NucleoDTO nucleo = new NucleoDTO();

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

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

                // add
                log.Debug("_nucleoService.AddNucleo - " + NucleoDTO.FormatNucleoDTO(nucleo));

                int id = _nucleoService.AddNucleo(nucleo);

                nucleo.NucleoId = id;

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

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

                throw;
            }
        }
Beispiel #2
0
        public static NucleoDTO SampleNucleoDTO(int id = 1)
        {
            NucleoDTO nucleo = new NucleoDTO();

            // int
            nucleo.NucleoId = id;
            // string
            nucleo.Name = "NameTestValue";
            // string
            nucleo.PersonResponsible = "PersonResponsibleTestValue";
            // int?
            nucleo.Photo = 1;
            // int?
            nucleo.AddressId = 1;
            // System.DateTime?
            nucleo.OpeningDate = new System.DateTime();
            // string
            nucleo.PrimaryPhoneNumber = "PrimaryPhoneNumberTestValue";
            // string
            nucleo.PrimaryEmail = "PrimaryEmailTestValue";
            // bool
            nucleo.Active = false;
            // bool
            nucleo.IsDeleted = false;
            // int?
            nucleo.CreateBy = 1;
            // System.DateTime?
            nucleo.CreateOn = new System.DateTime();
            // int?
            nucleo.UpdateBy = 1;
            // System.DateTime?
            nucleo.UpdateOn = new System.DateTime();

            return(nucleo);
        }
Beispiel #3
0
        public void GetNucleosPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

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

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

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

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

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            var       resultList = nucleoService.GetNucleos(searchTerm, pageIndex, pageSize);
            NucleoDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
            Assert.AreEqual(10, resultList.Count);
        }
Beispiel #4
0
        public NucleoDTO GetNucleo(int nucleoId)
        {
            try
            {
                //Requires.NotNegative("nucleoId", nucleoId);

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

                // get
                R_Nucleo t = Repository.GetNucleo(nucleoId);

                NucleoDTO dto = new NucleoDTO(t);

                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

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

                throw;
            }
        }
Beispiel #5
0
        public void GetNucleos_Success_Test()
        {
            // Arrange
            R_Nucleo nucleo = SampleNucleo(1);

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

            list.Add(nucleo);

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

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

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            var       resultList = nucleoService.GetNucleos();
            NucleoDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
        }
Beispiel #6
0
        public int AddNucleo(NucleoDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

                // add
                id           = Repository.AddNucleo(t);
                dto.NucleoId = id;

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

                throw;
            }

            return(id);
        }
Beispiel #7
0
 public NucleoViewModel(NucleoDTO t)
 {
     NucleoId           = t.NucleoId;
     Name               = t.Name;
     PersonResponsible  = t.PersonResponsible;
     Photo              = t.Photo;
     AddressId          = t.AddressId;
     OpeningDate        = t.OpeningDate;
     PrimaryPhoneNumber = t.PrimaryPhoneNumber;
     PrimaryEmail       = t.PrimaryEmail;
     Active             = t.Active;
     IsDeleted          = t.IsDeleted;
     CreateBy           = t.CreateBy;
     CreateOn           = t.CreateOn;
     UpdateBy           = t.UpdateBy;
     UpdateOn           = t.UpdateOn;
 }
Beispiel #8
0
        public void UpdateNucleo_Success_Test()
        {
            // Arrange
            NucleoDTO dto = SampleNucleoDTO(1);

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

            mock.Setup(s => s.UpdateNucleo(Moq.It.IsAny <R_Nucleo>())).Verifiable();

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            nucleoService.UpdateNucleo(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
Beispiel #9
0
        public NucleoDTO UpdateDTO(NucleoDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.NucleoId           = this.NucleoId;
                dto.Name               = this.Name;
                dto.PersonResponsible  = this.PersonResponsible;
                dto.Photo              = this.Photo;
                dto.AddressId          = this.AddressId;
                dto.OpeningDate        = this.OpeningDate;
                dto.PrimaryPhoneNumber = this.PrimaryPhoneNumber;
                dto.PrimaryEmail       = this.PrimaryEmail;
                dto.Active             = this.Active;
                dto.IsDeleted          = this.IsDeleted;

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

            return(dto);
        }
Beispiel #10
0
        private NucleoDTO Update(NucleoViewModel viewModel)
        {
            try
            {
                log.Debug(NucleoViewModel.FormatNucleoViewModel(viewModel));

                // get
                log.Debug("_nucleoService.GetNucleo - nucleoId: " + viewModel.NucleoId + " ");

                var existingNucleo = _nucleoService.GetNucleo(viewModel.NucleoId);

                log.Debug("_nucleoService.GetNucleo - " + NucleoDTO.FormatNucleoDTO(existingNucleo));

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

                    // update
                    log.Debug("_nucleoService.UpdateNucleo - " + NucleoDTO.FormatNucleoDTO(existingNucleo));

                    _nucleoService.UpdateNucleo(existingNucleo);

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

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

                throw;
            }
        }
Beispiel #11
0
        public void AddNucleo_Success_Test()
        {
            // Arrange
            NucleoDTO dto = SampleNucleoDTO(1);

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

            mock.Setup(s => s.AddNucleo(Moq.It.IsAny <R_Nucleo>())).Returns(1);

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            int id = nucleoService.AddNucleo(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.NucleoId);
        }
Beispiel #12
0
        public void DeleteNucleo(NucleoDTO dto)
        {
            try
            {
                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Beispiel #13
0
        public void GetNucleo_Success_Test()
        {
            // Arrange
            int      id     = 1;
            R_Nucleo nucleo = SampleNucleo(id);

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

            mock.Setup(s => s.GetNucleo(Moq.It.IsAny <int>())).Returns(nucleo);

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            NucleoDTO result = nucleoService.GetNucleo(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
        }
Beispiel #14
0
        public void UpdateNucleo(NucleoDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "NucleoId");

                log.Debug(NucleoDTO.FormatNucleoDTO(dto));

                R_Nucleo t = NucleoDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateNucleo(t);

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

                throw;
            }
        }
Beispiel #15
0
        public void GetNucleoListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name = null;
            string personResponsible = null;
            int?   photo             = null;
            int?   addressId         = null;

            System.DateTime?openingDateFrom    = null;
            System.DateTime?openingDateTo      = null;
            string          primaryPhoneNumber = null;
            string          primaryEmail       = null;
            bool?           active             = null;

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

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

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

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

            mock.Setup(s => s.GetNucleoListAdvancedSearch(
                           Moq.It.IsAny <string>()             // name
                           , Moq.It.IsAny <string>()           // personResponsible
                           , Moq.It.IsAny <int?>()             // photo
                           , Moq.It.IsAny <int?>()             // addressId
                           , Moq.It.IsAny <System.DateTime?>() // openingDateFrom
                           , Moq.It.IsAny <System.DateTime?>() // openingDateTo
                           , Moq.It.IsAny <string>()           // primaryPhoneNumber
                           , Moq.It.IsAny <string>()           // primaryEmail
                           , Moq.It.IsAny <bool?>()            // active
                           )).Returns(list);

            // service
            NucleoService nucleoService = new NucleoService();

            NucleoService.Repository = mock.Object;

            // Act
            var resultList = nucleoService.GetNucleoListAdvancedSearch(
                name
                , personResponsible
                , photo
                , addressId
                , openingDateFrom
                , openingDateTo
                , primaryPhoneNumber
                , primaryEmail
                , active
                );

            NucleoDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.NucleoId);
        }