public void ListRelatedCodeType_GetWithoutPostRedirect()
        {
            // Arrange
            var controller = SystemUnderTest();

            var codeModel = new RelatedCodeTypeModel {
                SubType = "ABCD", SubDescription = "subordinate Description", DomDescription = "LongDescription"
            };
            IList <RelatedCodeTypeModel> models = new List <RelatedCodeTypeModel>()
            {
                codeModel
            };

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

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


            // Assert
            Assert.IsNotNull(result, "View Result must not be null.");
            if (result != null)
            {
                var model = result.Model as ListRelatedCodeTypeViewModel;
                Assert.IsNotNull(model, "Model must not be null.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list containing all the <see cref="RelatedCodeTypeModel"/> that meets the given criteria.
        /// </summary>
        /// <param name="startingTableType">Starting Related 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 <RelatedCodeTypeModel> GetRelatedListCodeTypes(string startingTableType, char listType, bool exactLookup, int maxRows = 0)
        {
            IList <RelatedCodeTypeModel> results = Enumerable.Empty <RelatedCodeTypeModel>().ToList();

            var keyModel = new KeyModel(CacheType.Global, "RelatedListCodeTypes").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_ListRelatedCodeType
                // Parameters are: @StartingRelType, @ListType, @ExactLookup, @MaxRows
                if (!string.IsNullOrEmpty(startingTableType))
                {
                    sqlParameters.Add(new SqlParameter {
                        ParameterName = "@StartingRelType", 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 <RelatedCodeTypeModel>(ConnectionName, "up_ListRelatedCodeType", sqlParameters, dataReader =>
                {
                    var item            = new RelatedCodeTypeModel();
                    item.Relationship   = dataReader["relation_type_cd"].ToString();
                    item.SubType        = dataReader["sub_code_type"].ToString();
                    item.SubDescription = dataReader["SubDesc"].ToString();
                    item.DomType        = dataReader["dom_code_type"].ToString();
                    item.DomDescription = dataReader["DomDesc"].ToString();
                    return(item);
                }
                                                                    ).ToList();

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


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

            return(new RelatedCodeTypeViewModel
            {
                Relationship = relatedCodeModel.Relationship,
                SubType = relatedCodeModel.SubType,
                SubDescription = relatedCodeModel.SubDescription,
                DomType = relatedCodeModel.DomType,
                DomDescription = relatedCodeModel.DomDescription
            });
        }