コード例 #1
0
        public void SearchGroceriesCommandHandlerShouldReturnNotification()
        {
            var _mock   = MockRepository.GenerateMock <IGroceriesRepository>();
            var command = new SearchGroceriesCommand();

            _mock.Expect(x => x.GetAll()).Return(null);

            SearchGroceriesCommandHandler handler = new SearchGroceriesCommandHandler(_mock);
            var g = handler.Handle(command);

            Assert.AreNotEqual(handler.Notifications.Count, 0);
        }
コード例 #2
0
        public void SearchGroceriesCommandHandlerShouldntReturnNotification()
        {
            var _mock   = MockRepository.GenerateMock <IGroceriesRepository>();
            var command = new SearchGroceriesCommand();

            _mock.Expect(x => x.GetAll()).Return(new List <Groceries>()
            {
                new Groceries(Guid.NewGuid(), "Test1", 10, Unity.Grams, Category.Bakery),
                new Groceries(Guid.NewGuid(), "Test2", 20, Unity.Liters, Category.Bakery),
                new Groceries(Guid.NewGuid(), "Test3", 30, Unity.Unity, Category.Beverages)
            });

            SearchGroceriesCommandHandler handler = new SearchGroceriesCommandHandler(_mock);
            var g = handler.Handle(command);

            Assert.AreEqual(handler.Notifications.Count, 0);
        }
コード例 #3
0
        public void UpdateGroceriesPositionElementShouldMoveToCorrectPosition()
        {
            var _mock   = MockRepository.GenerateMock <IGroceriesRepository>();
            var command = new UpdateGroceriesPositionCommand(Guid.NewGuid(), 0);

            _mock.Expect(x => x.GetAll()).Return(new List <Groceries>()
            {
                new Groceries(Guid.NewGuid(), "Test1", 10, Unity.Grams, Category.Bakery),
                new Groceries(Guid.NewGuid(), "Test2", 20, Unity.Liters, Category.Bakery),
                new Groceries(command.Id, "Test3", 30, Unity.Unity, Category.Beverages) //Selected element to move.
            });

            UpdateGroceriesPositionCommandHandler handler = new UpdateGroceriesPositionCommandHandler(_mock);
            var g = handler.Handle(command);

            Assert.AreEqual(handler.Notifications.Count, 0);
            //Verify the new position of the element in the array.
            SearchGroceriesCommand        s             = new SearchGroceriesCommand();
            SearchGroceriesCommandHandler handlerSearch = new SearchGroceriesCommandHandler(_mock);
            SearchGroceriesCommandResult  groceries     = (SearchGroceriesCommandResult)handlerSearch.Handle(s);
            var grocery = groceries.GroceriesList.FirstOrDefault(x => x.Id == command.Id);
            var index   = groceries.GroceriesList.ToList().LastIndexOf(grocery);

            Assert.AreEqual(index, command.Position);
        }
コード例 #4
0
        public async Task <IActionResult> Get()
        {
            var result = _searchGroceriesCommandHandler.Handle(new SearchGroceriesCommand(null, 0, 0));

            return(await Response(result, _searchGroceriesCommandHandler.Notifications));
        }