コード例 #1
0
        public void deserialize_a_balista()
        {
            Arena arena = new Arena();
            Team  team  = arena.CreateTeam("blue");

            Balista sut = new Balista(arena, team, 1);

            team.Units.Add(sut.Name, sut);
            team.Acount++;

            string fileName = Path.GetTempFileName();

            {
                JToken token = sut.Serialize();
                using (FileStream fs = File.OpenWrite(fileName))
                    using (StreamWriter sw = new StreamWriter(fs))
                        using (JsonTextWriter jw = new JsonTextWriter(sw))
                        {
                            token.WriteTo(jw);
                        }
            }

            {
                using (FileStream fs = File.OpenRead(fileName))
                    using (StreamReader sr = new StreamReader(fs))
                        using (JsonTextReader jr = new JsonTextReader(sr))
                        {
                            JToken  token  = JToken.ReadFrom(jr);
                            Balista result = new Balista(arena, team, token);

                            Assert.That(arena.TeamCount, Is.EqualTo(1));
                            Assert.That(team.UnitCount, Is.EqualTo(1));
                            Assert.That(team.Acount, Is.EqualTo(1));

                            Assert.That(sut.Arena, Is.EqualTo(arena));
                            Assert.That(result.Arena, Is.EqualTo(arena));

                            Assert.That(sut.Team, Is.EqualTo(team));
                            Assert.That(result.Team, Is.EqualTo(team));

                            Assert.That(sut.Life == 25.0 && sut.Speed == 0.7);
                            Assert.That(result.Life == 25.0 && result.Speed == 0.7);

                            Assert.That(sut.Team, Is.EqualTo(result.Team));
                        }
            }
        }
コード例 #2
0
        public void deserialize_a_balista()
        {
            Arena arena = new Arena();
            Team  team  = arena.CreateTeam("blue");

            Balista sut = new Balista(arena, team, 1);

            string fileName = Path.GetTempFileName();

            {
                JToken jToken = sut.Serialize();
                using (FileStream fs = File.OpenWrite(fileName))
                    using (StreamWriter sw = new StreamWriter(fs))
                        using (JsonTextWriter jw = new JsonTextWriter(sw))
                        {
                            jToken.WriteTo(jw);
                        }
            }

            {
                using (FileStream fs = File.OpenRead(fileName))
                    using (StreamReader sr = new StreamReader(fs))
                        using (JsonTextReader jr = new JsonTextReader(sr))
                        {
                            JToken  jToken   = JToken.ReadFrom(jr);
                            Balista balista  = new Balista(arena, team, jToken);
                            Balista balista1 = new Balista(arena, team, 22);

                            Assert.That(balista.Life, Is.EqualTo(25.0));
                            Assert.That(balista.Troop, Is.EqualTo("balista"));
                            Assert.That(balista.Equals(balista1), Is.False);
                            Assert.That(balista.Name, Is.EqualTo(1));
                            Assert.That(balista.Name, Is.Not.EqualTo(balista1.Name));
                        }
            }
        }