public void ChooseImageTest()
        {
            var command = Substitute.For <CreateNewDropletCommand>(_logger, _tg, _sessionRepo, _handlerCallbackRepo, _pageFactory, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.WaitInputNameDroplet);

            command.Received().Execute(_message, SessionState.WaitInputNameDroplet);
            var doApi = _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));

            doApi.Images.Received().GetAll(Requests.ImageType.Distribution);
            _sessionRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new Session()));
            _pageFactory.Received().GetInstance <ImagePage>().Received().GetPage(Arg.Is <int>(i => i == 100), Arg.Any <int>());
            _tg.SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>(), ParseMode.Markdown, replyMarkup: Arg.Any <InlineKeyboardMarkup>());
            _handlerCallbackRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new HandlerCallback()));
        }
Exemplo n.º 2
0
        public void GetDropletsTest()
        {
            var command = Substitute.For <GetDropletsCommand>(_logger, _tg, _sessionRepo, _handlerCallbackRepo, _pageFactory, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.MainMenu);

            command.Received().Execute(_message, SessionState.MainMenu);
            var doApi = _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));

            doApi.Droplets.Received().GetAll();
            _pageFactory
            .Received().GetInstance <DropletPage>()
            .Received().GetPage(Arg.Is <int>(i => i == 100), Arg.Any <int>());
            _sessionRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new Session()));
            _handlerCallbackRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new HandlerCallback()));
            _tg.Received().SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>(), ParseMode.Markdown, replyMarkup: Arg.Any <InlineKeyboardMarkup>());
        }
        public void AddInboundRuleTest()
        {
            _message.Text = "tcp:80:0.0.0.0/0";
            var command = Substitute.For <AddInboundRuleCommand>(_logger, _tg, _sessionRepo, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.WaitInputAddInboundRuleFirewall);

            command.Received().Execute(_message, SessionState.WaitInputAddInboundRuleFirewall);
            _sessionRepo.Received().Get(Arg.Is <int>(i => i == 100));
            _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));
            _tg.Received().SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>());
        }
        public void GetAccountTest()
        {
            var command = Substitute.For <GetAccountCommand>(_logger, _tg, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.MainMenu);

            command.Received().Execute(_message, SessionState.MainMenu);
            var doApi = _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));

            doApi.Account.Received().Get();
            doApi.BalanceClient.Received().Get();
            _tg.Received().SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>(), ParseMode.Markdown);
        }
        public void PowerOnDropletTest()
        {
            var command = Substitute.For <PowerOnDropletCommand>(_logger, _tg, _sessionRepo, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.SelectedDroplet);

            command.Received().Execute(_message, SessionState.SelectedDroplet);
            var doApi = _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));

            _sessionRepo.Received().Get(Arg.Is <int>(i => i == 100));
            doApi.DropletActions.Received().PowerOn(Arg.Is <int>(i => i == 1000));
            doApi.DropletActions.Received().GetDropletAction(Arg.Is <int>(i => i == 1000), Arg.Is <int>(i => i == 200));
            _tg.Received().SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>());
            _sessionRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new Session()));
        }
        public void ShutdownDropletTest_AnswerYes()
        {
            _message.Text = "Yes";
            var command = Substitute.For <ShutdownDropletCommand>(_logger, _tg, _sessionRepo, _digitalOceanClientFactory);

            command.Execute(_message, SessionState.WaitConfirmShutdown);

            command.Received().Execute(_message, SessionState.WaitConfirmShutdown);
            var doApi = _digitalOceanClientFactory.Received().GetInstance(Arg.Is <int>(i => i == 100));

            _sessionRepo.Received().Get(Arg.Is <int>(i => i == 100));
            doApi.DropletActions.Received().Shutdown(Arg.Is <int>(i => i == 1000));
            doApi.DropletActions.Received().GetDropletAction(Arg.Is <int>(i => i == 1000), Arg.Is <int>(i => i == 200));
            _tg.Received().SendTextMessageAsync(Arg.Is <ChatId>(i => i.Identifier == 101), Arg.Any <string>());
            _sessionRepo.Received().Update(Arg.Is <int>(i => i == 100), Arg.Invoke(new Session()));
        }