protected virtual void Dispose(bool disposing) { if (disposing) { if (null != mockFactory) { mockFactory.Dispose(); mockFactory = null; } } }
/// <summary> /// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters. /// </summary> /// <param name="factory">The MockFactory that threw this exception</param> /// <param name="invocation">The unexpected invocation</param> /// <param name="expectations">The expectations collection to describe</param> /// <param name="message">A message to help the user understand what was unexpected</param> internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message) { if (factory == null) { throw new ArgumentNullException("factory"); } if (invocation == null) { throw new ArgumentNullException("invocation"); } if (expectations == null) { throw new ArgumentNullException("expectations"); } Factory = factory; var writer = new DescriptionWriter(); writer.WriteLine(); if (invocation.IsPropertySetAccessor) { writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX); } else if (invocation.IsPropertyGetAccessor) { writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX); } else { writer.WriteLine(MESSAGE_PREFIX); } writer.Write(" "); ((ISelfDescribing)invocation).DescribeTo(writer); writer.Write(message); //expectations.DescribeActiveExpectationsTo(writer); //expectations.DescribeUnmetExpectationsTo(writer); expectations.DescribeTo(writer); _message = writer.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="Popper"/> class. /// </summary> /// <param name="mockFactory">The mockFactory.</param> /// <param name="previous">The previous.</param> public Popper(MockFactory mockFactory, ExpectationListBase previous) { this.previous = previous; this.mockFactory = mockFactory; }
public void UnitTest_NMock3_Concrete() { _factory = new NMock.MockFactory(); var mockBankAccount = _factory.CreateMock<BankAccount>(); var mockView = _factory.CreateMock<IView>(); //nie da sie bo prywatna //mockBankAccount.Expects.One.MethodWith(_ => _.Credit(10)) // .WillReturn(100); mockBankAccount.Expects.One.MethodWith(_ => _.Credit(10)) .WillReturn(100); var presenter = new CustomerPresenter(mockView.MockObject, mockBankAccount.MockObject); var result = presenter.CreditCustomerAccount(10); Assert.AreEqual(100, result); Assert.IsTrue(typeof(IBankAccount).IsInstanceOfType(mockBankAccount.MockObject)); }