public void TestAddRejectsElementFromDifferentGroup() { var otherAlgebraStub = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict); otherAlgebraStub.Setup(alg => alg.IsPotentialElement(It.IsAny <int>())).Returns(true); var otherElement = new CryptoGroupElement <BigInteger, int>(0, otherAlgebraStub.Object); var algebraStub = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict); algebraStub.Setup(alg => alg.IsPotentialElement(It.IsAny <int>())).Returns(true); var element = new CryptoGroupElement <BigInteger, int>(0, algebraStub.Object); Assert.Throws <ArgumentException>( () => element.Add(otherElement) ); }
public void TestAdd() { int otherValue = 3; int value = 7; int expected = value + otherValue; var algebraMock = new Mock <ICryptoGroupAlgebra <BigInteger, int> >(MockBehavior.Strict); algebraMock.Setup(alg => alg.IsPotentialElement(It.IsAny <int>())).Returns(true); algebraMock.Setup(alg => alg.Add(It.IsAny <int>(), It.IsAny <int>())).Returns(expected); var element = new CryptoGroupElement <BigInteger, int>(value, algebraMock.Object); var otherElement = new CryptoGroupElement <BigInteger, int>(otherValue, algebraMock.Object); var result = element.Add(otherElement); var expectedElement = new CryptoGroupElement <BigInteger, int>(expected, algebraMock.Object); Assert.AreEqual(value, element.Value); Assert.AreEqual(otherValue, otherElement.Value); Assert.AreEqual(expectedElement, result); algebraMock.Verify(alg => alg.Add(It.Is <int>(x => x == value), It.Is <int>(x => x == otherValue)), Times.Once()); }