public async Task On_disconnect_and_if_logged_in_resume_old_session()
        {
            var loginOption = Substitute.For <ILoginOption>();
            var loginResult = AutoFixture.Build <MethodResult <LoginResult> >()
                              .With(x => x.Error, null)
                              .Create();

            _driverMock.LoginAsync(loginOption).Returns(Task.FromResult(loginResult));

            var resumeResult = AutoFixture.Build <MethodResult <LoginResult> >()
                               .With(x => x.Error, null)
                               .Create();

            _driverMock.LoginResumeAsync(loginResult.Result.Token)
            .Returns(Task.FromResult(resumeResult));

            var bot = new RocketChatBot(_driverMock, _loggerMock);
            await bot.LoginAsync(loginOption);

            // Act
            _driverMock.DdpReconnect += Raise.Event <DdpReconnect>();
            Thread.Sleep(200);

            // Assert
            await _driverMock.Received().LoginResumeAsync(Arg.Any <string>());
        }
        public async Task On_unsuccessful_resume_throw()
        {
            var loginOption = Substitute.For <ILoginOption>();
            var loginResult = AutoFixture.Build <MethodResult <LoginResult> >()
                              .With(x => x.Error, null)
                              .Create();

            _driverMock.LoginAsync(loginOption).Returns(Task.FromResult(loginResult));

            var resumeResult = AutoFixture.Build <MethodResult <LoginResult> >()
                               .Create();

            _driverMock.LoginResumeAsync(loginResult.Result.Token)
            .Returns(Task.FromResult(resumeResult));

            var bot = new RocketChatBot(_driverMock, _loggerMock);

            // Act
            await bot.LoginAsync(loginOption);

            Action resumeAction = () => bot.ResumeAsync().Wait();

            // Assert
            resumeAction.ShouldThrow <Exception>();
        }
Esempio n. 3
0
        private static async Task MainAsync()
        {
            const string username        = "******";
            const string password        = "******";
            const string rocketServerUrl = "dev0:3000"; // just the host and port
            const bool   useSsl          = false;       // Basically use ws or wss.

            // Create the bot - an abstraction of the driver
            RocketChatBot bot = new RocketChatBot(rocketServerUrl, useSsl);

            // Connect to Rocket.Chat
            await bot.ConnectAsync();

            // Login
            ILoginOption loginOption = new EmailLoginOption
            {
                Email    = username,
                Password = password
            };
            await bot.LoginAsync(loginOption);

            // Start listening for messages
            await bot.SubscribeAsync();

            // Add possible responses to be checked in order
            // This is not thead safe, FYI
            IBotResponse giphyResponse = new GiphyResponse();

            bot.AddResponse(giphyResponse);

            // And that's it
            // Checkout GiphyResponse in the example project for more info.
        }
Esempio n. 4
0
        private static async Task MainAsync()
        {
            const string username = "******";
            const string password = "******";
            const string rocketServerUrl = "dev0:3000"; // just the host and port
            const bool useSsl = false; // Basically use ws or wss.
            
            // Create the bot - an abstraction of the driver
            RocketChatBot bot = new RocketChatBot(rocketServerUrl, useSsl);

            // Connect to Rocket.Chat
            await bot.ConnectAsync();

            // Login
            ILoginOption loginOption = new EmailLoginOption
            {
                Email = username,
                Password = password
            };
            await bot.LoginAsync(loginOption);

            // Start listening for messages
            await bot.SubscribeAsync();

            // Add possible responses to be checked in order
            // This is not thead safe, FYI 
            IBotResponse giphyResponse = new GiphyResponse();
            bot.AddResponse(giphyResponse);

            // And that's it
            // Checkout GiphyResponse in the example project for more info.
        }
Esempio n. 5
0
        private static async void StartBot(ILoginOption option)
        {
            await bot.ConnectAsync();

            await bot.LoginAsync(option);

            await bot.SubscribeAsync(() => new DirectResponseMessage(), () => new DirectResponseMessage());
        }
        public void On_unsuccessful_login_throw()
        {
            var loginOption = Substitute.For <ILoginOption>();
            var loginResult = AutoFixture.Create <MethodResult <LoginResult> >();

            _driverMock.LoginAsync(loginOption).Returns(Task.FromResult(loginResult));

            var bot = new RocketChatBot(_driverMock, _loggerMock);

            // Act
            Action loginAction = () => bot.LoginAsync(loginOption).Wait();

            // Assert
            var exception = loginAction.ShouldThrow <Exception>().And;

            exception.Message.Should().Contain(loginResult.Error.Message);
        }
        public async Task On_successful_login_set_login_token()
        {
            var loginOption = Substitute.For <ILoginOption>();
            var loginResult = AutoFixture.Build <MethodResult <LoginResult> >()
                              .With(x => x.Error, null)
                              .Create();

            _driverMock.LoginAsync(loginOption).Returns(Task.FromResult(loginResult));

            var bot = new RocketChatBot(_driverMock, _loggerMock);

            // Act
            await bot.LoginAsync(loginOption);

            // Assert
            bot.LoginToken.Should().Be(loginResult.Result.Token);
        }