小编use*_*890的帖子

单元测试内部属性的反思

我有一个公共类(TargetContainerDto)有2个内部属性.枚举和包含该枚举值的类型.

我正在尝试对这种类型进行单元测试,但我遇到了问题.

internal enum TargetContainerType
{
    Endpoint,
    Group,
    User,
    UserGroup
}


internal TargetContainerType Type { get; set; }
Run Code Online (Sandbox Code Playgroud)

这是我的测试类中的反射代码

public void setType(TargetContainerDto t, int val)
{
    BindingFlags bf = BindingFlags.NonPublic | BindingFlags.Instance;
    PropertyInfo pi = t.GetType().GetProperty("Type", bf);
    pi.SetValue(t, val, null);
}

public TargetContainerDto setTypeTo(TargetContainerDto t, int val)
{
    setType(t, val);
    return t;
}
Run Code Online (Sandbox Code Playgroud)

TargetContainerDto比Type更多的属性,但它们是公共的,所以测试它们很好.这iconURL是一个TargetContainerDto根据类型定义的字符串.这是我的Testmethod:

public void DefaultSubGroupIcon()
{
    var o1 = new TargetContainerDto
    {
        Id = 1234,
        DistinguishedName = "1.1.1.1",
        SubGroup = "test", …
Run Code Online (Sandbox Code Playgroud)

c# reflection unit-testing

5
推荐指数
3
解决办法
4856
查看次数

null 未声明的标识符错误

我不知道发生了什么,因为这几天前运行得很好,但现在我收到一个关于detectcircle()方法中未定义的空标识符的错误。if(p==null){return;}我不知道怎么回事。

 #include <stdio.h>
    #include "cv.h"
    #include "highgui.h"
    #include <iostream>
    #include <math.h>
    #include <string.h>
    #include <conio.h>

using namespace std;

IplImage* img = 0;
CvMemStorage * cstorage;
CvMemStorage * hstorage;

void detectCircle( IplImage *frame );


int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    hstorage = cvCreateMemStorage( 0 );
    cstorage = cvCreateMemStorage( 0 );

    //CvVideoWriter *writer = 0;
    //int colour = 1;
    //int fps = 25;
    //int …
Run Code Online (Sandbox Code Playgroud)

null compiler-errors computer-vision

1
推荐指数
1
解决办法
1万
查看次数