示例#1
0
        public async void GetAll_test_InternalServerError()
        {
            //Given
            var queryMock   = new Mock <IPedidoQuery>();
            var commandMock = new Mock <IPedidoCommand>();

            var mocker             = new AutoMoqer();
            var baseControllerMock = new PedidoController(commandMock.Object, queryMock.Object, "User");

            var faker = AutoFaker.Create();

            var response = new Exception();

            var expectResponse = baseControllerMock.StatusCode(500);

            queryMock.Setup(r => r.GetAll()).ThrowsAsync(response).Verifiable();

            //When
            var result = await baseControllerMock.GetAll();

            //Then
            //var comparison = new CompareLogic();
            queryMock.Verify(mock => mock.GetAll(), Times.Once());
            Assert.True(((ObjectResult)result).StatusCode == expectResponse.StatusCode);
        }
示例#2
0
        public async void GetAll_test()
        {
            //Given
            var queryMock   = new Mock <IPedidoQuery>();
            var commandMock = new Mock <IPedidoCommand>();

            var mocker             = new AutoMoqer();
            var baseControllerMock = new PedidoController(commandMock.Object, queryMock.Object, "User");

            var faker = AutoFaker.Create();

            var response = faker.Generate <List <PedidoEntity> >();

            var expectResponse = baseControllerMock.Ok(response);

            queryMock.Setup(r => r.GetAll()).ReturnsAsync(response).Verifiable();

            //When
            var result = await baseControllerMock.GetAll();

            //Then
            var comparison = new CompareLogic();

            queryMock.Verify(mock => mock.GetAll(), Times.Once());
            Assert.True(comparison.Compare(result, expectResponse).AreEqual);
        }
示例#3
0
        public async void GetAll_test_NotFound()
        {
            //Given
            var queryMock   = new Mock <IPedidoQuery>();
            var commandMock = new Mock <IPedidoCommand>();

            var mocker             = new AutoMoqer();
            var baseControllerMock = new PedidoController(commandMock.Object, queryMock.Object, "User");

            var faker = AutoFaker.Create();

            var response = new List <PedidoEntity>();

            var expectResponse = baseControllerMock.NotFound(response);

            queryMock.Setup(r => r.GetAll()).ReturnsAsync(response).Verifiable();

            //When
            var result = await baseControllerMock.GetAll();

            //Then
            //var comparison = new CompareLogic();
            queryMock.Verify(mock => mock.GetAll(), Times.Once());
            Assert.True(((NotFoundResult)result).StatusCode == ((NotFoundObjectResult)expectResponse).StatusCode);
        }
示例#4
0
        public async Task GetAllPedido_Should_Return_Ok()
        {
            //Arrange
            var Pedidos = PedidoBuilder.GetPedidosTest();

            //Act
            _mock.Setup(x => x.GetAll()).Returns(Pedidos);
            var result = await _controller.GetAll() as OkObjectResult;

            //Assert
            result.Should().NotBeNull("Result is null.");
            result.Value.Should().BeOfType <List <PedidoModel> >($"Return type is not List<PedidoModel>");
            result.StatusCode.Should().Be(200, $"Status Code {result.StatusCode}");
        }