public void IsLastDraw_ChecksIfItDeterminesLastDraw_Determines()
        {
            CardDTO card1 = new CardDTO(SymbolsDTO.DIAMONDS, 9);
            CardDTO card2 = new CardDTO(SymbolsDTO.HEARTS, 2);

            ActiveCardDTO activeDTO = new ActiveCardDTO(card1, card2);

            Assert.IsFalse(activeDTO.IsLastDraw());

            activeDTO.HumanCard = null;

            Assert.IsTrue(activeDTO.IsLastDraw());

            activeDTO.HumanCard = new CardDTO(SymbolsDTO.HEARTS, 5);

            Assert.IsFalse(activeDTO.IsLastDraw());

            activeDTO.ComputerCard = null;

            Assert.IsTrue(activeDTO.IsLastDraw());

            activeDTO.ComputerCard = new CardDTO(SymbolsDTO.DIAMONDS, 10);

            Assert.IsFalse(activeDTO.IsLastDraw());

            activeDTO.HumanCard = null;
            activeDTO.ComputerCard = null;

            Assert.IsTrue(activeDTO.IsLastDraw());
        }
        public static CardDTO GetCardDTO(Card card)
        {
            CardDTO dto = new CardDTO()
                          	{
                                    Number = card.Number,
                                    Symbol = (SymbolsDTO)((int)card.Symbol)
                          	};

            return dto;
        }
Example #3
0
        public void SerializeAndDeserialize_ChecksIfObjectStateIsSavedCorrectly_Saved()
        {
            CardDTO card = new CardDTO(SymbolsDTO.DIAMONDS, 12);

            XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDTO));

            TextWriter WriteFileStream = new StreamWriter("_cardDTO.xml");
            SerializerObj.Serialize(WriteFileStream, card);
            WriteFileStream.Close();

            FileStream ReadFileStream = new FileStream("_cardDTO.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
            CardDTO gotCard = (CardDTO)SerializerObj.Deserialize(ReadFileStream);
            ReadFileStream.Close();

            Assert.AreEqual(card.Number, gotCard.Number);
            Assert.AreEqual(card.Symbol, gotCard.Symbol);
        }
Example #4
0
        public override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!IsDisposed)
                {
                    if (_humanCard != null)
                    {
                        _humanCard.Dispose();
                        _humanCard = null;
                    }

                    if (_computerCard != null)
                    {
                        _computerCard.Dispose();
                        _computerCard = null;
                    }
                }
            }
            base.Dispose(disposing);
        }
        public void SerializeAndDeserialize_ChecksIfObjectStateIsSavedCorrectly_Saved()
        {
            CardDTO card1 = new CardDTO(SymbolsDTO.DIAMONDS, 12);
            CardDTO card2 = new CardDTO(SymbolsDTO.HEARTS, 10);

            ActiveCardDTO activeDTO = new ActiveCardDTO(card1, card2);

            XmlSerializer SerializerObj = new XmlSerializer(typeof(ActiveCardDTO));

            TextWriter WriteFileStream = new StreamWriter("_activeCardDTO.xml");
            SerializerObj.Serialize(WriteFileStream, activeDTO);
            WriteFileStream.Close();

            FileStream ReadFileStream = new FileStream("_activeCardDTO.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
            ActiveCardDTO gotCard = (ActiveCardDTO)SerializerObj.Deserialize(ReadFileStream);
            ReadFileStream.Close();

            Assert.AreEqual(activeDTO.ComputerCard.Number, gotCard.ComputerCard.Number);
            Assert.AreEqual(activeDTO.ComputerCard.Symbol, gotCard.ComputerCard.Symbol);
            Assert.AreEqual(activeDTO.HumanCard.Number, gotCard.HumanCard.Number);
            Assert.AreEqual(activeDTO.HumanCard.Symbol, gotCard.HumanCard.Symbol);
        }
Example #6
0
 public ActiveCardDTO(CardDTO humanCard, CardDTO computerCard)
 {
     HumanCard = humanCard;
     ComputerCard = computerCard;
 }