public ReceiptAttempt ProcessPurchaseAttempt (string username, string password, Item clientDescriptionOfItem) {
			return ReceiptAttempt.Make(() => {
				Global.DoWrappingExceptions<GildedRoseClientComplaintException>(() => {
					username = username.NullHandlingNormalize();
					password = password.NullHandlingNormalize();
					clientDescriptionOfItem = clientDescriptionOfItem.WithNormalizedStrings();
					Assert.NotNull(username);
					Assert.NotNull(password);
					clientDescriptionOfItem.AssertNotNullAndInvariantsIfAny();
				}, "Invalid data.");
				lock (model) {//todo find a way to not do this.
					var customer = model.AuthenticateOrThrow(username, password);
					return model.ConductSaleOrThrow(customer, clientDescriptionOfItem);
				}
			});
		}
Exemplo n.º 2
0
		public Receipt ConductSaleOrThrow (Customer customer, Item clientDescriptionOfItem) {
			var actualItem = ItemMatching(clientDescriptionOfItem);
			if (actualItem == null) Global.ThrowComplaint("Item not carried.", true);
			if (!customer.CanAfford(actualItem)) Global.ThrowComplaint("Insufficient money.", true);
			return ConductSale(customer, actualItem);
		}
Exemplo n.º 3
0
		///<summary>Precondition: sale is valid.</summary>
		public Receipt ConductSale (Customer customer, Item item) {
			customer.MoneyInWallet -= item.Price;
			MoneyInRegister += item.Price;
			inventory.Remove(item);
			return new Receipt(customer, item);
		}
Exemplo n.º 4
0
		public Item ItemMatching (Item description) {return inventory.ItemMatching(description);}
Exemplo n.º 5
0
		public void Remove (Item item) {items.Remove(item);}
Exemplo n.º 6
0
		public Item ItemMatching (Item description) {return items.FirstOrDefault(i => i.InterchangeableWith(description));}
Exemplo n.º 7
0
		uint price = 10;//Invariant: positive.
		public bool InterchangeableWith (Item other) {return name == other.name && description == other.description && price == other.price;}
Exemplo n.º 8
0
		public bool CanAfford (Item item) {return item.Price <= MoneyInWallet;}
Exemplo n.º 9
0
			[Theory] public static void Invariants (Item item) {
				Assume.That(item != null);
				// ReSharper disable once PossibleNullReferenceException
				item.AssertInvariants();
			}