Exemple #1
0
        public void LoadCommand_populates_Items_from_api()
        {
            var batman   = new SuperheroListDTO();
            var superman = new SuperheroListDTO();
            var heroes   = new[] { batman, superman };

            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();

            var client = new Mock <IRestClient>();

            client.Setup(s => s.GetAllAsync <SuperheroListDTO>("superheroes")).ReturnsAsync((HttpStatusCode.OK, heroes));

            var service = new Mock <IAuthenticationService>();
            var dialog  = new Mock <IDialogService>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object, service.Object, dialog.Object);

            vm.LoadCommand.Execute(null);

            Assert.Collection(vm.Items,
                              a => Assert.Equal(a, batman),
                              a => Assert.Equal(a, superman)
                              );

            // Ensure not busy when command finished
            Assert.False(vm.IsBusy);
        }
        public void Ctor_subscribes_to_SuperheroDetailsPage()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object);

            messaging.Verify(m => m.Subscribe(vm, "DeleteSuperhero", It.IsAny <Action <SuperheroDetailsViewModel, int> >(), default));
        }
        public void Ctor_subscribes_to_NewSuperheroPage()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object);

            messaging.Verify(m => m.Subscribe(vm, "AddSuperhero", It.IsAny <Action <SuperheroCreateViewModel, SuperheroListDTO> >(), default));
        }
        public void Ctor_sets_Title_to_Browse()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object);

            Assert.Equal("Browse", vm.Title);
        }
Exemple #5
0
        public void Ctor_subscribes_to_EditSuperheroPage()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();
            var service    = new Mock <IAuthenticationService>();
            var dialog     = new Mock <IDialogService>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object, service.Object, dialog.Object);

            messaging.Verify(m => m.Subscribe(vm, "UpdateSuperhero", It.IsAny <Action <SuperheroUpdateViewModel, SuperheroListDTO> >(), default));
        }
        public void NewCommand_opens_NewAsync()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object);

            vm.NewCommand.Execute(null);

            navigation.Verify(s => s.NewAsync());

            // Ensure not busy when command finished
            Assert.False(vm.IsBusy);
        }
        public void ViewCommand_opens_ViewAsync_with_superhero()
        {
            var navigation = new Mock <INavigationService>();
            var messaging  = new Mock <IMessagingCenter>();
            var client     = new Mock <IRestClient>();

            var vm = new SuperheroesViewModel(navigation.Object, messaging.Object, client.Object)
            {
                SelectedItem = new SuperheroListDTO()
            };

            vm.ViewCommand.Execute(null);

            navigation.Verify(s => s.ViewAsync(vm.SelectedItem));

            // Ensure not busy when command finished
            Assert.False(vm.IsBusy);
        }
        public SuperheroesPage()
        {
            InitializeComponent();

            BindingContext = _viewModel = App.Container.GetRequiredService <SuperheroesViewModel>();
        }
 public bool Equals(SuperheroesViewModel obj)
 {
     return this.Name == obj.Name &&
     this.Powers == obj.Powers &&
     this.ImgUrl == obj.ImgUrl;
 }
 public SuperheroesViewModel(SuperheroesViewModel newSuperhero)
     : this(newSuperhero.Name, newSuperhero.ImgUrl, newSuperhero.Powers)
 {
 }
Exemple #11
0
 public bool Equals(SuperheroesViewModel obj)
 {
     return(this.Name == obj.Name &&
            this.Powers == obj.Powers &&
            this.ImgUrl == obj.ImgUrl);
 }
Exemple #12
0
 public SuperheroesViewModel(SuperheroesViewModel newSuperhero)
     : this(newSuperhero.Name, newSuperhero.ImgUrl, newSuperhero.Powers)
 {
 }