public async Task ShouldAddFavouriteSupplierListThrowException() { FavouriteSupplierListModel favouriteSupplierList = new FavouriteSupplierListModel() { Name = "name", BranchId = 1 }; _moqSupplierQueries.Setup(s => s.FindFavouriteListByName(It.IsAny <string>(), It.IsAny <int>())) .Returns(() => { return(Task.FromResult <FavouriteSupplierList>(new IDMDefaults().GetFavouriteSupplierList())); }); await Assert.ThrowsAsync <BusinessRuleException>(async() => await _sut.AddFavouriteSupplierList(favouriteSupplierList)); }
public async Task <FavouriteSupplierListModel> AddFavouriteSupplierList(FavouriteSupplierListModel favouriteSupplierList) { var supplier = await _supplierQueries.FindFavouriteListByName(favouriteSupplierList.Name, favouriteSupplierList.BranchId); if (supplier != null) { throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.FavouriteListNameExist); } var FavouriteSupplierList = new FavouriteSupplierList(favouriteSupplierList.Name, favouriteSupplierList.AgencyCode, favouriteSupplierList.BranchId); var result = await _supplierCommands.CreateFavouriteSupplierListAsync(FavouriteSupplierList); favouriteSupplierList.FavouriteSupplierListId = result.FavouriteSupplierListId; return(favouriteSupplierList); }
public async Task <bool> DeleteFavouriteSupplierList(FavouriteSupplierListModel favouriteSupplierList) { Check.ArgumentNotNullOrEmpty(nameof(favouriteSupplierList.FavouriteSupplierListId), favouriteSupplierList.FavouriteSupplierListId.ToString()); var result = await _supplierQueries.FindFavouriteList(favouriteSupplierList.FavouriteSupplierListId); if (result.AgencyCode != favouriteSupplierList.AgencyCode) { throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.FavouriteListNotForAgency); } if (result.BranchId != favouriteSupplierList.BranchId) { throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.FavouriteListNotForBranch); } result.DeActive(); await _supplierCommands.UpdateFavouriteSupplierListAsync(result); return(true); }