[Fix] Refactor project
This commit is contained in:
@@ -12,23 +12,23 @@ namespace YachtDice.Tests
|
||||
{
|
||||
public sealed class ShopModelTests
|
||||
{
|
||||
private CurrencyBank bank;
|
||||
private ModifierRegistry registry;
|
||||
private InventoryModel inventory;
|
||||
private DiceCollection diceCollection;
|
||||
private ShopModel shop;
|
||||
private CurrencyBank _bank;
|
||||
private ModifierRegistry _registry;
|
||||
private InventoryModel _inventory;
|
||||
private DiceCollection _diceCollection;
|
||||
private ShopModel _shop;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
var go = new GameObject("Bank");
|
||||
bank = go.AddComponent<CurrencyBank>();
|
||||
bank.SetBalance(500);
|
||||
_bank = go.AddComponent<CurrencyBank>();
|
||||
_bank.SetBalance(500);
|
||||
|
||||
registry = new ModifierRegistry(5);
|
||||
inventory = new InventoryModel(registry);
|
||||
diceCollection = new DiceCollection();
|
||||
shop = new ShopModel(bank, inventory, diceCollection);
|
||||
_registry = new ModifierRegistry(5);
|
||||
_inventory = new InventoryModel(_registry);
|
||||
_diceCollection = new DiceCollection();
|
||||
_shop = new ShopModel(_bank, _inventory, _diceCollection);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -52,24 +52,24 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(mod);
|
||||
bool result = _shop.TryPurchase(mod);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(400, bank.Balance);
|
||||
Assert.AreEqual(1, inventory.OwnedModifiers.Count);
|
||||
Assert.AreEqual(400, _bank.Balance);
|
||||
Assert.AreEqual(1, _inventory.OwnedModifiers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryPurchase_FailsWhenBroke()
|
||||
{
|
||||
bank.SetBalance(10);
|
||||
_bank.SetBalance(10);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(mod);
|
||||
bool result = _shop.TryPurchase(mod);
|
||||
|
||||
Assert.IsFalse(result);
|
||||
Assert.AreEqual(10, bank.Balance);
|
||||
Assert.AreEqual(0, inventory.OwnedModifiers.Count);
|
||||
Assert.AreEqual(10, _bank.Balance);
|
||||
Assert.AreEqual(0, _inventory.OwnedModifiers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -77,12 +77,12 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var mod = CreateDef("perm", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
bool secondResult = shop.TryPurchase(mod);
|
||||
_shop.TryPurchase(mod);
|
||||
bool secondResult = _shop.TryPurchase(mod);
|
||||
|
||||
Assert.IsFalse(secondResult);
|
||||
Assert.AreEqual(400, bank.Balance);
|
||||
Assert.AreEqual(1, inventory.OwnedModifiers.Count);
|
||||
Assert.AreEqual(400, _bank.Balance);
|
||||
Assert.AreEqual(1, _inventory.OwnedModifiers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -90,23 +90,23 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var mod = CreateDef("limited", hasLimitedUses: true, maxUses: 3, shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
bool secondResult = shop.TryPurchase(mod);
|
||||
_shop.TryPurchase(mod);
|
||||
bool secondResult = _shop.TryPurchase(mod);
|
||||
|
||||
Assert.IsTrue(secondResult);
|
||||
Assert.AreEqual(300, bank.Balance);
|
||||
Assert.AreEqual(2, inventory.OwnedModifiers.Count);
|
||||
Assert.AreEqual(300, _bank.Balance);
|
||||
Assert.AreEqual(2, _inventory.OwnedModifiers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryPurchase_FiresPurchaseEvent()
|
||||
{
|
||||
IShopItem purchased = null;
|
||||
shop.OnItemPurchased += item => purchased = item;
|
||||
_shop.OnItemPurchased += item => purchased = item;
|
||||
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
_shop.TryPurchase(mod);
|
||||
|
||||
Assert.IsNotNull(purchased);
|
||||
Assert.AreEqual("test", purchased.Id);
|
||||
@@ -117,16 +117,16 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
Assert.AreEqual(ShopItemState.Available, shop.GetItemState(mod));
|
||||
Assert.AreEqual(ShopItemState.Available, _shop.GetItemState(mod));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItemState_TooExpensive_WhenCannotAfford()
|
||||
{
|
||||
bank.SetBalance(10);
|
||||
_bank.SetBalance(10);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
Assert.AreEqual(ShopItemState.TooExpensive, shop.GetItemState(mod));
|
||||
Assert.AreEqual(ShopItemState.TooExpensive, _shop.GetItemState(mod));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -134,9 +134,9 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var mod = CreateDef("perm", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
_shop.TryPurchase(mod);
|
||||
|
||||
Assert.AreEqual(ShopItemState.Owned, shop.GetItemState(mod));
|
||||
Assert.AreEqual(ShopItemState.Owned, _shop.GetItemState(mod));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -144,11 +144,11 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var die = DiceDefinition.CreateForTest<StandardDice>("test_die", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(die);
|
||||
bool result = _shop.TryPurchase(die);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(400, bank.Balance);
|
||||
Assert.AreEqual(1, diceCollection.OwnedDice.Count);
|
||||
Assert.AreEqual(400, _bank.Balance);
|
||||
Assert.AreEqual(1, _diceCollection.OwnedDice.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -156,12 +156,12 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var die = DiceDefinition.CreateForTest<StandardDice>("unique_die", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(die);
|
||||
bool secondResult = shop.TryPurchase(die);
|
||||
_shop.TryPurchase(die);
|
||||
bool secondResult = _shop.TryPurchase(die);
|
||||
|
||||
Assert.IsFalse(secondResult);
|
||||
Assert.AreEqual(400, bank.Balance);
|
||||
Assert.AreEqual(1, diceCollection.OwnedDice.Count);
|
||||
Assert.AreEqual(400, _bank.Balance);
|
||||
Assert.AreEqual(1, _diceCollection.OwnedDice.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -169,9 +169,9 @@ namespace YachtDice.Tests
|
||||
{
|
||||
var die = DiceDefinition.CreateForTest<StandardDice>("die1", shopPrice: 50);
|
||||
|
||||
shop.TryPurchase(die);
|
||||
_shop.TryPurchase(die);
|
||||
|
||||
Assert.AreEqual(ShopItemState.Owned, shop.GetItemState(die));
|
||||
Assert.AreEqual(ShopItemState.Owned, _shop.GetItemState(die));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user