Exemple #1
0
        public void DatalistException_SetsMessage()
        {
            String actual   = new DatalistException("Test").Message;
            String expected = "Test";

            Assert.Equal(expected, actual);
        }
        public void FilterByNotIds_NotSupportedIdType_Throws()
        {
            DatalistException exception = Assert.Throws <DatalistException>(() => new TestDatalist <GuidModel>().FilterByNotIds(null, new String[0]));

            String expected = $"'{typeof(GuidModel).Name}.Id' property type has to be a string or an int.";
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void Add_SameColumnKey_Throws()
        {
            DatalistException exception = Assert.Throws <DatalistException>(() => columns.Add(columns.First()));

            String expected = String.Format("Can not add datalist column with the same key '{0}'.", columns.First().Key);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void FilterByNotIds_NoIdProperty_Throws()
        {
            TestDatalist <NoIdModel> testDatalist = new TestDatalist <NoIdModel>();

            DatalistException exception = Assert.Throws <DatalistException>(() => testDatalist.FilterByNotIds(null, null));

            String expected = $"'{typeof(NoIdModel).Name}' type does not have key or property named 'Id', required for automatic id filtering.";
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void AddId_NoProperty_Throws()
        {
            GenericDatalistProxy <NoIdModel> datalist = new GenericDatalistProxy <NoIdModel>();

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseAddId(row, new NoIdModel()));

            String expected = String.Format("'{0}' type does not have property named 'Id'.", typeof(NoIdModel).Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void AddColumns_EmptyColumns_Throws()
        {
            datalist.Columns.Clear();

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseAddColumns(null, new TestModel()));

            String expected = "Datalist should have at least one column.";
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void Sort_NoProperty_Throws()
        {
            datalist.CurrentFilter.SortColumn = "Test";

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseSort(datalist.BaseGetModels()));

            String expected = "Datalist does not contain sort column named 'Test'.";
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void FilterById_NoIdProperty_Throws()
        {
            GenericDatalistProxy <NoIdModel> datalist = new GenericDatalistProxy <NoIdModel>();

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseFilterById(datalist.BaseGetModels()));

            String expected = String.Format("Type '{0}' does not have property named 'Id'.", typeof(NoIdModel).Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void GetColumnHeader_NoRelation_Throws()
        {
            PropertyInfo property = typeof(NoRelationModel).GetProperty("NoRelation");

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseGetColumnHeader(property));

            String expected = String.Format("{0}.{1} does not have property named 'None'.", property.DeclaringType.Name, property.Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void AddColumns_NoProperty_Throws()
        {
            datalist.Columns.Clear();
            datalist.Columns.Add(new DatalistColumn("Test", ""));

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseAddColumns(row, new TestModel()));

            String expected = String.Format("'{0}' type does not have property named 'Test'.", typeof(TestModel).Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void FilterBySearchTerm_NoProperty_Throws()
        {
            datalist.CurrentFilter.SearchTerm = "Test";
            datalist.Columns.Add(new DatalistColumn("Test", ""));

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseFilterBySearchTerm(datalist.BaseGetModels()));

            String expected = String.Format("Type {0} does not have property named Test.", typeof(TestModel).Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }
        public void FilterById_NotNumericId_Throws()
        {
            GenericDatalistProxy <NonNumericIdModel> datalist = new GenericDatalistProxy <NonNumericIdModel>();

            datalist.CurrentFilter.Id = "9";

            DatalistException exception = Assert.Throws <DatalistException>(() => datalist.BaseFilterById(datalist.BaseGetModels()));

            String expected = String.Format("{0}.Id can not be filtered by using '9' value, because it's not a string nor a number.", typeof(NonNumericIdModel).Name);
            String actual   = exception.Message;

            Assert.Equal(expected, actual);
        }