public SalvarClienteTest() { var mocker = new AutoMoqer <SalvarClienteCommandHandler>().Build(); _commandHandler = mocker.Service; _repository = mocker.Param <IClienteRepository>(); _validations = mocker.Param <IValidationMessage>(); }
public SalvarPedidoTest() { var mocker = new AutoMoqer <CriarPedidoCommandHandler>().Build(); _commandHandler = mocker.Service; _mediator = mocker.Param <IMediator>(); _repository = mocker.Param <IPedidoRepository>(); _validations = mocker.Param <IValidationMessage>(); DefaultArrange(); }
public void AutoMoqerShouldThrowCorrectExceptionWithUsingStatement() { using (var automoqer = new AutoMoqer <CommonService>().Build()) { automoqer .Param <ISimpleService>() .Setup(f => f.SetString(It.IsAny <string>())); throw new ArgumentException(); } }
public void AutoMoqerWithExplicitVerificationCallThrowsExceptionForNonCalledMethods() { try { var automoqer = new AutoMoqer <CommonService>().BuildWithExplicitVerification(); automoqer .Param <ISimpleService>() .Setup(f => f.GetBool()) .Returns(true); automoqer.VerifyAll(); } catch (System.Reflection.TargetInvocationException exc) { // Moq.MockVerificationException is internal. Assert.AreEqual("Moq.MockVerificationException", exc.InnerException.GetType().FullName); } }
public void AutoMoqerCanBeCreatedWithNormalConstructorSuccessfullt() { var automoqer = new AutoMoqer <CommonService>().Build(); //Assert result Assert.IsNotNull(automoqer); //Assert parameter var parameter = automoqer.Param <ISimpleService>(); Assert.IsNotNull(parameter); Assert.IsInstanceOfType(parameter, typeof(Mock <ISimpleService>)); //Assert service Assert.IsNotNull(automoqer.Service); Assert.IsInstanceOfType(automoqer.Service, typeof(CommonService)); }
public void AutoMoqerThrowsExceptionOnDisposeForNonCalledMethods() { try { using (var automoqer = new AutoMoqer <CommonService>().Build()) { automoqer .Param <ISimpleService>() .Setup(f => f.GetBool()) .Returns(true); } // Should not happen. Assert.IsFalse(true); } catch (System.Reflection.TargetInvocationException exc) { // Moq.MockVerificationException is internal. Assert.AreEqual("Moq.MockVerificationException", exc.InnerException.GetType().FullName); } }
public void AutoMoqerCanBeCreatedWithEmptyConstructor() { var automoqer = new AutoMoqer <ServiceWithNoConstructorParameters>().Build(); //Assert result Assert.IsNotNull(automoqer); //Assert parameter try { automoqer.Param <ISimpleService>(); Assert.Fail("Should have thrown exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } //Assert service Assert.IsNotNull(automoqer.Service); Assert.IsInstanceOfType(automoqer.Service, typeof(ServiceWithNoConstructorParameters)); }