public void ShouldReturnCorrectData()
        {
            var screen             = Substitute.For <IScreen>();
            var serversDataService = Substitute.For <IServersDataService>();
            var userService        = Substitute.For <IUserService>();

            Server[] servers = new Server[] {
                new Server {
                    Name = "Lithuania", Distance = 50
                },
                new Server {
                    Name = "Latvia", Distance = 150
                }
            };

            serversDataService
            .GetServers(Arg.Any <string>())
            .Returns(servers);

            var model = new ServersViewModel(screen, serversDataService, userService);

            model.LoadServers.Execute().Subscribe();

            model.Servers.Length.Should().Be(2);
        }
Exemple #2
0
        public ServersViewPage()
        {
            InitializeComponent();

            BindingContext = new ServersViewModel();
            var vm = (ServersViewModel)BindingContext;

            CreateBindings(vm);
        }
        public MainWindow()
        {
            _viewModel = new ServersViewModel();

            DataContext = _viewModel;
            InitializeComponent();

            Unloaded += (s, ea) => Dispose();
            Dispatcher.ShutdownStarted += (s, ea) => Dispose();
        }
Exemple #4
0
        public void ShowsServersOnActivate()
        {
            var sut = new ServersViewModel(
                new FakeServers(),
                new EventAggregator());

            sut.As <IActivate>().Activate();

            var server = sut.Servers.Single();

            server.Name.Should().Be("testName");
            server.Distance.Should().Be("100 km");
        }
        public void Setup()
        {
            _accountHelper = new Mock <IAccountHelper>();
            _accountHelper.SetupGet(x => x.Token).Returns(new TokenItem());

            _apiHelper          = new Mock <IAPIHelper>();
            _apiHelper.CallBase = true;
            _apiHelper.Setup(x => x.GetServersList(It.IsAny <string>())).ReturnsAsync(new List <Server>()
            {
                new Server {
                    Name = "name", Distance = 111
                }
            });

            _eventAggregator = new Mock <IEventAggregator>();
            _serversVm       = new ServersViewModel(_apiHelper.Object, _eventAggregator.Object, _accountHelper.Object);
        }
        // TODO: We probably want to create a new viewmodel for each game, also pass in the game?
        // Or should we merge these viewmodels into this one as the more important part is the libraries that are within those viewmodels?
        public GameViewModel(Game game, ServersViewModel serversViewModel, ModsViewModel modsViewModel,
            MissionsViewModel missionsViewModel, Lazy<ContentViewModel> cvmLazy) {
            _game = game;
            _cvmLazy = cvmLazy;
            if (game.SupportsServers())
                Servers = serversViewModel;
            serversViewModel.SwitchGame(game);

            if (game.SupportsMods())
                Mods = modsViewModel;
            modsViewModel.SwitchGame(game);

            if (game.SupportsMissions())
                Missions = missionsViewModel;
            missionsViewModel.SwitchGame(game);

            this.SetCommand(x => ActivateServerList).Subscribe(() => ShowServerList());
            this.SetCommand(x => ActivateMissionList).Subscribe(() => ShowMissionList());
        }
        public void ShouldBeBusyWhenServerDataIsLoading() => new TestScheduler().With(scheduler =>
        {
            // Use NSubstute to generate stubs and mocks.
            var screen             = Substitute.For <IScreen>();
            var serversDataService = Substitute.For <IServersDataService>();
            var userService        = Substitute.For <IUserService>();
            var model = new ServersViewModel(screen, serversDataService, userService);

            // A test needs to subscribe to a ReactiveCommand,
            // because the execution is lazy and won't trigger
            // with no subscribers.
            model.LoadServers.Execute().Subscribe();

            // We advance our scheduler with two ticks.
            // On the first tick, IsExecuting emits a new value,
            // and the second tick invokes IsBusy.
            scheduler.AdvanceBy(2);
            model.IsBusy.Should().BeTrue();

            scheduler.AdvanceBy(4);
            model.IsBusy.Should().BeFalse();
        });
Exemple #8
0
 private void CreateBindings(ServersViewModel vm)
 {
     serversCollection.SetBinding(CollectionView.ItemsSourceProperty, nameof(vm.ServersList));
 }
 public void Init()
 {
     _serverListProviderMock = new Mock <IServerListProvider>();
     _navigatorMock          = new Mock <INavigator>();
     _sut = new ServersViewModel(_navigatorMock.Object, _serverListProviderMock.Object);
 }
 public ExportLifetimeContext <ServerLibraryViewModel> CreateServerLibraryViewModel(Game game,
                                                                                    ServersViewModel serversViewModel) => new ExportLifetimeContext <ServerLibraryViewModel>(
     new ServerLibraryViewModel(game, new Lazy <ServersViewModel>(() => serversViewModel),
                                _contentList,
                                serversViewModel.ServerList, _lm.Value, _dm, _specialDialogManager),
     TaskExt.NullAction);
        public ExportLifetimeContext<ServerLibraryViewModel> CreateServerLibraryViewModel(Game game,
ServersViewModel serversViewModel) => new ExportLifetimeContext<ServerLibraryViewModel>(
        new ServerLibraryViewModel(game, new Lazy<ServersViewModel>(() => serversViewModel),
            _contentList,
            serversViewModel.ServerList, _lm.Value, _dm, _specialDialogManager),
        TaskExt.NullAction);