示例#1
0
        public void GetAllMethod_Exception()
        {
            #region Arrange

            IInventarioItemManager manager = CreateInventarioItemManager();
            _inventarioItemServiceMocked.Setup(s => s.GetAll()).Throws(new Exception("Error controlado"));

            #endregion

            #region Act

            manager.GetAll().GetAwaiter().GetResult();

            #endregion
        }
示例#2
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var result = await _inventarioManager.GetAll();

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ocurrió un error al obtener los elementos del inventario.");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
示例#3
0
        public void GetAllMethod_OK()
        {
            #region Arrange

            IEnumerable <InventarioItem> expectedBD = new List <InventarioItem>()
            {
                new InventarioItem()
                {
                    Id             = Guid.NewGuid(),
                    Nombre         = "item 1",
                    Unidades       = 100,
                    FechaCaducidad = DateTime.UtcNow.AddDays(5)
                },
                new InventarioItem()
                {
                    Id             = Guid.NewGuid(),
                    Nombre         = "item 2",
                    Unidades       = 0,
                    FechaCaducidad = DateTime.UtcNow.AddDays(-5)
                }
            };

            IInventarioItemManager manager = CreateInventarioItemManager();
            _inventarioItemServiceMocked.Setup(s => s.GetAll()).Returns(Task.FromResult(expectedBD));

            #endregion

            #region Act

            var actual = manager.GetAll().Result;

            #endregion

            #region Assert

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual is IEnumerable <InventarioItemViewModel>);
            Assert.AreEqual(actual.Count(), expectedBD.Count());
            _inventarioItemServiceMocked.Verify(s => s.GetAll(), Times.Once);
            #endregion
        }