예제 #1
0
        public void TestNegateRejectsDifferentGroupElement()
        {
            var algebraStub = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict);
            var group       = new CryptoGroup <BigInteger, int>(algebraStub.Object);

            var otherAlgebra = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict);

            otherAlgebra.Setup(algebra => algebra.IsPotentialElement(It.IsAny <int>())).Returns(true);
            var element = new CryptoGroupElement <BigInteger, int>(3, otherAlgebra.Object);

            Assert.Throws <ArgumentException>(
                () => group.Negate(element)
                );
        }
예제 #2
0
        public void TestSpecificNegateCallsAlgebra()
        {
            int expectedRaw = 3;
            int elementRaw  = 8;

            var algebraMock = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict);

            algebraMock.Setup(algebra => algebra.IsPotentialElement(It.IsAny <int>())).Returns(true);
            algebraMock.Setup(algebra => algebra.Negate(It.IsAny <int>())).Returns(expectedRaw);

            var groupMock = new CryptoGroup <BigInteger, int>(algebraMock.Object);
            var expected  = new CryptoGroupElement <BigInteger, int>(expectedRaw, algebraMock.Object);
            var element   = new CryptoGroupElement <BigInteger, int>(elementRaw, algebraMock.Object);

            Assert.AreEqual(expected, groupMock.Negate(element));

            algebraMock.Verify(
                algebra => algebra.Negate(It.Is <int>(x => x == elementRaw)),
                Times.Once()
                );
        }