Exemple #1
0
        private SupplierTypeDTO Create(SupplierTypeViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierTypeViewModel.FormatSupplierTypeViewModel(viewModel));

                SupplierTypeDTO supplierType = new SupplierTypeDTO();

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

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

                // add
                log.Debug("_supplierTypeService.AddSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(supplierType));

                int id = _supplierTypeService.AddSupplierType(supplierType);

                supplierType.SupplierTypeId = id;

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

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

                throw;
            }
        }
Exemple #2
0
        public static SupplierTypeDTO SampleSupplierTypeDTO(int id = 1)
        {
            SupplierTypeDTO supplierType = new SupplierTypeDTO();

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

            return(supplierType);
        }
Exemple #3
0
        public SupplierTypeDTO GetSupplierType(int supplierTypeId)
        {
            try
            {
                //Requires.NotNegative("supplierTypeId", supplierTypeId);

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

                // get
                R_SupplierType t = Repository.GetSupplierType(supplierTypeId);

                SupplierTypeDTO dto = new SupplierTypeDTO(t);

                log.Debug(SupplierTypeDTO.FormatSupplierTypeDTO(dto));

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

                throw;
            }
        }
Exemple #4
0
        public int AddSupplierType(SupplierTypeDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(SupplierTypeDTO.FormatSupplierTypeDTO(dto));

                R_SupplierType t = SupplierTypeDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddSupplierType(t);
                dto.SupplierTypeId = id;

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

                throw;
            }

            return(id);
        }
Exemple #5
0
        public void GetSupplierTypesPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

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

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

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

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

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            var             resultList = supplierTypeService.GetSupplierTypes(searchTerm, pageIndex, pageSize);
            SupplierTypeDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierTypeId);
            Assert.AreEqual(10, resultList.Count);
        }
Exemple #6
0
        public void GetSupplierTypes_Success_Test()
        {
            // Arrange
            R_SupplierType supplierType = SampleSupplierType(1);

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

            list.Add(supplierType);

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

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

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            var             resultList = supplierTypeService.GetSupplierTypes();
            SupplierTypeDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierTypeId);
        }
Exemple #7
0
 public SupplierTypeViewModel(SupplierTypeDTO t)
 {
     SupplierTypeId = t.SupplierTypeId;
     Name           = t.Name;
     Description    = t.Description;
     Active         = t.Active;
     IsDeleted      = t.IsDeleted;
     CreateBy       = t.CreateBy;
     CreateOn       = t.CreateOn;
     UpdateBy       = t.UpdateBy;
     UpdateOn       = t.UpdateOn;
 }
Exemple #8
0
        public SupplierTypeDTO UpdateDTO(SupplierTypeDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.SupplierTypeId = this.SupplierTypeId;
                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);
        }
Exemple #9
0
        public void GetSupplierTypeListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name        = null;
            string description = null;
            bool?  active      = null;

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

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

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

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

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

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            var resultList = supplierTypeService.GetSupplierTypeListAdvancedSearch(
                name
                , description
                , active
                );

            SupplierTypeDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierTypeId);
        }
Exemple #10
0
        public void UpdateSupplierType_Success_Test()
        {
            // Arrange
            SupplierTypeDTO dto = SampleSupplierTypeDTO(1);

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

            mock.Setup(s => s.UpdateSupplierType(Moq.It.IsAny <R_SupplierType>())).Verifiable();

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            supplierTypeService.UpdateSupplierType(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
Exemple #11
0
        private SupplierTypeDTO Update(SupplierTypeViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierTypeViewModel.FormatSupplierTypeViewModel(viewModel));

                // get
                log.Debug("_supplierTypeService.GetSupplierType - supplierTypeId: " + viewModel.SupplierTypeId + " ");

                var existingSupplierType = _supplierTypeService.GetSupplierType(viewModel.SupplierTypeId);

                log.Debug("_supplierTypeService.GetSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(existingSupplierType));

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

                    // update
                    log.Debug("_supplierTypeService.UpdateSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(existingSupplierType));

                    _supplierTypeService.UpdateSupplierType(existingSupplierType);

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

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

                throw;
            }
        }
Exemple #12
0
        public void DeleteSupplierType(SupplierTypeDTO dto)
        {
            try
            {
                log.Debug(SupplierTypeDTO.FormatSupplierTypeDTO(dto));

                R_SupplierType t = SupplierTypeDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Exemple #13
0
        public void AddSupplierType_Success_Test()
        {
            // Arrange
            SupplierTypeDTO dto = SampleSupplierTypeDTO(1);

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

            mock.Setup(s => s.AddSupplierType(Moq.It.IsAny <R_SupplierType>())).Returns(1);

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            int id = supplierTypeService.AddSupplierType(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.SupplierTypeId);
        }
Exemple #14
0
        public void GetSupplierType_Success_Test()
        {
            // Arrange
            int            id           = 1;
            R_SupplierType supplierType = SampleSupplierType(id);

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

            mock.Setup(s => s.GetSupplierType(Moq.It.IsAny <int>())).Returns(supplierType);

            // service
            SupplierTypeService supplierTypeService = new SupplierTypeService();

            SupplierTypeService.Repository = mock.Object;

            // Act
            SupplierTypeDTO result = supplierTypeService.GetSupplierType(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierTypeId);
        }
Exemple #15
0
        public void UpdateSupplierType(SupplierTypeDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "SupplierTypeId");

                log.Debug(SupplierTypeDTO.FormatSupplierTypeDTO(dto));

                R_SupplierType t = SupplierTypeDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateSupplierType(t);

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

                throw;
            }
        }