我一直在尝试将参数化@pytest.mark.parametrize测试添加到基于类的单元测试中.
class SomethingTests(unittest.TestCase):
@pytest.mark.parametrize(('one', 'two'), [
(1, 2), (2, 3)])
def test_default_values(self, one, two):
assert one == (two + 1)
Run Code Online (Sandbox Code Playgroud)
但是参数化的东西没有起作用:
TypeError: test_default_values() takes exactly 3 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
我已经改用基于简单类的测试(没有单元测试).但是我想知道是否有人尝试过它并且有效.
在C#中使用SqlCommand我在where子句中创建了一个包含IN(list ...)部分的查询.而不是循环我的字符串列表生成我需要查询的列表(如果您认为在sqlInjection中是危险的).我以为我可以创建一个参数,如:
SELECT blahblahblah WHERE blahblahblah IN @LISTOFWORDS
Run Code Online (Sandbox Code Playgroud)
然后在代码中我尝试添加如下参数:
DataTable dt = new DataTable();
dt.Columns.Add("word", typeof(string));
foreach (String word in listOfWords)
{
dt.Rows.Add(word);
}
comm.Parameters.Add("LISTOFWORDS", System.Data.SqlDbType.Structured).Value = dt;
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
问题:
谢谢你的时间 :)
有人知道为接口设置ProtoContract的正确方法是什么吗?
我得到以下异常“一旦生成序列化程序,就无法更改类型”,仅使用属性。
使用的代码:
[ProtoContract]
public class Lesson5TestClass2 : ILesson5TestInteface1
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public string Phone { get; set; }
}
[ProtoContract]
[ProtoInclude(1000, typeof(Lesson5TestClass2))]
public interface ILesson5TestInteface1
{
[ProtoMember(1)]
string Name { get; set; }
[ProtoMember(2)]
string Phone { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
只有添加以下设置,我才能反序列化:
RuntimeTypeModel.Default.Add(typeof (ILesson5TestInteface1), true)
.AddSubType(50, typeof(Lesson5TestClass2));
Run Code Online (Sandbox Code Playgroud)
我真的很想只使用属性来配置它。
我正在使用 NuGet 的 protobuf-net r470。
顺便说一句:这个例子来自一组“通过测试的教训”,展示了如何为我的同事使用 protobuf-net 进行序列化。
谢谢阅读 :)