2008-10-23 6 views
53

어디에서 MOQ에 대한 포괄적 인 문서를 찾을 수 있습니까? 나는 그냥 조롱하는 것으로 시작하고 그 주위에 머리를 쓰는 데 어려움을 겪고 있습니다. http://code.google.com/p/moq/wiki/QuickStart에있는 모든 링크를 읽었지만 튜토리얼이나 부드러운 소개를 찾을 수 없습니다.MOQ 설명서는 어디에 있습니까?

나는 또한 Rhino Mock을 잠깐 보았지만 매우 혼란 스럽습니다.


예 - 스티븐 왈츠의 기사를 읽었습니다. 매우 유용합니다. 나는 또한 링크를 통해 갔다. 나는 특히 내가 이벤트가 조롱 클래스에서 제기되었는지 여부를 결정하기 위해 노력하고 http://www.bestechvideos.com/2008/06/08/dimecasts-net-introduction-to-mocking-with-moq [깨진 링크]

에서 비디오를 볼 수없는 것. 컴파일 할 QuickStarts 페이지의 이벤트 예제를 가져올 수 없습니다. Google 그룹에서 Daniel은 CreateEventHandler가 EventHandler<TEventArgs> 유형의 이벤트 만 처리 할 수 ​​있다고 설명했지만 컴파일하더라도 코드를 가져올 수 없습니다.

좀 더 구체적으로 말해서 INotifyChanged을 구현하는 클래스가 있습니다.

public class Entity : INotifyChanged 
{ 
    public event PropertyChangingEventHandler PropertyChanging; 

    public int Id 
     { 
      get {return _id;} 
      set { 
       _id = value; 
       OnPropertyChanged("Id"); 
       } 
     } 

    protected void OnPropertyChanged(string property) 
     { 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
etc .....  
} 

PropertyChanged 이벤트가 발생했는지 여부를 테스트하려면 어떻게해야합니까?

Error 1 'CoreServices.Notifier' does not implement interface member System.ComponentModel.INotifyPropertyChanged.PropertyChanged'. 'CoreServices.Notifier.PropertyChanged' cannot implement 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' because it does not have the matching return type of 'System.ComponentModel.PropertyChangedEventHandler'.

+0

표시된 오류는 시각적 스튜디오/컴파일러 버그입니다. bin 폴더에서 모든 것을 제거하고 다시 작성하십시오. – CodingBarfield

+0

* My answer in Moq * *에 대한 링크가 수정되었습니다. –

+0

링크가 끊어졌습니다 (다시) – PPC

답변

15

당신이 Introduction to Mocking with Moq를 본 적이 :이 오류가 becuase 나는 public event EventHandler<PropertyChangedEventArgs>에 이벤트를 다시 작성할 수없는 이유는 무엇입니까? Moq 사용에 대한 소개 개요이며 일반적으로 조롱하는 사람이나 Moq 프레임 워크 자체를 처음 접하는 사람을 대상으로합니다.

30

MOQ의 최신 문서는 GitHub의 위키 페이지에서 사용할 수 있습니다 :

https://github.com/Moq/moq4/wiki/Quickstart

는 이전에 그들은 구글 코드에 있었다. 위키 및 기타 온라인 리소스뿐만 아니라 에서 링크 된 Moq binary download에 포함 된 Windows .CHM 도움말 파일 형식의 전체 설명서가 있습니다.

+1

최신 (4.0.10827) 릴리스로 바로 연결되는 링크 : http://moq.googlecode.com/files/Moq.4.0.10827.Final.zip – vossad01

+0

매우 기이하고 특이한 플랫폼이지만 기능은 훌륭합니다! –

+1

자세한 내용 * 문서 * – anatol

1

I am trying to determine whether an event was raised from the mocked class.

너니? 또는 Id 속성이 설정되었는지 확인하려고합니까? 기본적으로 mock에는 아무런 동작이 없음을 기억하십시오. 알림 이벤트는 발생하지 않습니다.

내가 할 줄 :

const int ExpectedId = 123; 
mockEntity.VerifySet(x => x.Id = ExpectedId); 

이 엔티티는 인터페이스를 구현하는 것으로 가정; 하나의 예 : Entity 내가 (INotifyChanged 제외) 인터페이스를 구현하지 않으며 조롱 것 어느 쪽도 더 흥미로운 행동과 POCO 경우 말했다

public interface IKeyedEntity 
{ 
    int Id { get; set; } 
} 

. 실제 Entity 인스턴스로 테스트하십시오 (데이터베이스를 사용하지 마십시오). 서비스 및 복잡한 종속성에 대한 준비를 조장하십시오.더 MOQ 기능에 대한

Old style imperative mocks vs moq functional specificationsMock.Of - how to specify behavior? (thread) 참조하십시오. 또한 Moq v4 functional specifications이라는 자신의 예를 게시했습니다.

관련 문제