예제 #1
0
파일: Tests.cs 프로젝트: ic16b011/oom
        public void FriendplaceEqualsInit()
        {
            var x = new Friends("Test", "Test2");

            Assert.IsTrue(x.Place == "Test2");
        }
예제 #2
0
파일: Tests.cs 프로젝트: ic16b011/oom
        public void FriendnameEqualsInit()
        {
            var x = new Friends("Test", "Test2");

            Assert.IsTrue(x.Name == "Test");
        }
예제 #3
0
        /* main */
        static void Main(string[] args)
        {
            /* Anlegen einiger Objekte */
            var newHobby   = new Hobby("Fußball", "Sportplatz");
            var newHobby2  = new Hobby("Programmieren", "FH");
            var newFriend  = new Friends("Alex", "Wien");
            var newFriend2 = new Friends("Bianca", "Wien");
            int i          = 0;


            /* Ausgabe des Inhalts von newHobby und HobbyYears ändern */
            Console.WriteLine("Hobby Name: " + newHobby.Name);
            Console.WriteLine("Hobby Place: " + newHobby.Place);
            newHobby.UpdateHobbyYears(5);
            newHobby.UpdateHobbyYears(8);


            /* Ändern von Place von newHobby */
            Console.Write("Set new Place: ");
            string newPlace = Console.ReadLine();

            newHobby.SetPlace(newPlace);


            /* IClass Array mit ein paar Objekten anlegen und Place ändern */
            var objects = new IClass[] { newHobby, newHobby2, newFriend, newFriend2 };

            while (i < objects.Count())
            {
                objects[i].SetPlace("Wien_Test");
                i++;
            }


            /* Einstellungen für Json Datei festlegen und Json Datei im aktuellen Directory anlegen mit dem Inhalt des Objekts newFriend */
            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto, Formatting = Formatting.Indented
            };
            string json = JsonConvert.SerializeObject(newFriend, settings);
            var    cwd  = Directory.GetCurrentDirectory();
            var    file = Path.Combine(cwd, "friends.json");

            File.WriteAllText(file, json);


            /* Inhalt der zuvor angelegten Json Datei lesen und auf die Console ausgeben */
            var     jsonread   = File.ReadAllText(file);
            Friends newFriend3 = JsonConvert.DeserializeObject <Friends>(jsonread, settings);

            Console.WriteLine(newFriend.Name + " " + newFriend.Place);
            Console.WriteLine(newFriend3.Name + " " + newFriend3.Place);


            /* Pull Beispiel, neues Hobby anlegen und Place über Subject ändern */
            var producer  = new Subject <string>();
            var newHobby3 = new Hobby("Test", "Test");

            producer.Subscribe(x => newHobby3.SetPlace(x));
            for (i = 0; i < 2; i++)
            {
                Console.Write("New Place Hobby3: ");
                var temp = Console.ReadLine();
                producer.OnNext(temp);
            }


            /* async Task1 */
            Task <bool> result = Task.Run(() => {
                for (int counter = 0; counter < 1000; counter++)
                {
                    if (counter == 999)
                    {
                        return(true);
                    }
                }
                return(false);
            });

            result.ContinueWith(t => Console.WriteLine("Schleife completed"));


            /* async Task2 */
            Task <bool> temp2 = WaitTask();

            temp2.ContinueWith(t => Console.WriteLine("Task Delay done"));


            /* IObservable für linke Pfeiltaste in Windows Form, KeyDown --> wenn Key gedrückt wird */
            var w = new Form();
            IObservable <Keys> moves = Observable.FromEventPattern <KeyEventArgs>(w, "KeyDown")
                                       .Select(u => u.EventArgs.KeyCode);

            var subscription = moves
                               .Where(e => e.Equals(Keys.Left))
                               .Subscribe(e => Console.WriteLine("Key Left pressed"));

            Application.Run(w);


            /* Beenden des Programms */
            Console.WriteLine("Zum Beenden Taste druecken");
            Console.ReadLine();
        }