Example #1
0
        public SalvarClienteTest()
        {
            var mocker = new AutoMoqer <SalvarClienteCommandHandler>().Build();

            _commandHandler = mocker.Service;

            _repository  = mocker.Param <IClienteRepository>();
            _validations = mocker.Param <IValidationMessage>();
        }
Example #2
0
        public SalvarPedidoTest()
        {
            var mocker = new AutoMoqer <CriarPedidoCommandHandler>().Build();

            _commandHandler = mocker.Service;

            _mediator    = mocker.Param <IMediator>();
            _repository  = mocker.Param <IPedidoRepository>();
            _validations = mocker.Param <IValidationMessage>();

            DefaultArrange();
        }
Example #3
0
        public void AutoMoqerShouldThrowCorrectExceptionWithUsingStatement()
        {
            using (var automoqer = new AutoMoqer <CommonService>().Build())
            {
                automoqer
                .Param <ISimpleService>()
                .Setup(f => f.SetString(It.IsAny <string>()));

                throw new ArgumentException();
            }
        }
Example #4
0
 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);
     }
 }
Example #5
0
        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));
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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));
        }