Ejemplo n.º 1
0
        public void Register()
        {
            var shopState     = new ShopState();
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(
                weaponRow,
                Guid.NewGuid(),
                0);
            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                price,
                itemUsable);

            shopState.Register(shopItem);

            Assert.Equal(1, shopState.Products.Count);
            Assert.Contains(productId, shopState.Products);
            Assert.Equal(shopItem, shopState.Products[productId]);
        }
Ejemplo n.º 2
0
        public void RegisterThrowShopStateAlreadyContainsException()
        {
            var shopState     = new ShopState();
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(
                weaponRow,
                Guid.NewGuid(),
                0);
            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                price,
                itemUsable);

            shopState.Register(shopItem);

            Assert.Throws <ShopStateAlreadyContainsException>(() => shopState.Register(shopItem));
        }
Ejemplo n.º 3
0
        public void TryGet()
        {
            var shopState     = new ShopState();
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(
                weaponRow,
                Guid.NewGuid(),
                0);
            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                price,
                itemUsable);

            shopState.Register(shopItem);

            Assert.True(shopState.TryGet(agentAddress, shopItem.ProductId, out var outShopItem));
            Assert.Equal(shopItem, outShopItem);

            shopState.Unregister(shopItem);

            Assert.False(shopState.TryGet(agentAddress, shopItem.ProductId, out _));
        }
Ejemplo n.º 4
0
        public void Unregister()
        {
            var shopState     = new ShopState();
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(
                weaponRow,
                Guid.NewGuid(),
                0);
            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                itemUsable,
                price
                );

            shopState.Register(shopItem);
            shopState.Unregister(agentAddress, shopItem);

            Assert.Equal(0, shopState.Products.Count);
            Assert.Equal(0, shopState.AgentProducts.Count);
            Assert.Equal(0, shopState.ItemSubTypeProducts.Count);

            Assert.Throws <FailedToUnregisterInShopStateException>(() =>
                                                                   shopState.Unregister(agentAddress, shopItem));
        }
Ejemplo n.º 5
0
        public void SerializeBackup1()
        {
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(weaponRow, Guid.NewGuid(), 0);
            var row        = _tableSheets.CostumeItemSheet.Values.First();

            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                price,
                itemUsable);

            var beforeSerialized   = shopItem.SerializeBackup1();
            var beforeDeserialized = new ShopItem((Dictionary)beforeSerialized);
            var serialized         = shopItem.Serialize();
            var deserialized       = new ShopItem((Dictionary)serialized);

            Assert.Equal(beforeSerialized, serialized);
            Assert.Equal(beforeDeserialized, deserialized);
        }
Ejemplo n.º 6
0
        public void LevelUp()
        {
            var row = new EquipmentItemSheet.Row();

            row.Set(new List <string>()
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000"
            });
            var equipment = (Equipment)ItemFactory.CreateItemUsable(row, default, 0, 0);
Ejemplo n.º 7
0
        public void Register()
        {
            var shopState     = new ShopState();
            var agentAddress  = new PrivateKey().ToAddress();
            var avatarAddress = new PrivateKey().ToAddress();
            var productId     = Guid.NewGuid();
            var weaponRow     = new EquipmentItemSheet.Row();

            weaponRow.Set(new[]
            {
                "10100000", "Weapon", "0", "Normal", "0", "ATK", "1", "2", "10100000",
            });
            var itemUsable = new Weapon(
                weaponRow,
                Guid.NewGuid(),
                0);
            var price    = new FungibleAssetValue(new Currency("NCG", 2, minter: null));
            var shopItem = new ShopItem(
                agentAddress,
                avatarAddress,
                productId,
                itemUsable,
                price
                );

            shopState.Register(shopItem);

            Assert.Equal(1, shopState.Products.Count);
            Assert.Contains(productId, shopState.Products);
            Assert.Equal(shopItem, shopState.Products[productId]);
            Assert.Equal(1, shopState.AgentProducts.Count);
            Assert.True(shopState.AgentProducts.ContainsKey(agentAddress));
            Assert.Single(shopState.AgentProducts[agentAddress]);
            Assert.Contains(productId, shopState.AgentProducts[agentAddress]);
            Assert.Equal(1, shopState.ItemSubTypeProducts.Count);
            Assert.Contains(ItemSubType.Weapon, shopState.ItemSubTypeProducts);
            Assert.Single(shopState.ItemSubTypeProducts[ItemSubType.Weapon]);
            Assert.Contains(productId, shopState.ItemSubTypeProducts[ItemSubType.Weapon]);

            Assert.Throws <ShopStateAlreadyContainsException>(() =>
                                                              shopState.Register(shopItem));
        }