public void SetUp()
        {
            var mocker = new AutoMocker();
            dataManipulator = mocker.GetMock<IHmrcDataManipulator>();
            configRepository = mocker.GetMock<IConfigurationRepository>();
            messageSender = mocker.GetMock<IMessageSender>();

            messageSender.Setup(x => x.PostXml(It.IsAny<string>(), It.IsAny<string>())).Returns(GetPostResult());

            proxyService = mocker.CreateInstance<ProxyService>();
        }
예제 #2
0
        public void ChangeStates()
        {
            // Arrange
            var mocker = new AutoMocker();
            mocker.Setup<IHartbeatTimer>(p => p.Reset()).Callback(() =>
            {

            });

            var mockFollower = mocker.GetMock<Follower>();
            var mockCandidate = mocker.GetMock<Candidate>();
            var mockLeader = mocker.GetMock<Leader>();

            mocker.Setup<IObservableProvider>(p =>  p.GetObservable<Follower, ServerStateType>())
                .Returns(mockFollower.Object);

            mocker.Setup<IObservableProvider>(p => p.GetObservable<Candidate, ServerStateType>())
                .Returns(mockCandidate.Object);

            mocker.Setup<IObservableProvider>(p => p.GetObservable<Leader, ServerStateType>())
                .Returns(mockLeader.Object);

            Machine<ServerStateType, ServerStateType> machine = null;
            mocker.Setup<IHartbeatTimer>(p => p.Subscribe(It.IsAny<Machine<ServerStateType, ServerStateType>>()))
                .Returns(new Disposable())
                .Callback<Machine<ServerStateType, ServerStateType>>(m =>
                {
                    machine = m;
                });
            
            var node = new Node(mocker.Get<IVoteReceived>(),
                mocker.Get<IAppendEntry>(),
                mocker.Get<IHartbeatTimer>(),
                mocker.Get<ILoggerFactory>(),
                mocker.Get<IObservableProvider>(),
                mocker.Get<ILogReplication>(),
                mocker.Get<ServerIdentifier>());

            var mockHartbeat = mocker.GetMock<IHartbeatTimer>();

            // Assert
            Assert.Equal(ServerStateType.Follower, node.State);

            machine.OnNext(ServerStateType.Candidate);

            Assert.Equal(ServerStateType.Candidate, node.State);

            machine.OnNext(ServerStateType.Leader);
        }
예제 #3
0
        public CandidateBaseTests()
        {
            var mocker = new AutoMocker();

            ServerIdentifier = new ServerIdentifier();
            mocker.Use(ServerIdentifier);


            Election = new Election();
            RequestVoteResult = new Subject<RequestVoteResultMessage>();
            RequestVote = new Subject<RequestVoteMessage>();
            MockVotingSystem = mocker.GetMock<IVotingSystem>();


            Candidate = new Rafting.States.Candidate(mocker.Get<ServerIdentifier>(),
                mocker.Get<IElectionTimer>(),
                RequestVote,
                RequestVoteResult,
                MockVotingSystem.Object,
                Election,
                mocker.Get<ILogReplication>(),
                mocker.Get<Nodes>(),
                mocker.Get<ILoggerFactory>(),
                new RaftOptions());
        }
예제 #4
0
        public async Task Pedido_AoAtualizarPedidoSemDroneCadastrado_RetornarNotificacoesComFalha()
        {
            // Arrange
            var command = new AtualizarPedidoStatusCommand(Guid.NewGuid(), PedidoStatus.Pago);

            var usuario = Usuario.Criar("test", "*****@*****.**", 0, 0, UsuarioRole.Cliente);

            //Usuario autenticado nao retorna nada
            _mocker.GetMock <IUsuarioAutenticado>()
            .Setup(p => p.GetCurrentId())
            .Returns(usuario.Id);

            //Obter usuario
            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Usuarios.ObterPorIdAsync(usuario.Id))
            .Returns(Task.FromResult(usuario));

            //obter pedido
            var pedido = Pedido.Criar(Guid.NewGuid(), 1000, 1000, usuario);

            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Pedidos.ObterPorIdAsync(pedido.Id))
            .Returns(Task.FromResult(pedido));



            //Criar lista de drones
            IEnumerable <Drone> drones = new List <Drone> {
            };

            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Drones.ObterTodosAsync())
            .Returns(Task.FromResult(drones));

            // Act
            var responseResult = await _handler.Handle(command, CancellationToken.None);

            // Assert
            Assert.True(responseResult.HasFails);
            Assert.True(responseResult.Fails.Count() == 1);
            Assert.NotNull(responseResult.Fails.Select(x => x.Message == Erros.ErroDrone_NaoCadastrado));
        }
예제 #5
0
 public void SetupSendCommand <T>(bool result) where T : Command
 {
     Mocker.GetMock <IMediatorHandler>().Setup(m => m.SendCommand(It.IsAny <T>()))
     .Returns(Task.FromResult(result));
 }
 public void GetCastSetup(List <Cast> casts)
 {
     Mocker.GetMock <IMovieRepository>()
     .Setup(x => x.GetCast(It.IsAny <Expression <Func <Cast, bool> > >()))
     .Returns(casts);
 }
예제 #7
0
        public void GetAll_listar_todas_pessoas()
        {
            //Arrange
            var pessoas = new List <Pessoa>()
            {
                new Pessoa(Guid.NewGuid(), "Anthue"),
                new Pessoa(Guid.NewGuid(), "Teste")
            };

            _mocker.GetMock <IPessoaRepository>().Setup(e => e.GetAll()).Returns(pessoas);

            //Act
            var result = _pessoaAppService.GetAll();

            //Assert
            _mocker.GetMock <IPessoaRepository>().Verify(e => e.GetAll(), Times.Once);
            Assert.Equal(2, result.Count());
        }
예제 #8
0
 protected Mock <TInterfaceType> GetMock <TInterfaceType>() where TInterfaceType : class
 {
     return(_mocker.GetMock <TInterfaceType>());
 }