public void VerseEngineeringEncryptTest()
        {
            ICryptoServiceFactory factory = new CryptoServiceFactory();
            ICryptoService cryptoService = factory.Create();
            DateTime expiryDate = DateTime.Now.AddDays(30);
            VerseEngineeringUser user = new VerseEngineeringUser
                {
                    Name = "Sergiu Ciumac",
                    ProfileId = 1393021216,
                    UserLocale = "en-US",
                    PlayingGames = new List<long>(new long[] { 1, 2, 3 })
                };

            VerseEngineeringToken verseEngineeringToken = new VerseEngineeringToken
                { Expiration = expiryDate.ToBinary(), User = user };

            string cipherText = cryptoService.Encrypt(verseEngineeringToken);
            VerseEngineeringToken decryptedVerseEngineeringToken =
                cryptoService.Decrypt<VerseEngineeringToken>(cipherText);

            Assert.AreEqual(true, !string.IsNullOrEmpty(cipherText));
            Assert.AreEqual(verseEngineeringToken.Expiration, decryptedVerseEngineeringToken.Expiration);
            Assert.IsNotNull(decryptedVerseEngineeringToken.User);
            Assert.AreEqual(verseEngineeringToken.User.Name, decryptedVerseEngineeringToken.User.Name);
            Assert.AreEqual(verseEngineeringToken.User.ProfileId, decryptedVerseEngineeringToken.User.ProfileId);
            Assert.AreEqual(verseEngineeringToken.User.UserLocale, decryptedVerseEngineeringToken.User.UserLocale);
            Assert.IsNotNull(decryptedVerseEngineeringToken.User.PlayingGames);
            Assert.AreEqual(
                verseEngineeringToken.User.PlayingGames.Count, decryptedVerseEngineeringToken.User.PlayingGames.Count);
            foreach (var poemId in verseEngineeringToken.User.PlayingGames)
            {
                Assert.IsTrue(decryptedVerseEngineeringToken.User.PlayingGames.Contains(poemId));
            }
        }
Exemplo n.º 2
0
 public Raw()
 {
     ICryptoServiceFactory factory = new CryptoServiceFactory();
     cryptoService = factory.Create();
 }