public void CheckUserKeyPairPassword_Fail() { // ARRANGE IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => a.GetAndCheckUserKeyPair()).Throws(new DracoonCryptoException()).Occurs(1); // ACT - ASSERT Assert.Throws <DracoonCryptoException>(() => a.CheckUserKeyPairPassword()); Mock.Assert(a); Mock.Assert(c.Executor); }
public void CheckUserKeyPairPassword_WrongPassword() { // ARRANGE bool expected = false; IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => a.GetAndCheckUserKeyPair()).Throws(new DracoonCryptoException(DracoonCryptoCode.INVALID_PASSWORD_ERROR)).Occurs(1); // ACT bool actual = a.CheckUserKeyPairPassword(); // ASSERT Assert.Equal(expected, actual); Mock.Assert(a); Mock.Assert(c.Executor); }
public void CheckUserKeyPairPassword_Success() { // ARRANGE bool expected = true; IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => a.GetAndCheckUserKeyPair()).Returns(FactoryUser.UserKeyPair).Occurs(1); // ACT bool actual = a.CheckUserKeyPairPassword(); // ASSERT Assert.Equal(expected, actual); Mock.Assert(a); Mock.Assert(c.Executor); }
public void GetAndCheckUserKeyPair_WrongPassword() { // ARRANGE int expected = DracoonCryptoCode.INVALID_PASSWORD_ERROR.Code; IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => c.Builder.GetUserKeyPair()).Returns(FactoryRestSharp.GetUserKeyPairMock()); Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUserKeyPair>(Arg.IsAny <IRestRequest>(), RequestType.GetUserKeyPair, 0)) .Returns(FactoryUser.ApiUserKeyPair); Mock.Arrange(() => Crypto.Sdk.Crypto.CheckUserKeyPair(Arg.IsAny <UserKeyPair>(), Arg.AnyString)).Returns(false); try { // ACT a.GetAndCheckUserKeyPair(); } catch (DracoonCryptoException e) { // ASSERT Assert.Equal(expected, e.ErrorCode.Code); } }
public void GetAndCheckUserKeyPair_Fail() { // ARRANGE IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => c.Builder.GetUserKeyPair()).Returns(FactoryRestSharp.GetUserKeyPairMock()); Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUserKeyPair>(Arg.IsAny <IRestRequest>(), RequestType.GetUserKeyPair, 0)) .Returns(FactoryUser.ApiUserKeyPair); Mock.Arrange(() => Crypto.Sdk.Crypto.CheckUserKeyPair(Arg.IsAny <UserKeyPair>(), Arg.AnyString)).Throws(new CryptoException()); Mock.Arrange(() => CryptoErrorMapper.ParseCause(Arg.IsAny <Exception>())).Returns(DracoonCryptoCode.UNKNOWN_ERROR).Occurs(1); try { // ACT a.GetAndCheckUserKeyPair(); } catch (DracoonCryptoException e) { // ASSERT Assert.NotEqual(DracoonCryptoCode.INVALID_PASSWORD_ERROR.Code, e.ErrorCode.Code); Mock.Assert(() => CryptoErrorMapper.ParseCause(Arg.IsAny <Exception>())); } }
public void GetAndCheckUserKeyPair_Success() { // ARRANGE UserKeyPair expected = FactoryUser.UserKeyPair; IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(false); DracoonAccountImpl a = new DracoonAccountImpl(c); Mock.Arrange(() => c.Builder.GetUserKeyPair()).Returns(FactoryRestSharp.GetUserKeyPairMock()).Occurs(1); Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUserKeyPair>(Arg.IsAny <IRestRequest>(), RequestType.GetUserKeyPair, 0)) .Returns(FactoryUser.ApiUserKeyPair).Occurs(1); Mock.Arrange(() => UserMapper.FromApiUserKeyPair(Arg.IsAny <ApiUserKeyPair>())).Returns(FactoryUser.UserKeyPair).Occurs(1); Mock.Arrange(() => Crypto.Sdk.Crypto.CheckUserKeyPair(Arg.IsAny <UserKeyPair>(), Arg.AnyString)).Returns(true).Occurs(1); // ACT UserKeyPair actual = a.GetAndCheckUserKeyPair(); // ASSERT Assert.Equal(expected, actual, new UserKeyPairComparer()); Mock.Assert(() => UserMapper.FromApiUserKeyPair(Arg.IsAny <ApiUserKeyPair>())); Mock.Assert(() => Crypto.Sdk.Crypto.CheckUserKeyPair(Arg.IsAny <UserKeyPair>(), Arg.AnyString)); Mock.Assert(c.Builder); Mock.Assert(c.Executor); }