小编Cod*_*iwi的帖子

单元测试新手

我想知道如何使用visual studio 2008(.net 2.0)在现有(非常大)的应用程序中实现单元测试.

我理解为现有/遗留代码开发单元测试是不现实的,但我希望对代码进行测试.

我已经找到了很多关于如何编写代码测试的例子,但没有关于如何在现有项目中从头开始设置它的方法,以及如何将它集成到开发周期中.

.net asp.net unit-testing

11
推荐指数
2
解决办法
5893
查看次数

WP7中的Enum.GetValues

为什么Enum.GetValues()在Windows Phone 7 API中不可用,这是否意味着我应该回避Enums而选择结构或其他机制.

windows-phone-7

10
推荐指数
2
解决办法
3101
查看次数

执行Assert.AreMatch()以深度比较两个对象中的属性

我写这封信对我们的缓存机制的测试,我想肯定是什么进入高速缓存是一样的东西出来,即所有属性相匹配.这是一个虚构的例子,说明我希望它如何工作

    [Test]
    public void add_client_model_member_to_cache_then_retreve()
    {
        //arrange
        MemcachedClient client = new MemcachedClient();
        Member member = GetMember();
        client.Store(StoreMode.Set, "membertest", member);

        // act
        var result = client.Get<Member>("membertest");

        // assert
        Assert.AreMatch(result, member);
    }
Run Code Online (Sandbox Code Playgroud)

在每个属性上执行Assert.AreEqual是不可行的,因为会有许多这些测试,每个属性都有许多属性.

哇,谢谢乔恩.我想你在一分钟之内就回答了这个问题.以下是我为任何相关方提供的解决方案.我实现乔恩建议(我认为),但我与阵列性能有点麻烦,因此我的解决方案只能处理整型数组(所有我目前需要).

如果我尝试检查深度超过一个级别,它也会变得相当滑.我确信这可以实现,但是出于我的目的,这不是必需的.

private bool AreMatch(object initial, object result)
    {
        if (initial.Equals(result)) 
            return true;

        foreach (var property in initial.GetType().GetProperties())
        {
            var initialPropValue = property.GetValue(initial,null);
            var resultPropValue = result.GetType().GetProperty(property.Name).GetValue(result,null);

            if (property.PropertyType.IsArray)
            {
                if ((initialPropValue != null && resultPropValue != null) && !Enumerable.SequenceEqual((int[])initialPropValue, (int[])resultPropValue))
                        return false;                   
            }
            else if (!object.Equals(initialPropValue, resultPropValue))
            { …
Run Code Online (Sandbox Code Playgroud)

c# testing memcached assertions

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

是否可以在.net中读取.eml文件

我想知道是否可以解析点网中的.eml和.msg文件(最好是从内存流中解析),以便我可以在ASP.Net页面上使用它们.

vb.net asp.net file

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

检查整数的最安全的方法

这可能是一个优雅的问题,而不是功能.我正在寻找从字符串和对象检查整数的绝对最安全的方法,

在.net中使用大多数内置函数似乎会生成第一个机会异常,显示在立即窗口中,并且随着时间的推移它们只是构建起来.这些异常的含义是什么,因为它们似乎不会影响系统的运行.

这是我的两次尝试,都觉得笨重,我知道必须有一个比使用VB.IsDBNull和Integer.TryParse更好的方法...或者我只是肛门.

(从对象的整数)

    Dim nInteger As Integer = 0
    If oData Is Nothing OrElse VB.IsDBNull(oData) Then
    Else
        If bThrowErrorIfInvalid Then
        Else
            On Error Resume Next
        End If
        nInteger = CType(oData, Integer)
    End If
    Return nInteger
Run Code Online (Sandbox Code Playgroud)

(从字符串整数)

    Dim nInteger As Integer = 0
    If sText Is Nothing Then
    Else
        If bThrowErrorIfInvalid Then
        Else
            On Error Resume Next
        End If
        Integer.TryParse(sText, nInteger) 
    End If
    Return nInteger
Run Code Online (Sandbox Code Playgroud)

vb.net

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

如何在WP7文本框中启用拼写检查器

如何让拼写检查程序适用于Windows Phone 7中的常规(单行)文本框?

windows-phone-7

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