SORU
19 ŞUBAT 2010, Cuma


Adedi ile alay Uzatma Yöntemleri

Önceden var olan bir Arayüzü var

public interface ISomeInterface
{
    void SomeMethod();
}

ve bu intreface bir kendisine dahil ederse kullanarak genişletilmiş

public static class SomeInterfaceExtensions
{
    public static void AnotherMethod(this ISomeInterface someInterface)
    {
        // Implementation here
    }
}

Test etmek istiyorum, bu arama bu böyle bir sınıf var

public class Caller
{
    private readonly ISomeInterface someInterface;

    public Caller(ISomeInterface someInterface)
    {
        this.someInterface = someInterface;
    }

    public void Main()
    {
        someInterface.AnotherMethod();
    }
}

ve arabirimi ve doğrulamak uzatma yöntemi çağrısı alay etmek istiyorum bir test...

    [Test]
    public void Main_BasicCall_CallsAnotherMethod()
    {
        // Arrange
        var someInterfaceMock = new Mock<ISomeInterface>();
        someInterfaceMock.Setup(x => x.AnotherMethod()).Verifiable();

        var caller = new Caller(someInterfaceMock.Object);

        // Act
        caller.Main();

        // Assert
        someInterfaceMock.Verify();
    }

Bu test ancak, bir özel durum oluşturur...

System.ArgumentException: Invalid setup on a non-member method:
x => x.AnotherMethod()

Benim sorum, güzel bir çıkış yolu kendisine dahil ederse, çağrı alay etmek var mı?

CEVAP
23 AĞUSTOS 2011, Salı


O "şey" alaycı çerçeve ile alay statik yöntem (dolayısıyla uzatma yöntemi). doğrudan Mol (http://research.microsoft.com/en-us/projects/pex/downloads.aspx), farklı bir yaklaşım, ücretsiz bir Microsoft aracını deneyebilirsiniz. Burada aracı açıklaması: "Benler test koçanları için hafif bir çerçeve ve tali yollar .Delegeler dayalı NET." ... "Benler herhangi bir sapma olabilir .NET yöntemi, kapalı tipte olmayan sanal/statik yöntemler de dahil olmak üzere". Herhangi bir test çerçevesi (bu konuda bağımsız) ile Mol kullanabilirsiniz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • emimusic

    emimusic

    10 Mart 2006
  • Just So

    Just So

    3 HAZİRAN 2007
  • TheSalband Rai

    TheSalband R

    11 NİSAN 2011