public void TestExecuteWithItemIdShouldReturnShopItemModelWithItemId() { //Arrange const int itemId = 2; _shopItems.Add(new ShopItem { Id = 2, Name = "testItemName2" }); var expectedResult = _mapper.Map <ShopItemModel>(_shopItems.FirstOrDefault(s => s.Id == itemId)); var mockShopItemRepository = new Mock <IShopItemRepository>(); mockShopItemRepository.Setup(s => s.Get(itemId)).Returns(_shopItems.FirstOrDefault(s => s.Id == itemId)); var sut = new GetShopItemsListQuery(mockShopItemRepository.Object, _mapper); //Act var result = sut.Execute(itemId); //Assert Assert.IsType <ShopItemModel>(result); Assert.Equal(expectedResult, result); }
public void TestExecuteShouldReturnListOfShopItemModel() { //Arrange var expectedResult = _shopItems.Select(s => _mapper.Map <ShopItemModel>(s)).ToList(); var mockShopItemRepository = new Mock <IShopItemRepository>(); mockShopItemRepository.Setup(s => s.GetAll()).Returns(_shopItems.AsQueryable); var sut = new GetShopItemsListQuery(mockShopItemRepository.Object, _mapper); //Act var result = sut.Execute(); //Assert Assert.IsType <List <ShopItemModel> >(result); Assert.Equal(expectedResult, result); }