static void Main(string[] args) { Console.Clear(); VendingController vc = new VendingController(); vc.Run(); }
public void InsertMoneySeveralTimesTest() { //arrange var vm = new VendingController(false); var expInitialMoney = 0; var expFirstBuyRemains = 20; var expSecondBuyRemains = 20; var expThirdBuyRemains = 20; //act var actInitialMoney = vm.Payment; bool insertResult1 = vm.InsertMoney(20); var actFirstInsertRemainders = vm.Payment; bool insertResult2 = vm.InsertMoney(-50); //negative value, not in denominations var actSecondInsertRemainders = vm.Payment; bool insertResult3 = vm.InsertMoney(133); //not in denominations var actThirdInsertRemainders = vm.Payment; //assert Assert.Equal(expInitialMoney, actInitialMoney); Assert.Equal(expFirstBuyRemains, actFirstInsertRemainders); Assert.Equal(expSecondBuyRemains, actSecondInsertRemainders); Assert.Equal(expThirdBuyRemains, actThirdInsertRemainders); Assert.True(insertResult1); Assert.False(insertResult2); Assert.False(insertResult3); }
public void PropertyPaymentTest() { //Arrange var vm1 = new VendingController(true); int expectedInitialPayment = 0; int expectedChangedPayment = 20; var vm2 = new VendingController(false); //Act int actualInitialPayment = vm1.Payment; //set method is private, can only be set from other methods in the class bool goodInsert = vm1.InsertMoney(20); int actualChangedPayment = vm1.Payment; //item 0 costs more than available... expects Payment to be unchanged string purchaceResult = vm1.Purchase(0);//item 0 costs more than available... expects Payment to be unchanged int actualPayment = vm1.Payment; bool insertResult = vm1.InsertMoney(-100); //-100 is not in denomination, should not be accepted int actualPaymentAfterFailedInsert = vm1.Payment; //Assert Assert.Equal(expectedInitialPayment, actualInitialPayment); Assert.True(goodInsert); Assert.Equal(expectedChangedPayment, actualChangedPayment); Assert.Equal(actualChangedPayment, actualPayment); Assert.Contains("More money needed", purchaceResult); Assert.Equal(actualChangedPayment, actualPaymentAfterFailedInsert); Assert.False(insertResult); }
public void MultiplePurchasesTest() { //Arrange var vm = new VendingController(true); var expInitialMoney = 0; var expInsertMoney1 = 10; var expInsertMoney2 = 10; //Act var actInitialMoney = vm.Payment; vm.InsertMoney(10); var actInsertMoney1 = vm.Payment; vm.InsertMoney(-1); //should not be accepted since it is not in denominations var actInsertMoney2 = vm.Payment; //money should remain the same string returnString = vm.Purchase(1); //purchase item 1 with price 15 (more money needed) var actPurchase1Remainder = vm.Payment; string returnString2 = vm.Purchase(7); //purchase item 7 with price 10 var actPurchase2Remainder = vm.Payment; //Assert Assert.Equal(expInitialMoney, actInitialMoney); Assert.Equal(expInsertMoney1, actInsertMoney1); Assert.Equal(expInsertMoney2, actInsertMoney2); Assert.Contains("More money needed", returnString); Assert.Equal(expInsertMoney2, actPurchase1Remainder); Assert.Contains("Water", returnString2); Assert.Equal(0, actPurchase2Remainder); }
public void InsertMoneyTest(int amount, bool expectedResult, int expectedAmount) { //arrange var vm = new VendingController(false); //act bool insertResult = vm.InsertMoney(amount); //assert Assert.Equal(insertResult, expectedResult); Assert.Equal(expectedAmount, vm.Payment); }
public void ConstructorNoProductsAddedTest() { //Arrange int initialPayment = 0; string choice = "choice"; //Act var vm = new VendingController(false); //Assert Assert.Equal(initialPayment, vm.Payment); Assert.DoesNotContain(choice, vm.ShowAll()); }
public void PurchaseTest(int availableMoney, int choice, string expectedResult) { //Arrange var vm = new VendingController(true); vm.InsertMoney(availableMoney); //Act string actualReturnString = vm.Purchase(choice); //Assert Assert.Contains(expectedResult, actualReturnString); }
public void ConstructorWithAdditionTest() { //Arrange int initialPayment = 0; string lastChoice = "Choice 7"; //Act var vm = new VendingController(true); //Assert Assert.Equal(initialPayment, vm.Payment); Assert.Contains(lastChoice, vm.ShowAll()); }
public void EndTransactionTest(int availableMoney, int choice, int expChange, string expResult) { //Arrange var vm = new VendingController(true); vm.InsertMoney(availableMoney); vm.Purchase(choice); int actualPayment = vm.Payment; //Act string actualResult = vm.EndTransaction(); //Assert Assert.Equal(expChange, actualPayment); Assert.Contains(expResult, actualResult); }
public void DeleteStockTest() { var commandMock = new Mock <ICommandBus>(); var queryMock = new Mock <IQueryProcessor>(); var vendingController = new VendingController(commandMock.Object, queryMock.Object); var flavour = "f1"; vendingController.DeleteStock(flavour); commandMock.Verify(bus => bus.Send(It.Is <DeleteStock>(stock => stock.Flavour == flavour)), Times.Once); }
public void AddStockTest() { var commandMock = new Mock <ICommandBus>(); var queryMock = new Mock <IQueryProcessor>(); var vendingController = new VendingController(commandMock.Object, queryMock.Object); var add = new CanItemDto("f1", 1, 1); vendingController.AddStock(add); commandMock.Verify(bus => bus.Send(It.Is <AddStock>(stock => stock.Flavour == add.Flavour && stock.Price == add.Price && stock.Quantity == add.Quantity)), Times.Once); }
static void Main(string[] args) { VendingController vc = new VendingController(); vc.Run(); }
void Update() { if (IsInActionRadius() == true) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D[] hits = Physics2D.RaycastAll(mousePos2D, Vector2.zero); if (hits.Length == 0) { isdetected = false; } foreach (var hit in hits) { if (hit.collider.tag == "substitudeItem") { BaseConection baseConection = hit.collider.GetComponent <BaseConection>(); NPC_Info npcInfo = hit.collider.GetComponent <NPC_Info>(); PCController pcController = baseConection.FindPcInRadius(); string interactionStr = Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_TURN_OFF; if (pcController != null) { bool isConnected = pcController.peripherals.Contains(hit.collider.gameObject); interactionStr = ((isConnected == true) ? Global.Tooltip.LM_DISCONNECT : Global.Tooltip.LM_CONNECT) + " / " + Global.Tooltip.RM_TURN_OFF; } isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.transform.position); ShowToolTip(npcInfo == null ? "obj" : npcInfo.npcName, interactionStr); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "table") { TableController tableController = hit.collider.GetComponent <TableController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == false) { ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName, PrintRed(Global.Tooltip.NO_ACTIONS)); } else if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true) { Item itemOnTable = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false)?.collider .GetComponent <ItemCell>().item; ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + itemOnTable.itemName + ")" : tableController.tableName + " (" + itemOnTable.itemName + ")", Global.Tooltip.LM_PICK_UP); } else if (IsCurrentHandEmpty() == false && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true) { Item tool = controller.GetItemInHand(controller.currentHand); RaycastHit2D?itemOnTableHit = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false); Item temOnTable = itemOnTableHit.GetValueOrDefault().collider.GetComponent <ItemCell>().item; ItemCraftData craftData = CraftController.FindRecept_Static(tool, temOnTable, CraftType.Cooking, /* TODO */ CraftTable.Table); ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + temOnTable.itemName + ")" : tableController.tableName + " (" + temOnTable.itemName + ")", Global.Tooltip.LM_PUT + ((tableController.isCraftTable) ? ((craftData != null) ? " / " + Global.Tooltip.RM_CRAFT + " " + craftData.recept.craftResult.itemName : string.Empty) : string.Empty)); } else { ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName, Global.Tooltip.LM_PUT); } TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX)) { bool onTable = false; foreach (var hitTable in hits) { if (hitTable.collider.tag == "table") { onTable = true; } } if (onTable == false) { Item item = hit.collider.GetComponent <ItemCell>().item; Item itemInHand = controller.currentHand.GetComponent <ItemCell>().item; isdetected = true; string useInteraction = (item.itemSubstitution.IsSubstituted() == true && item.itemSubstitution.IsItemToUseExist(itemInHand)) ? " / " + Global.Tooltip.RM_TURN_ON : string.Empty; ShowToolTip(item.itemName, (controller.IsEmpty(controller.currentHand) == true) ? Global.Tooltip.LM_PICK_UP + useInteraction : ((useInteraction == string.Empty) ? PrintRed(Global.Tooltip.NO_ACTIONS) : useInteraction.Substring(" / ".Length))); TooltipLocate(hit.collider.transform.position); return; } } else if (hit.collider.tag == "case") { CaseController caseController = hit.collider.GetComponent <CaseController>(); isdetected = true; ShowToolTip((caseController.caseName == string.Empty) ? "case" : caseController.caseName, (caseController.isOpen == false) ? Global.Tooltip.LM_OPEN : Global.Tooltip.LM_CLOSE); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "tv") { TVController tvController = hit.collider.GetComponent <TVController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); ShowToolTip("tv", (tvController.IsTvOpen() == false) ? Global.Tooltip.LM_TURN_ON : Global.Tooltip.LM_TURN_OFF + " / " + Global.Tooltip.RM_NEXT_CHANNEL); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "envObj") { VendingController vending = hit.collider.GetComponent <VendingController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position + // Global.Tooltip.EnvObjOffset()); ShowToolTip((vending.headerTitle == string.Empty) ? "vending" : vending.headerTitle.ToLower(), Global.Tooltip.LM_USE); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "pc") { Item itemInHand = controller.currentHand.GetComponent <ItemCell>().item; PCController pcController = hit.collider.GetComponent <PCController>(); Item disk = pcController.disk; isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); if (disk != null && controller.IsEmpty(controller.currentHand)) { ShowToolTip("pc", Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_PULL_THE_DISK); } else { ShowToolTip("pc", (controller.IsEmpty(controller.currentHand) == false && itemInHand.itemName.Contains("disk")) ? Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_INSERT : Global.Tooltip.LM_INTERACT); } TooltipLocate(hit.collider.transform.position); } else if (hit.collider.tag == "playerAction") { if (controller.IsEmpty(controller.currentHand) == false && controller.GetItemInHand(controller.currentHand).itemBuff.buff != null) { playerTooltip.gameObject.SetActive(true); } else { playerTooltip.gameObject.SetActive(false); } return; } else if (hit.collider.gameObject.name.Contains(Global.ITEM_SWITCH_PREFIX)) { isdetected = true; ISwitchItem switchItem = hit.collider.GetComponent <ISwitchItem>(); Item itemInHand = controller.GetItemInHand(controller.currentHand); ShowToolTip(switchItem.GetISwitchName(), (itemInHand.IsSameItems(switchItem.GetNeedItem()) ? Global.Tooltip.RM_INSERT : PrintRed(Global.Tooltip.NO_ACTIONS))); TooltipLocate(hit.collider.transform.position); } else { isdetected = false; } //playerTooltip.gameObject.SetActive(hit.collider.tag == "player"); } playerTooltip.gameObject.SetActive(false); if (isTooltipOpen == true && isdetected == false) { HideToolTip(); } } else { if (isTooltipOpen == true) { HideToolTip(); } } }
public void VendingTest() { VendingController.Vending(); }