Ejemplo n.º 1
0
        public async void Cadastrar_test()
        {
            //Given

            var queryMock   = new Mock <IPedidoQuery>();
            var commandMock = new Mock <IPedidoCommand>();

            var faker = AutoFaker.Create();

            var param = faker.Generate <PedidoParam>();

            var response = "Pedido realizado com sucesso!";

            var baseControllerMock = new PedidoController(commandMock.Object, queryMock.Object, "User");
            var expectResponse     = baseControllerMock.Ok(response);


            commandMock.Setup(r => r.InserirPedido(It.IsAny <PedidoParam>())).ReturnsAsync(true).Verifiable();

            //When

            var result = await baseControllerMock.Cadastrar(param);

            //Then
            var comparison = new CompareLogic();

            commandMock.Verify(mock => mock.InserirPedido(It.IsAny <PedidoParam>()), Times.Once());
            Assert.True(comparison.Compare(result, expectResponse).AreEqual);
        }
Ejemplo n.º 2
0
        public async void Cadastrar_test_InternalServerError()
        {
            //Given

            var queryMock   = new Mock <IPedidoQuery>();
            var commandMock = new Mock <IPedidoCommand>();

            var faker = AutoFaker.Create();

            var param = faker.Generate <PedidoParam>();

            var baseControllerMock = new PedidoController(commandMock.Object, queryMock.Object, "User");
            var expectResponse     = baseControllerMock.StatusCode(500);


            commandMock.Setup(r => r.InserirPedido(It.IsAny <PedidoParam>())).ThrowsAsync(new Exception()).Verifiable();

            //When

            var result = await baseControllerMock.Cadastrar(param);

            //Then
            //var comparison = new CompareLogic();
            commandMock.Verify(mock => mock.InserirPedido(It.IsAny <PedidoParam>()), Times.Once());
            Assert.True(((ObjectResult)result).StatusCode == expectResponse.StatusCode);
        }