public static CodeTypeViewModel MapToCodeTypeViewModel(CodeTypeModel source)
        {
            var target = new CodeTypeViewModel();

            Map(source, target);
            return(target);
        }
        public void ListCodeType_GetWithoutPostRedirect()
        {
            // Arrange
            var controller = SystemUnderTest();

            var codeModel = new CodeTypeModel {
                CodeType = "ABCD", ShortDescription = "Short Description", LongDescription = "LongDescription"
            };
            IList <CodeTypeModel> models = new List <CodeTypeModel>()
            {
                codeModel
            };

            mockAdwAdminService.Setup(m => m.GetListCodeTypes(It.IsAny <string>(), It.IsAny <char>(), It.IsAny <bool>(), It.IsAny <int>())).Returns(models);


            // Act
            var result = controller.ListCodeType(startswith: null, listtype: null) as ViewResult;


            // Assert
            Assert.IsNotNull(result, "View Result must not be null.");
            if (result != null)
            {
                var model = result.Model as ListCodeTypeViewModel;
                Assert.IsNotNull(model, "Model must not be null.");
            }
        }
        public void ListCodeType_Post()
        {
            // Arrange
            var controller = SystemUnderTest();

            var viewModel = new ListCodeTypeViewModel()
            {
            };
            var codeModel = new CodeTypeModel {
                CodeType = "ABCD", ShortDescription = "Short Description", LongDescription = "LongDescription"
            };
            IList <CodeTypeModel> models = new List <CodeTypeModel>()
            {
                codeModel
            };

            controller.ModelState.AddModelError("", "SomeError");

            // Act
            var result = controller.ListCodeType(viewModel) as ViewResult;


            // Assert
            Assert.IsNotNull(result, "View Result must not be null.");
        }
        public void ListCodeType_PostRedirectedToGet()
        {
            // Arrange
            var controller = SystemUnderTest();

            var viewModel = new ListCodeTypeViewModel()
            {
                StartFromTableType = "A", ListType = "A", MaxRows = 1, ExactLookup = true
            };
            var codeModel = new CodeTypeModel {
                CodeType = "ABCD", ShortDescription = "Short Description", LongDescription = "LongDescription"
            };
            IList <CodeTypeModel> models = new List <CodeTypeModel>()
            {
                codeModel
            };

            mockAdwAdminService.Setup(m => m.GetListCodeTypes(It.IsAny <string>(), It.IsAny <char>(), It.IsAny <bool>(), It.IsAny <int>())).Returns(models);


            // Act
            var result = controller.ListCodeType(viewModel) as RedirectToRouteResult;


            // Assert
            Assert.IsNotNull(result, "Redirect To Route Result must not be null.");
            if (result != null)
            {
                Assert.AreEqual("ListCodeType", result.RouteValues["action"]);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Returns a list containing all the <see cref="CodeTypeModel"/> that meets the given criteria.
        /// </summary>
        /// <param name="startingTableType">Starting Table Type.</param>
        /// <param name="listType">Whether to use current codes only (default is all). Values: '' (all), 'C' current codes, 'E' ended codes.</param>
        /// <param name="exactLookup">Whether to do an exact lookup (default is true).</param>
        /// <param name="maxRows">Maximum rows to be returned. Default is 0 indicating unlimited.</param>
        /// <returns>A list of all the <see cref="CodeTypeModel"/> that meets the specified criteria.</returns>
        public IList <CodeTypeModel> GetListCodeTypes(string startingTableType, char listType, bool exactLookup, int maxRows = 0)
        {
            if (string.IsNullOrEmpty(startingTableType))
            {
                throw new ArgumentNullException("startingTableType", "startingTableType cannot be empty.");
            }


            IList <CodeTypeModel> results = Enumerable.Empty <CodeTypeModel>().ToList();

            var keyModel = new KeyModel(CacheType.Global, "ListCodeTypes").Add(startingTableType).Add(listType).Add(exactLookup);

            if (!CacheService.TryGet(keyModel, out results))
            {
                var sqlParameters = new List <SqlParameter>();
                // Retrieve all the Adw Code data for the specified starting table type.

                // PROC Name = up_ListCodeType
                // Parameters are: @StartingCodeType, @ListType, @ExactLookup, @MaxRows
                sqlParameters.Add(new SqlParameter {
                    ParameterName = "@StartingCodeType", SqlDbType = System.Data.SqlDbType.VarChar, Value = startingTableType
                });
                if (listType != null && listType != '\0' && listType != 'A')
                {
                    sqlParameters.Add(new SqlParameter {
                        ParameterName = "@ListType", SqlDbType = System.Data.SqlDbType.Char, Value = listType
                    });
                }
                sqlParameters.Add(new SqlParameter {
                    ParameterName = "@ExactLookup", SqlDbType = System.Data.SqlDbType.Char, Value = exactLookup ? 'y' : 'n'
                });
                sqlParameters.Add(new SqlParameter {
                    ParameterName = "@MaxRows", SqlDbType = System.Data.SqlDbType.Int, Value = maxRows
                });

                results = SqlService.Execute <CodeTypeModel>(ConnectionName, "up_ListCodeType", sqlParameters, dataReader =>
                {
                    var item              = new CodeTypeModel();
                    item.CodeType         = dataReader["code_type"].ToString();
                    item.LongDescription  = dataReader["long_desc"].ToString();
                    item.ShortDescription = dataReader["short_desc"].ToString();

                    return(item);
                }).ToList();

                if (results.Any())
                {
                    CacheService.Set(keyModel, results);
                }
            }


            return(results);
        }
        /// <summary>
        /// Extension method for mapping <see cref="CodeTypeModel"/> to <see cref="CodeTypeViewModel"/>.
        /// </summary>
        /// <param name="codeModel"><see cref="CodeTypeModel"/> instance.</param>
        /// <returns>Instance of <see cref="CodeTypeViewModel"/>.</returns>
        public static CodeTypeViewModel ToCodeTypeViewModel(this CodeTypeModel codeModel)
        {
            if (codeModel == null)
            {
                return(null);
            }

            return(new CodeTypeViewModel
            {
                CodeType = codeModel.CodeType,
                LongDescription = codeModel.LongDescription,
                ShortDescription = codeModel.ShortDescription
            });
        }
 public static void Map(CodeTypeModel source, CodeTypeViewModel target)
 {
     target.CodeType         = source.CodeType;
     target.ShortDescription = source.ShortDescription;
     target.LongDescription  = source.LongDescription;
 }