private XDocument GenerateFishTankXml() { if (_tank == null || _tank.GetFishList() == null) { return(null); } XDocument fishTankXDoc = new XDocument( new XElement("FishTank", new XElement("RequiredFoodInGram", _tank.Feed()), new XElement("Fishes") ) ); var fishesXml = fishTankXDoc.Descendants("Fishes").FirstOrDefault(); if (fishesXml != null && _tank.GetFishList() != null) { foreach (var fish in _tank.GetFishList()) { fishesXml.Add(new XElement(nameof(Fish), new XAttribute(nameof(fish.FishType), fish.FishType.ToString()), new XElement(nameof(fish.Name), fish.Name), new XElement(nameof(fish.FoodRequired), fish.FoodRequired) ) ); } } fishTankXDoc.Declaration = new XDeclaration("1.0", "utf-8", "true"); return(fishTankXDoc); }
public void Run() { //tank null kontrol if (_tank != null) { var goldFish = new GoldFish("Gold"); _tank.AddFish(goldFish); var angelFish = new AngelFish("Angel"); _tank.AddFish(angelFish); var babelFish = new BabelFish("Babel"); _tank.AddFish(babelFish); var goldFishNemo = new GoldFish("Nemo"); _tank.AddFish(goldFishNemo); var tankFile = _xmlSaver.Save(); if (!string.IsNullOrEmpty(tankFile)) { Console.WriteLine(tankFile + Environment.NewLine); } foreach (var item in _tank.GetFishList()) { Console.WriteLine($"Fishes in the Tank: {item.Name}"); } } else { Console.WriteLine("Tank is not found!"); } }
public void Should_Return_Fish_Count_1() { var goldFish = new GoldFish("Test Gold Fish"); var actal = _sut.AddFish(goldFish); var count = _sut.GetFishList().Count; Assert.IsTrue(actal); Assert.AreEqual(1, count); }