public void SetMoney(MoneyCollection money) { lock (_lock) { _state.SetMoney(money); } }
private void LoadNotes(MoneyCollection moneyCollection) { var noteLoader = new NoteRepository(_sqlConnectionProvider); foreach (var noteEntity in noteLoader.Load(moneyCollection.Currency)) { moneyCollection.Notes.Add(noteEntity.Nominal, noteEntity.Count); } }
public static MoneyCollection ToMoneyCollection(this MoneyInfo moneyInfo) { var moneyCollection = MoneyCollection.Create(CurrencyRegistry.GetCurrency(moneyInfo.Currency)); moneyInfo.Coins.ForEach(coinInfo => moneyCollection.Coins.Add(coinInfo.Nominal, coinInfo.Count)); moneyInfo.Notes.ForEach(noteInfo => moneyCollection.Notes.Add(noteInfo.Nominal, noteInfo.Count)); return(moneyCollection); }
private void EnsureMoneyLoaded(Currency currency) { if (!_totalMoney.ContainsKey(currency)) { var money = MoneyCollection.Create(currency); LoadNotes(money); LoadCoins(money); _totalMoney.Add(currency, money); } }
private void LoadCoins(MoneyCollection moneyCollection) { var coinLoader = new CoinRepository(_sqlConnectionProvider); foreach (var coinEntity in coinLoader.Load(moneyCollection.Currency)) { Verifiers.Verify(coinEntity.Count >= 0, "Coins count is less than zero: {0}", coinEntity.Count); moneyCollection.Coins.Add(coinEntity.Nominal, coinEntity.Count); } }
private bool TryExchange(MoneyCollection resultMoney) { ICountableCollection <int> exchangeResult; var greedyExchanger = new GreedyExchanger(); if (greedyExchanger.TryExchange(new DecreasingIntegerCollectionMultiplier(Money.Notes, _currency.UnitFractions), _insertedCoins.Total, out exchangeResult)) { resultMoney.Notes.Add(exchangeResult.Select(nominal => nominal / Money.Currency.UnitFractions)); return(true); } resultMoney.Coins.Add(_insertedCoins); return(false); }
private bool TryExchange(MoneyCollection resultMoney) { int valueForExchange = _insertedNotes.Total * _currency.UnitFractions; var money = _cashRepository.LoadMoney(_currency); ICountableCollection <int> exchangeResult; var greedyExchanger = new GreedyExchanger(); if (greedyExchanger.TryExchange(money.Coins, valueForExchange, out exchangeResult)) { resultMoney.Coins.Add(exchangeResult); return(true); } resultMoney.Notes.Add(_insertedNotes); return(false); }
public IExchangeResult Exchange() { var returnedMoney = MoneyCollection.Create(_currency); bool success = TryExchange(returnedMoney); if (success) { _cashRepository.RemoveMoney(returnedMoney); } _owner.ChangeState <FreshMachineState>(_cashRepository, _currency); return(new ExchangeResult { Success = success, Money = returnedMoney }); }
void OnTriggerEnter(Collider col) { //Don't do a getcomponent if it isn't on our layer. if (col.gameObject.layer == 8) { MoneyProjectile money = col.GetComponent <MoneyProjectile>(); if (money != null && CanWeCollectThisMoney(money)) { MoneyCollection collection = new MoneyCollection(); collection.collisionLocation = MyCollider.ClosestPoint(col.transform.position); collection.moneyCollide = col; collection.collectionBin = transform; collection.collectionFloor = Floor.transform; collection.dirToOutOfBin = OutDirection; CollectMoney(money, collection); } } }
private HttpResponseMessage SetMoney(MoneyCollection money) { return(HttpClient.SendAsync(CreateRequest("api/cashmachine/money", HttpMethod.Post, MoneyInfo.CreateFrom(money))).Result); }
private void Given_InitialMoney_And_MoneyInserted_Then_MakeExchangeRequest_Should_ReturnExpectedMoney(MoneyCollection initialMoney, MoneyCollection insertedMoney, HttpStatusCode expectedStatusCode, MoneyCollection expectedExchangeResult, MoneyCollection expectedMoneyAfterExchange) { SetMoney(initialMoney).AssertSuccess(); insertedMoney.Notes.SelectMany(noteNominalCounPair => Enumerable.Repeat(noteNominalCounPair.Key, noteNominalCounPair.Value)) .ForEach(noteNominal => InsertNote(noteNominal).AssertSuccess()); insertedMoney.Coins.SelectMany(coinNominalCounPair => Enumerable.Repeat(coinNominalCounPair.Key, coinNominalCounPair.Value)) .ForEach(coinNominal => InsertCoin(coinNominal).AssertSuccess()); var actualExchangeResult = Exchange().AssertStatusCode(expectedStatusCode) .ExtractJson <MoneyInfo>() .ToMoneyCollection(); Assert.IsTrue(MoneyCollectionEqualityComparer.IsEquals(expectedExchangeResult, actualExchangeResult)); var actualMoneyAfterExchange = GetAvailableMoney().AssertSuccess() .ExtractJson <MoneyInfo>() .ToMoneyCollection(); Assert.IsTrue(MoneyCollectionEqualityComparer.IsEquals(expectedMoneyAfterExchange, actualMoneyAfterExchange)); }
public void RemoveMoney(MoneyCollection money) { EnsureMoneyLoaded(money.Currency); RemoveNotes(money.Notes, money.Currency); RemoveCoins(money.Coins, money.Currency); }
public void SetMoney(MoneyCollection money) { _cashRepository.SetMoney(money); }
public void CollectMoney(MoneyProjectile money, MoneyCollection OutDirection) { money.StartCoroutine(money.CollectMoney(OutDirection)); }
public static MoneyInfo CreateFrom(MoneyCollection money) { return(new MoneyInfo(money.Currency.Name, money.Notes.ToMonetaryAggregateInfoCollection(), money.Coins.ToMonetaryAggregateInfoCollection())); }
public void AddMoney(MoneyCollection money) { EnsureMoneyLoaded(money.Currency); AddNotes(money.Notes, money.Currency); AddCoins(money.Coins, money.Currency); }
public void SetMoney(MoneyCollection money) { throw new InvalidOperationException("Failed to set available money: complete notes exchange"); }
public void SetMoney(MoneyCollection money) { RemoveMoney(LoadMoney(money.Currency)); AddMoney(money); }
public MoneyBuilder(Currency currency) { _money = MoneyCollection.Create(currency); }