Esempio n. 1
0
        public async Task <IActionResult> ReadAllCategories()
        {
            var command = new ReadAllCategoriesCommand();
            var result  = this._mediator.Send(command).Result;

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult(result));
        }
        public async void Handle_Exception_Test()
        {
            var ex = new Exception();

            this._unitOfUnitMock.Setup(mock => mock.CategoryRepository.ReadAll())
            .Throws(ex);

            ReadAllCategoriesCommand       command = new ReadAllCategoriesCommand();
            ReadAllCategoriesCommandHanler handler = new ReadAllCategoriesCommandHanler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Null(result);
        }
        public async void Handle_ReadAllCategories_Test()
        {
            List <Category> categories = new List <Category>();

            this._unitOfUnitMock.Setup(mock => mock.CategoryRepository.ReadAll())
            .Returns(Task.FromResult(categories));

            ReadAllCategoriesCommand       command = new ReadAllCategoriesCommand();
            ReadAllCategoriesCommandHanler handler = new ReadAllCategoriesCommandHanler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Equal(categories, result);
        }