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); }
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); }
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); }
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}"); }