public void CallA_CallsDependencyA() { var subject = _moq.Create <SomeClass>(); subject.CallA(); _moq.Of <IDepencyA>().Verify(x => x.Call(), Times.Once); }
public void DoWork_CallsRepositoryGetData() { // 1 - First create an instance of Moqqer which will // act as a container for Mocks and Objects. _moq = new Moqqer(); // 2 - Get Moqqer to create an instance of some class you want to test. // It will auto inject mocks in the its constructor. _subject = _moq.Create <SomeClass>(); // 3 - Call the mothod you want to test on SomeClass _subject.CallA(); // Calls private field IDependencyA.Call() // 4 - Verify a mock that was auto injected was called. _moq.Of <IDepencyA>() .Verify(x => x.Call(), Times.Once); // Alternatively use the Verify extension method _moq.Verify <IDepencyA>(x => x.Call()) .Once(); // 5 - Test and Refactor to your hearts content // without worrying about changing the constructor calls! }
public void ConstrcutorInejction() { var subject = _moq.Create <SomeClass>(); var depencyA = _moq.Of <IDepencyA>().Object; var depencyB = _moq.Of <IDepencyB>().Object; var expected = _moq.Of <IMockSetup>().Object; subject.A.Should().BeSameAs(depencyA); subject.B.Should().BeSameAs(depencyB); subject.Mock.Should().BeSameAs(expected); }
public void A_TestSetup() { _moq = new Moqqer(); _root = _moq.Create <Root>(); }