public void AddCard_InvalidInventory_Throws() { //arrange const string CardId = "1-001"; var inventoryId = Guid.NewGuid().ToString(); var repository = new Mock <IInventoryRepository>(); repository.Setup(r => r.GetInventory(inventoryId)).Returns((Inventory)null); //act var inventoryService = new InventoryService(repository.Object); //assert Assert.Throws <Exception>(() => inventoryService.AddCard(inventoryId, CardId)); repository.Verify(r => r.AddCard(inventoryId, CardId), Times.Never); }
public void AddCard_ValidInputs_CardAddedSuccessfully() { //arrange var inventoryId = Guid.NewGuid().ToString(); const string CardId = "1-001"; var repository = new Mock <IInventoryRepository>(); repository.Setup(r => r.GetInventory(inventoryId)).Returns(new Inventory(inventoryId, new List <Card>())); //act var inventoryService = new InventoryService(repository.Object); inventoryService.AddCard(inventoryId, CardId); //assert repository.Verify(r => r.AddCard(inventoryId, CardId), Times.Once); }