public void Setup() { UnityEngine.Assertions.Assert.raiseExceptions = true; _converter = new CurrencyDoubleConverter(); _currencyCollection = new CurrencyCollection(); _gold = new Currency(Guid.NewGuid(), "Gold", "GOLD", 2, double.MaxValue); _silver = new Currency(Guid.NewGuid(), "Silver", "SILVER", 5, double.MaxValue); _copper = new Currency(Guid.NewGuid(), "Copper", "COPPER", 5, double.MaxValue); _diamonds = new Currency(Guid.NewGuid(), "Diamonds", "DIAMONDS", 0, double.MaxValue); _guildCredits = new Currency(Guid.NewGuid(), "Guild Credits", "GUILD", 0, double.MaxValue); _gold.conversionTable = new ConversionTable <ICurrency, double>(new Dictionary <ICurrency, ConversionTable <ICurrency, double> .Row>() { { _diamonds, new ConversionTable <ICurrency, double> .Row(0.01d) }, { _silver, new ConversionTable <ICurrency, double> .Row(100d) }, }); _silver.conversionTable = new ConversionTable <ICurrency, double>(new Dictionary <ICurrency, ConversionTable <ICurrency, double> .Row>() { { _gold, new ConversionTable <ICurrency, double> .Row(0.01d) }, { _copper, new ConversionTable <ICurrency, double> .Row(100d) }, }); _copper.conversionTable = new ConversionTable <ICurrency, double>(new Dictionary <ICurrency, ConversionTable <ICurrency, double> .Row>() { { _silver, new ConversionTable <ICurrency, double> .Row(0.01d) }, { _guildCredits, new ConversionTable <ICurrency, double> .Row(2d) }, }); _currencyCollection.Add(_gold, 10); _currencyCollection.Add(_silver, 10); }
public void MaxCurrencyTest() { var currencyCollection = new CurrencyCollection(); var currency1 = _currencyFactory.Create("USD", 1, 100, DateTime.Today); var currency2 = _currencyFactory.Create("USD", 1, 200, DateTime.Today); var currency3 = _currencyFactory.Create("USD", 1, 300, DateTime.Today); currencyCollection.Add(currency1); currencyCollection.Add(currency2); currencyCollection.Add(currency3); var max = currencyCollection.Max(); Assert.True(max == 300.0m, $"{max} <> {300.0m}"); }
public void MinCurrencyTest() { var currencyCollection = new CurrencyCollection(); var currency1 = _currencyFactory.Create("USD", 1, 100, DateTime.Today); var currency2 = _currencyFactory.Create("USD", 1, 200, DateTime.Today); var currency3 = _currencyFactory.Create("USD", 1, 300, DateTime.Today); currencyCollection.Add(currency1); currencyCollection.Add(currency2); currencyCollection.Add(currency3); var min = currencyCollection.Min(); Assert.True(min == 100.0m, $"{min} <> {100.0m}"); }
public void OnBuyItemFromVendorEventTest() { // Arrange BuyFromVendorResult <IItemInstance> boughtResult = null; int eventCount = 0; _vendor.OnBoughtFromVendor += (sender, result) => { boughtResult = result; eventCount++; }; _vendorCollection.Add(_product1, 10); _customerCurrencies.Add(_gold, 100); // Act var bought = _vendor.BuyFromVendor(_customer, _item1, 2); // Assert Assert.IsNull(bought.error); Assert.AreEqual(1, eventCount); Assert.AreEqual(boughtResult.amount, 2); Assert.AreEqual(boughtResult.item, _product1); Assert.AreEqual(boughtResult.currencies[0].currency, _gold); }
public void OnSellItemToVendorEventTest() { // Arrange SellToVendorResult <IItemInstance> sellResult = null; int eventCount = 0; _vendor.OnSoldToVendor += (sender, result) => { sellResult = result; eventCount++; }; _customerCollection.Add(_item1, 10); _vendorCurrencies.Add(_gold, 100); // Act var sold = _vendor.SellToVendor(_customer, _product1, 2); // Assert Assert.IsNull(sold.error); Assert.AreEqual(1, eventCount); Assert.AreEqual(sellResult.amount, 2); Assert.AreEqual(sellResult.item, _product1); Assert.AreEqual(sellResult.currencies[0].currency, _gold); }
public void MedianCurrencyTest() { var currencyCollection = new CurrencyCollection(); var currency1 = _currencyFactory.Create("USD", 1, 100, DateTime.Today); var currency2 = _currencyFactory.Create("USD", 1, 200, DateTime.Today); var currency3 = _currencyFactory.Create("USD", 1, 300, DateTime.Today); currencyCollection.Add(currency1); currencyCollection.Add(currency2); currencyCollection.Add(currency3); var median = currencyCollection.Median(); Assert.True(currencyCollection.Count == 3, "CurrencyCollection len <> 3"); Assert.True(median == 200.0m, $"{median} <> {200.0m}"); }
public void test_add_currency_to_collection() { //Given var twd = Currency.Create("TWD", 2); ICurrencyLookup collection = new CurrencyCollection(); //When collection.Add(twd); //Then Assert.True(collection.CurrencyList.Count() > 0); }
public void test_find_currency() { //Given var twd = Currency.Create("TWD", 2); ICurrencyLookup collection = new CurrencyCollection(); collection.Add(twd); //When var find = collection.Find(twd.CurrencyCode); //Then Assert.Equal(twd, find); }
private static CurrencyCollection DBMapping(DBCurrencyCollection dbCollection) { if (dbCollection == null) return null; CurrencyCollection collection = new CurrencyCollection(); foreach (DBCurrency dbItem in dbCollection) { Currency item = DBMapping(dbItem); collection.Add(item); } return collection; }
private static CurrencyCollection DBMapping(DBCurrencyCollection dbCollection) { if (dbCollection == null) { return(null); } CurrencyCollection collection = new CurrencyCollection(); foreach (DBCurrency dbItem in dbCollection) { Currency item = DBMapping(dbItem); collection.Add(item); } return(collection); }
public CurrencyCollection Query(string currencyID) { CurrencyCollection collection = new CurrencyCollection(); using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "SP_SEL_Table"; SqlParameter _param = command.Parameters.Add("@value1", System.Data.SqlDbType.VarChar); _param.Value = "System_Currency"; SqlParameter _param2 = command.Parameters.Add("@value2", System.Data.SqlDbType.VarChar); _param2.Value = "1"; SqlParameter _param3 = command.Parameters.Add("@value3", System.Data.SqlDbType.VarChar); _param3.Value = currencyID; SqlParameter _param4 = command.Parameters.Add("@order_by1", System.Data.SqlDbType.VarChar); _param4.Value = ""; SqlParameter _param5 = command.Parameters.Add("@order_by2", System.Data.SqlDbType.TinyInt); _param5.Value = 0 ; command.CommandType = System.Data.CommandType.StoredProcedure; connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Currency currency = new Currency(); currency.CurrencyID = reader["Currency_ID"].ToString(); collection.Add(currency); } } return collection; } }
public void AddToCurrencyTest() { var result = _currencies.Add(_gold, 2); Assert.IsNull(result.error); Assert.IsTrue(result.result); }