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);
				}
			});
		}
Пример #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);
		}
Пример #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);
		}
Пример #4
0
		public Item ItemMatching (Item description) {return inventory.ItemMatching(description);}
Пример #5
0
		public void Remove (Item item) {items.Remove(item);}
Пример #6
0
		public Item ItemMatching (Item description) {return items.FirstOrDefault(i => i.InterchangeableWith(description));}
Пример #7
0
		uint price = 10;//Invariant: positive.
		public bool InterchangeableWith (Item other) {return name == other.name && description == other.description && price == other.price;}
Пример #8
0
		public bool CanAfford (Item item) {return item.Price <= MoneyInWallet;}
Пример #9
0
			[Theory] public static void Invariants (Item item) {
				Assume.That(item != null);
				// ReSharper disable once PossibleNullReferenceException
				item.AssertInvariants();
			}