public void CryptoBinFormatsToStream() { var test = _testEntities[0] as MockClassC; var bson = TestResourceFactory.CreateBsonFormatter(); var crypto = new CryptoFormatter(TestResourceFactory.CreateCrypto(), bson, _keys); var stream = bson.FormatObjStream(test); var encrypted = crypto.Format(stream); var buffer = crypto.Unformat(encrypted); var unencrypted = bson.UnformatObj<MockClassA>(buffer) as MockClassC; Assert.AreEqual(unencrypted.Id, test.Id); Assert.AreEqual(unencrypted.Name, test.Name); Assert.AreEqual(unencrypted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]); Assert.AreEqual(unencrypted.Location.X, test.Location.X); Assert.AreEqual(unencrypted.Location.Y, test.Location.Y); Assert.AreEqual(unencrypted.Location.Z, test.Location.Z); Assert.AreEqual(unencrypted.Location.W, test.Location.W); Assert.AreEqual(unencrypted.ReferenceCode, test.ReferenceCode); Assert.AreEqual(unencrypted.ReplicationID, test.ReplicationID); }
public void CryptoSafeFormatsToStream() { var test = _testEntities[0] as MockClassC; var bson = TestResourceFactory.CreateBsonFormatter(); var crypto = new CryptoFormatter(TestResourceFactory.CreateCrypto(), bson, _keys); Stream encrypted; Assert.IsTrue(crypto.TryFormatObj(test, out encrypted)); MockClassA raw; Assert.IsTrue(crypto.TryUnformatObj<MockClassA>(encrypted, out raw)); var unencrypted = raw as MockClassC; Assert.AreEqual(unencrypted.Id, test.Id); Assert.AreEqual(unencrypted.Name, test.Name); Assert.AreEqual(unencrypted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]); Assert.AreEqual(unencrypted.Location.X, test.Location.X); Assert.AreEqual(unencrypted.Location.Y, test.Location.Y); Assert.AreEqual(unencrypted.Location.Z, test.Location.Z); Assert.AreEqual(unencrypted.Location.W, test.Location.W); Assert.AreEqual(unencrypted.ReferenceCode, test.ReferenceCode); Assert.AreEqual(unencrypted.ReplicationID, test.ReplicationID); Assert.IsFalse(crypto.TryFormatObj(default(MockClassA), out encrypted)); Assert.IsFalse(crypto.TryUnformatObj(new MemoryStream(), out raw)); }