/// <param name="parentPath">子菜单的父菜单的注册表路径</param>
                public void LoadItems(string parentPath)
                {
                    this.ParentPath = parentPath;
                    string value = GetValue(ParentPath, "SubCommands", null)?.ToString();

                    Array.ForEach(value.Split(';'), cmd => SubKeyNames.Add(cmd.TrimStart()));
                    SubKeyNames.RemoveAll(string.IsNullOrEmpty);

                    using (var shellKey = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath, false, true))
                    {
                        foreach (string keyName in SubKeyNames)
                        {
                            using (var key = shellKey.OpenSubKey(keyName))
                            {
                                MyListItem item;
                                if (key != null)
                                {
                                    item = new SubShellItem(this, keyName);
                                }
                                else if (keyName == "|")
                                {
                                    item = new SeparatorItem(this);
                                }
                                else
                                {
                                    item = new InvalidItem(this, keyName);
                                }
                                this.AddItem(item);
                            }
                        }
                    }
                }
        public void NameShouldChangeToNoSuchItem()
        {
            InvalidItem item = new InvalidItem("INVALID ITEM", 2, 2);

            item.DaysPast(1);
            Assert.AreEqual("NO SUCH ITEM", item.GetName());
        }
Пример #3
0
        public void TestInvalidItem_ToString_ReturnsExpectedOutput()
        {
            //Arrange / Act
            Item item = new InvalidItem("test-item", 1, 2);

            //Assert
            Assert.AreEqual("NO SUCH ITEM", item.ToString());
        }
Пример #4
0
        public void Order_should_not_be_valid_when_at_least_one_item_is_not_valid()
        {
            _order.Add(_validItem);
            IOrderItem invalidItem = new InvalidItem();

            _order.Add(invalidItem);
            _order.IsValid().Should().BeFalse();
        }
Пример #5
0
        public void UpdateSellIn_InvalidItem_Null()
        {
            Item item = new InvalidItem();

            item.SellIn = 1;
            item.UpdateSellIn();
            Assert.IsNull(item.SellIn);
        }
Пример #6
0
        public void UpdateName_InvalidItem_NoSuchItem()
        {
            Item item = new InvalidItem {
                Name = "a"
            };

            item.UpdateName();
            Assert.AreEqual("NO SUCH ITEM", item.Name);
        }
Пример #7
0
 public override int GetHashCode()
 {
     return(InvalidItem.GetHashCode() +
            PropertyName.GetHashCode() +
            Severity.GetHashCode() +
            ValidationCode.GetHashCode() +
            Message.GetHashCode() +
            Recommendation.GetHashCode());
 }
Пример #8
0
        public void TestInvalidItem_Age_SellInAndQualityAreNotUpdated()
        {
            //Arrange
            Item item = new InvalidItem("test-item", 1, 2);

            //Act
            item.Age();

            //Assert
            Assert.AreEqual(1, item.SellIn);
            Assert.AreEqual(2, item.Quality);
        }
Пример #9
0
        public void MarkAsInvalidUponMature()
        {
            // Arrange

            InventoryItem systemUnderTest = new InvalidItem("Something", 1, 2);

            // Act

            systemUnderTest.MatureOvernight();

            // Assert

            string result = systemUnderTest.Print();

            result.ShouldBe("NO SUCH ITEM");
        }
Пример #10
0
        public void InvalidItemIsInvalidatedWhenProcessed()
        {
            var invalidItem = new InvalidItem
            {
                SellIn  = 10,
                Quality = 10
            };

            Assert.IsTrue(invalidItem.IsValid);

            ManageInventory.ProcessItem(invalidItem);

            Assert.IsFalse(invalidItem.IsValid);
            Assert.AreEqual(0, invalidItem.SellIn);
            Assert.AreEqual(0, invalidItem.Quality);
        }
Пример #11
0
        private static List <Item> GetItemsFromFile(string fileName)
        {
            List <Item> items = new List <Item>();

            string[] fileLines = File.ReadAllLines(fileName);
            foreach (string line in fileLines)
            {
                string[] temp     = line.Split(' ');
                string   itemName = "";
                int      sellIn;
                int      quality;

                if (temp.Length > 3)
                {
                    itemName = GetItemName(temp[0], temp[1]);
                    sellIn   = int.Parse(temp[2]);
                    quality  = int.Parse(temp[3]);
                }
                else
                {
                    itemName = GetItemName(temp[0]);
                    sellIn   = int.Parse(temp[1]);
                    quality  = int.Parse(temp[2]);
                }
                switch (itemName)
                {
                case "Fresh Item":
                    Item freshItem = new FreshItem {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(freshItem);
                    break;

                case "Frozen Item":
                    Item frozenItem = new FrozenItem {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(frozenItem);
                    break;

                case "Christmas Crackers":
                    Item christmasCrackers = new ChristmasCrackers {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(christmasCrackers);
                    break;

                case "Soap":
                    Item soap = new Soap {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(soap);
                    break;

                case "Aged Brie":
                    Item agedBrie = new AgedBrie {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(agedBrie);
                    break;

                case "INVALID ITEM":
                    Item invalidItem = new InvalidItem {
                        Name = itemName, SellIn = sellIn, Quality = quality
                    };
                    items.Add(invalidItem);
                    break;
                }
            }
            return(items);
        }
Пример #12
0
 public override object GetData() => new { ItemType = InvalidItem.GetType(), Item = InvalidItem, Errors };