[ExpectedException(typeof(AbortSendLinkException))] // taken back to mail composer
        public void UseCase_NewInstall_FirstTimeUser_NoPlatformSupport()
        {
            OptionApi.SetString("SendLinkCloudStorageLoginName", "");
            OptionApi.SetString("SendLinkDeviceToken", "");

            // set up user selections
            string password = "******";
            string user = "******";
            LoginForm.AuthenticationType authMethod = LoginForm.AuthenticationType.Register;

            var ui = new Mock<ILoginUserInteraction>();
            ui.Setup(m => m.PromptUserLogin(
                It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                out authMethod,
                out user, out password))
              .Returns(true).Verifiable("User wasn't prompted to log in or register");

            // set up server responses
            _server.NextResponse.Enqueue(MockResponse.sign_ups_Success);
            _server.NextResponse.Enqueue(MockResponse.user_sessions_Unvalidated);

            // call storage links
            try
            {
                StorageLinks storageLinks = new StorageLinks(ui.Object);
                storageLinks.GetLinks("abc", new List<SendLinkInfo>(), new List<string> { "*****@*****.**" }, "subject", new List<IActionProperty>(), _tempDir, "id");
            }
            finally
            {
                ui.VerifySet(m => m.LoginFieldEnabled = true);
                ui.VerifySet(m => m.RegisterTabVisible = true);
                ui.Verify(m => m.ShowRegistrationSteps(It.IsAny<string>()), "Verification steps were not shown");

                var expectedServerCallSequence = new List<RequestPair>
                    {
                        new RequestPair("sign_ups.xml", "POST"),
                        new RequestPair("user_sessions.xml", "POST")
                    };

                CheckServerCalledAsExpected(expectedServerCallSequence);
            }
        }
        public void UseCase_NewInstall_UnvalidatedUser_UserHasNoPassword()
        {
            OptionApi.SetString("SendLinkCloudStorageLoginName", "");
            OptionApi.SetString("SendLinkDeviceToken", "");

            // set up user selections
            string password = "";
            string user = "******";
            LoginForm.AuthenticationType authMethod = LoginForm.AuthenticationType.Login;

            // the login dialog should appear twice
            // first time: login dialog normal
            var ui = new Mock<ILoginUserInteraction>();
            ui.Setup(m => m.PromptUserLogin(
                It.IsAny<string>(), string.Empty, It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                out authMethod,
                out user, out password))
              .Returns(true /*not cancelled*/).Verifiable("User wasn't prompted to log in or register");

            string setpassword = "******";
            string confirmpassword = "******";
            ui.Setup(m => m.PromptPassword(user, password, string.Empty, out setpassword, out confirmpassword))
              .Returns(true /*not cancelled*/).Verifiable("User wasn't prompted to set a new password");

            // set up server responses
            _server.NextResponse.Enqueue(MockResponse.user_sessions_FailureUnvalidatedNoPassword);
            _server.NextResponse.Enqueue(MockResponse.sign_ups_Success);
            _server.NextResponse.Enqueue(MockResponse.user_sessions_SuccessDeviceTokenUnvalidated);
            _server.NextResponse.Enqueue(MockResponse.folders_Success);
            _server.NextResponse.Enqueue(MockResponse.current_user_NotValidated);
            _server.NextResponse.Enqueue(MockResponse.resend_activation);
            _server.NextResponse.Enqueue(MockResponse.members_Success);
            _server.NextResponse.Enqueue(MockResponse.permissions_Success);

            // call storage links
            try
            {
                StorageLinks storageLinks = new StorageLinks(ui.Object);
                storageLinks.GetLinks("abc", new List<SendLinkInfo>(), new List<string> { "*****@*****.**" },
                                      "subject", new List<IActionProperty>(), _tempDir, "id");

            }
            finally
            {
                ui.VerifySet(m => m.LoginFieldEnabled = true);
                ui.VerifySet(m => m.RegisterTabVisible = true);

                var expectedServerCallSequence = new List<RequestPair>
                {
                    new RequestPair("user_sessions.xml", "POST"),
                    new RequestPair("sign_ups.xml", "POST"),
                    new RequestPair("user_sessions.xml", "POST"),
                    new RequestPair("folders.xml", "POST"),
                    new RequestPair("current_user.xml", "GET"),
                    new RequestPair("resend.xml", "POST"),
                    new RequestPair("members.xml", "POST"),
                    new RequestPair("permissions.xml", "PUT"),
                };

                CheckServerCalledAsExpected(expectedServerCallSequence);
            }
        }
        [ExpectedException(typeof(AbortSendLinkException))] // taken back to mail composer
        public void UseCase_NewInstall_UnvalidatedUser_FirstLogin_NoPlatformSupport()
        {
            OptionApi.SetString("SendLinkCloudStorageLoginName", "");
            OptionApi.SetString("SendLinkDeviceToken", "");

            // set up user selections
            string password = "******";
            string user = "******";
            LoginForm.AuthenticationType authMethod = LoginForm.AuthenticationType.Login;

            // the login dialog should appear twice
            // first time: login dialog normal
            var ui = new Mock<ILoginUserInteraction>();
            ui.Setup(m => m.PromptUserLogin(
                It.IsAny<string>(), string.Empty, It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                out authMethod,
                out user, out password))
              .Returns(true /*not cancelled*/).Verifiable("User wasn't prompted to log in or register");

            // second time: login dialog shows "Can't log in"
            ui.Setup(m => m.PromptUserLogin(
                It.IsAny<string>(), "Unrecognised login details", It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                out authMethod,
                out user, out password))
              .Returns(false /*cancelled*/).Verifiable("Error message wasn't shown");

            // set up server responses
            _server.NextResponse.Enqueue(MockResponse.user_sessions_Unvalidated);

            // call storage links
            try
            {

                StorageLinks storageLinks = new StorageLinks(ui.Object);
                storageLinks.GetLinks("abc", new List<SendLinkInfo>(), new List<string> { "*****@*****.**" },
                                      "subject", new List<IActionProperty>(), _tempDir, "id");

            }
            finally
            {
                ui.VerifySet(m => m.LoginFieldEnabled = true);
                ui.VerifySet(m => m.RegisterTabVisible = true);

                var expectedServerCallSequence = new List<RequestPair>
                {
                    new RequestPair("user_sessions.xml", "POST"),
                };

                CheckServerCalledAsExpected(expectedServerCallSequence);
            }
        }
        public void UseCase_NewInstall_UnvalidatedUser_SecondLogin_PlatformSupport()
        {
            OptionApi.SetString("SendLinkCloudStorageLoginName", "*****@*****.**");
            OptionApi.SetEncrypted("SendLinkDeviceToken", "devicetoken", _entropy);


            // set up user selections
            var ui = new Mock<ILoginUserInteraction>();
            // set up server responses
            _server.NextResponse.Enqueue(MockResponse.current_user_NotValidated);
            _server.NextResponse.Enqueue(MockResponse.folders_Success);
            _server.NextResponse.Enqueue(MockResponse.resend_activation);
            _server.NextResponse.Enqueue(MockResponse.members_Success);
            _server.NextResponse.Enqueue(MockResponse.permissions_Success);

            // call storage links
            try
            {

                StorageLinks storageLinks = new StorageLinks(ui.Object);
                storageLinks.GetLinks("abc", new List<SendLinkInfo>(), new List<string> { "*****@*****.**" },
                                      "subject", new List<IActionProperty>(), _tempDir, "id");

            }
            finally
            {
                ui.VerifySet(m => m.LoginFieldEnabled = true);
                ui.VerifySet(m => m.RegisterTabVisible = true);
                // never show login dialog
                string user;
                string password;
                LoginForm.AuthenticationType authMethod = LoginForm.AuthenticationType.Login;
                ui.Verify(m => m.PromptUserLogin(
                    It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                    out authMethod,
                    out user, out password), Times.Never());

                var expectedServerCallSequence = new List<RequestPair>
                {
                    new RequestPair("current_user.xml", "GET"),
                    new RequestPair("folders.xml", "POST"),
                    new RequestPair("resend.xml", "POST"),
                    new RequestPair("members.xml", "POST"),
                    new RequestPair("permissions.xml", "PUT"),
                };

                CheckServerCalledAsExpected(expectedServerCallSequence);
            }
        }
        public void UseCase_NewInstall_ValidatedUser_FirstLogin()
        {
            OptionApi.SetString("SendLinkCloudStorageLoginName", "");
            OptionApi.SetString("SendLinkDeviceToken", "");

            // set up user selections
            string password = "******";
            string user = "******";
            LoginForm.AuthenticationType authMethod = LoginForm.AuthenticationType.Login;

            var ui = new Mock<ILoginUserInteraction>();
            ui.Setup(m => m.PromptUserLogin(
                It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<LoginForm.AuthenticationType>(),
                out authMethod,
                out user, out password))
              .Returns(true).Verifiable("User wasn't prompted to log in or register");

            // set up server responses
            _server.NextResponse.Enqueue(MockResponse.user_sessions_SuccessDeviceTokenValidated);
            _server.NextResponse.Enqueue(MockResponse.current_user_Validated);
            _server.NextResponse.Enqueue(MockResponse.folders_Success);
            _server.NextResponse.Enqueue(MockResponse.members_Success);
            _server.NextResponse.Enqueue(MockResponse.permissions_Success);

            // call storage links
            StorageLinks storageLinks = new StorageLinks(ui.Object);
            storageLinks.GetLinks("abc", new List<SendLinkInfo>(), new List<string> { "*****@*****.**" }, "subject", new List<IActionProperty>(), _tempDir, "id");
            ui.VerifySet(m => m.LoginFieldEnabled = true);
            ui.VerifySet(m => m.RegisterTabVisible = true);

            var expectedServerCallSequence = new List<RequestPair>
                {
                    new RequestPair("user_sessions.xml", "POST"),
                    new RequestPair("current_user.xml", "GET"),
                    new RequestPair("folders.xml", "POST"),
                    new RequestPair("members.xml", "POST"),
                    new RequestPair("permissions.xml", "PUT"),
                };

            CheckServerCalledAsExpected(expectedServerCallSequence);
        }