Пример #1
0
        public async void GetAuthStatus_Tests(BitwardenStatus status)
        {
            var    mock             = new Mock <IAuthService>();
            string authStatusOutput = AuthStatusHelper.GetAuthStatusOutputByBitwardenStatus(status);
            var    t = CreateCommandResultTaskFromOutput(authStatusOutput);

            mock.Setup(service => service.GetAuthStatus()).Returns(t);

            var authHandler = new BitwardenAuthHandler(mock.Object);
            var authStatus  = await authHandler.GetAuthStatus();

            var expectedAuthStatus = AuthStatusHelper.GetAuthStatusByBitwardenStatus(status);

            Assert.Equal(status, authStatus.Status);
            Assert.Equal(expectedAuthStatus.UserEmail, authStatus.UserEmail);
            Assert.Equal(expectedAuthStatus.UserId, authStatus.UserId);
        }
        public async void LoginByAuthStatus_Logout_Test(string loginResponse, string unlockResponse,
                                                        string authStatusResponse, bool expectedSuccess, string expectedErrorMessage)
        {
            var authStatus     = AuthStatusHelper.GetAuthStatusByBitwardenStatus(BitwardenStatus.Logout);
            var mock           = new Mock <IAuthService>();
            var loginTask      = CreateCommandResultTaskFromOutput(loginResponse);
            var unlockTask     = CreateCommandResultTaskFromOutput(unlockResponse);
            var authStatusTask = CreateCommandResultTaskFromOutput(authStatusResponse);

            mock.Setup(service => service.Login(Email, PASSWORD)).Returns(loginTask);
            mock.Setup(service => service.Unlock(PASSWORD)).Returns(unlockTask);
            mock.Setup(service => service.GetAuthStatus()).Returns(authStatusTask);

            var authHandler = new BitwardenAuthHandler(mock.Object);
            var loginResult = await authHandler.LoginByAuthStatus(authStatus, Email, PASSWORD);

            Assert.Equal(expectedSuccess, loginResult.IsLoggedIn);
            Assert.Equal(expectedErrorMessage, loginResult.ErrorMessage);
        }