Ejemplo n.º 1
0
        public void Test_Encrypt_Ballot_Simple_Succeeds()
        {
            // Configure the election context
            var keypair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
            var description = new Manifest(manifest_json);
            var manifest = new InternalManifest(description);
            var context = new CiphertextElectionContext(
                1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);
            var device = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location");
            var mediator = new EncryptionMediator(manifest, context, device);

            var ballot = new PlaintextBallot(plaintext_json);

            // Act
            var ciphertext = mediator.Encrypt(ballot);

            // Assert
            
            // a property
            Assert.That(ciphertext.ObjectId == ballot.ObjectId);

            // json serialization
            var json = ciphertext.Json;
            var fromJson = new CiphertextBallot(json);
            Assert.That(ciphertext.ObjectId == fromJson.ObjectId);

            // binary serialization
            var bson = ciphertext.Bson;
            var fromBson = CiphertextBallot.FromBson(bson);
            Assert.That(ciphertext.ObjectId == fromBson.ObjectId);

            // submitted ballot
            var submitted = SubmittedBallot.From(ciphertext, BallotBoxState.cast);
            Assert.That(ciphertext.ObjectId == submitted.ObjectId);
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            var encryption = new Mock <IFakeSingnal>();

            encryption.Setup(_ => _.FakeSignalCall());


            EncryptionMediator mediator = new EncryptionMediator(encryption.Object);

            mediator.DecryptFile("", "");

            encryption.Verify(_ => _.FakeSignalCall(), Times.Once());
        }
Ejemplo n.º 3
0
        public void TestMethod2()
        {
            var encryption = new Mock <IFakeSingnal>();

            encryption.Setup(_ => _.FakeSignalCall());



            EncryptionMediator mediator = new EncryptionMediator(encryption.Object);

            //mediator.DecryptFile("", "");
            mediator.ReadBson("", "", "");

            encryption.Verify(_ => _.FakeSignalCall(), Times.Exactly(2));
        }
Ejemplo n.º 4
0
        public void Test_Compact_Encrypt_Ballot_Simple_Succeeds()
        {
            var keypair     = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
            var description = new Manifest(jsonManifest);
            var manifest    = new InternalManifest(description);
            var context     = new CiphertextElectionContext(1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);
            var device      = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location");
            var mediator    = new EncryptionMediator(manifest, context, device);

            var ballot = new PlaintextBallot(plaintext);

            // Act
            var compact = mediator.CompactEncrypt(ballot);

            // Assert
            Assert.That(compact.ObjectId == ballot.ObjectId);

            var msgpack     = compact.ToMsgPack();
            var fromMsgpack = new CompactCiphertextBallot(msgpack);

            Assert.That(compact.ObjectId == fromMsgpack.ObjectId);
        }
Ejemplo n.º 5
0
        public void TestMethod2()
        {
            bool flag            = true;
            var  fakeSingnalMock = new Mock <FakeSingalFactory>();

            fakeSingnalMock.SetupAllProperties();
            //fakeSingnalMock.Setup(_ => _.EncryptionMethod.IsFakeSingnal).Callback<bool>(value => flag = value).Returns(flag);
            fakeSingnalMock.Setup(_ => _.EncryptionMethod.FakeSignal(It.IsAny <Exception>()));
            fakeSingnalMock.Setup(_ => _.BsonMethod.FakeSignal(It.IsAny <Exception>()));



            EncryptionMediator mediator = new EncryptionMediator(fakeSingnalMock.Object);

            Action empty = () => { mediator.ReadBson("", "", ""); };

            empty.Invoke();

            //fakeSingnalMock.Verify(_ => _.EncryptionMethod.FakeSignal(It.IsAny<Exception>()), Times.AtLeastOnce);
            //fakeSingnalMock.Verify(_ => _.BsonMethod.FakeSignal(It.IsAny<Exception>()), Times.AtLeastOnce);


            Xunit.Assert.ThrowsAny <Exception>(empty);
        }