2009-01-09 7 views

Odpowiedz

20

Ja zakładając oznacza personelowi this[]

var mockClass = MockRepository.GenerateMock<MockClass>(); 

    mockClass.Expect(m => m["key"]).Return("value"); // return a value 
    mockClass.Expect(m => m["key2"] = "value2"); // set a value 

    ... some test in here using something that depends on mockClass... 


    mockClass.VerifyAllExpectations(); 
+0

Próbuję to mockClass.Expect (m => m [0]) Powrót (poz.); i otrzymuję indeks 0 jest poza zakresem. Jakieś pomysły? – Brian

+0

@ Brian jakiego typu to 'mockClass'? – tvanfosson

+0

mockClass jest dziedziczony z ConfigurationElementCollection, a błąd pojawia się public Item this [int index] { get { return base.BaseGet (index) jako Item; } ustawić { if (base.BaseGet (indeks)! = Null) // katastrofy Tu chociaż jego wyśmiewany/odgałęzienie { base.BaseRemoveAt (index); } this.BaseAdd (indeks, (ConfigurationElement) wartość); } } – Brian

Powiązane problemy