public void ShouldReturnDefaultForLooseBehaviorOnAbstract() { var mock = new Mock <Foo>(MockBehavior.Loose); Assert.Equal(0, mock.Object.AbstractGet()); Assert.Null(mock.Object.GetObject()); }
public void ShouldReturnNullStringOnLooseWithExpect() { var mock = new Mock <IFoo>(MockBehavior.Loose); mock.Setup(x => x.DoReturnString()); Assert.Null(mock.Object.DoReturnString()); }
public void ProvidesNullInt() { var provider = new EmptyDefaultValueProvider(); var value = provider.ProvideDefault(typeof(IFoo).GetProperty("NullableIntValue").GetGetMethod()); Assert.Null(value); }
public void ReturnsNullValueIfNullFunc() { var mock = new Mock <IFoo>(); mock.Setup(foo => foo.Execute("Whatever")).Returns((Func <string>)null); Assert.Null(mock.Object.Execute("Whatever")); mock.VerifyAll(); }
public void ReturnsNullStringOnLooseWithMockDefaultValue() { var mock = new Mock <IFoo>(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; Assert.Null(mock.Object.DoReturnString()); }
public void ProvidesNullReferenceTypes() { var provider = new EmptyDefaultValueProvider(); var value1 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); var value2 = provider.ProvideDefault(typeof(IFoo).GetProperty("Object").GetGetMethod()); Assert.Null(value1); Assert.Null(value2); }
public void AllowsSetupNewHiddenBaseProperty() { var value = new Mock <INewBar>().Object; var target = new Mock <INewFoo>(); target.As <IFoo>().SetupGet(x => x.Bar).Returns(value); Assert.Equal(value, target.As <IFoo>().Object.Bar); Assert.Null(target.Object.Bar); }
public void TestPresenterSelection() { var mockView = new Mock <IOrdersView>(); var presenter = new OrdersPresenter(mockView.Object); // Check that the presenter has no selection by default Assert.Null(presenter.SelectedOrder); // Finally raise the event with a specific arguments data mockView.Raise(mv => mv.OrderSelected += null, new OrderEventArgs { Order = new Order("moq", 500) }); // Now the presenter reacted to the event, and we have a selected order Assert.NotNull(presenter.SelectedOrder); Assert.Equal("moq", presenter.SelectedOrder.ProductName); }
public void Test() { var mock = new Mock <IRepository>(); mock.Setup(x => x.Select <User>(u => u.Id == 100)) .Returns(new User() { Id = 100 }); var user = mock.Object.Select <User>(usr => usr.Id == 100); Assert.Equal(100, user.Id); mock.Verify(x => x.Select <User>(usr => usr.Id == 100), Times.Once()); user = mock.Object.Select <User>(usr => usr.Id == 101); Assert.Null(user); mock.Verify(x => x.Select <User>(usr => usr.Id == 101), Times.Once()); mock.Verify(x => x.Select <User>(usr => usr.Id == 102), Times.Never()); mock.Verify(x => x.Select <User>(It.IsAny <Expression <Func <User, bool> > >()), Times.Exactly(2)); }
public void ShouldReturnNullListOnLoose() { var mock = new Mock <IFoo>(MockBehavior.Loose); Assert.Null(mock.Object.GetList()); }
public void ArgumentNullMatchProperCtor() { var target = new Mock <Foo>(null); Assert.Null(target.Object.Bar); }