首先,我是新手。我已经创建了class:
using System.Reflection;
public class EmployeeInfo
{
public string EmployeeName { get; set; }
public string PhoneNumber { get; set; }
public string Office { get; set; }
public string Department { get; set; }
public string Position { get; set; }
public string PhoneType { get; set; }
public bool IsPublic { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试开发一种方法,该方法将通过反射使用一些业务逻辑(如果为null,然后为空字符串等)填充所有属性,并返回的列表EmployeeInfo
。我认为它应该看起来像这样:
public List<Models.EmployeeInfo> GetEmployeeInfo(SPListItemCollection splic)
{
var listEmployeeInfo = new List<Models.EmployeeInfo>();
var propertyNames = new List<string>() {"EmployeeName","Position","Office","IsPublic"};
foreach (SPListItem item in …
Run Code Online (Sandbox Code Playgroud) 我有很多这个方法if statements
,其中我SharePoint list
根据员工职位进行过滤。结果是query string
作为参数传递给另一个方法QuerySPList
。
public List<Phone> GetListOfPhones(Employee emp)
{
List<Phone> records = new List<Phone>();
string query = string.Empty;
if (emp.Positions.Count == 1 && emp.Positions[0] == "Regular")
{
query = "";// some querystring
}
if (emp.Positions.Count == 1 && emp.Positions[0] == "OfficeDirector")
{
query = "";// some querystring
}
if (emp.Positions.Count == 1 && emp.Positions[0] == "Admin")
{
query = "";// some querystring
}
if (emp.Positions.Count == 2 && emp.Positions.Contains("Regular") && emp.Positions.Contains("OfficeDirector"))
{ …
Run Code Online (Sandbox Code Playgroud) 我知道这可能很容易,但由于我刚刚开始学习单元测试,我对所有的可能性有点困惑。
我有一个非常简单的方法,它应该从文件中读取整数(条件是文件仅包含整数,每个整数都存储在新行中)。
public static IEnumerable<int> ReadIntegers(string file)
{
using (var stream = File.OpenText(file))
{
string line;
while ((line = stream.ReadLine()) != null)
{
yield return int.Parse(line);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我继续之前,请不要建议我重构方法,我已经找到了它,并且我想学习如何为这个特定的输入参数和输出值编写单元测试。
我在另一个主题上发现有人建议在测试用例中创建一个测试文件,然后尝试将预期结果与实际结果进行比较,如下所示:
[Test]
public void ShouldValidateReadingOfTheFile()
{
string path = @"E:\TestFile.txt";
using (var sw = File.AppendText(path))
{
sw.WriteLine(1);
sw.WriteLine(100);
}
var expected = new List<int>() { 1, 100 };
var actual = TestProject.Merge.ReadIntegersFromFile(path);
Assert.IsTrue(expected.SequenceEqual(actual));
}
Run Code Online (Sandbox Code Playgroud)
我想问你这是一个不好的做法吗?你有不同的方法吗?关于此方法的不同测试还有其他想法吗?谢谢!
我想开发一个方法,它将返回由相同字符组成的最大子字符串的长度,形成作为参数传递的字符串,但不使用任何字符串.NET libraries
.
例如,如果我们aaacccccdefffgg
作为参数传递最大的子字符串,ccccc
并且方法应该返回5.
这是我的工作解决方案:
public static int GetMaxSubstringLenght(char[] myArray)
{
int max = 0;
for (int i = 0; i < myArray.Length-1; i++)
{
if (myArray.Length == 0)
{
return 0;
}
else
{
int j = i + 1;
int currentMax = 1; // string has some value, so we start with 1
while (myArray[i] == myArray[j])
{
currentMax++;
if (max < currentMax)
{
max = currentMax;
}
j++;
}
}
}
return …
Run Code Online (Sandbox Code Playgroud) 我有一个问题jQuery DataTables
。我有以下情况,当表加载时,所有内容都应该按第三列排序,但同时,我应该禁用按列排序(单击表格标题时),并突出显示还应禁用对其进行排序的列。
请如果您有任何想法,请与我分享。谢谢你。
c# ×4
algorithm ×1
datatables ×1
if-statement ×1
javascript ×1
jquery ×1
nunit ×1
reflection ×1
unit-testing ×1