Xamarin.Forms.Mocks | Library for running Xamarin.Forms inside of unit tests | Form library

 by   jonathanpeppers C# Version: 4.7.0.1 License: MIT

kandi X-RAY | Xamarin.Forms.Mocks Summary

Xamarin.Forms.Mocks is a C# library typically used in User Interface, Form, Xamarin applications. Xamarin.Forms.Mocks has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
Library for running Xamarin.Forms inside of unit tests. If you've ever written any complicated logic inside a Xamarin.Forms View, you quickly realize that this code can't be unit tested easily. Your colleagues will tell you to MVVM all the things, but you cannot get around interacting with Xamarin.Forms itself. Things like navigation, animations, custom markup extensions, etc. can become an untested mess.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        Xamarin.Forms.Mocks has a low active ecosystem.
                        summary
                        It has 183 star(s) with 23 fork(s). There are 12 watchers for this library.
                        summary
                        It had no major release in the last 12 months.
                        summary
                        There are 2 open issues and 34 have been closed. On average issues are closed in 19 days. There are 1 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of Xamarin.Forms.Mocks is 4.7.0.1
                        Xamarin.Forms.Mocks Support
                          Best in #Form
                            Average in #Form
                            Xamarin.Forms.Mocks Support
                              Best in #Form
                                Average in #Form

                                  kandi-Quality Quality

                                    summary
                                    Xamarin.Forms.Mocks has 0 bugs and 0 code smells.
                                    Xamarin.Forms.Mocks Quality
                                      Best in #Form
                                        Average in #Form
                                        Xamarin.Forms.Mocks Quality
                                          Best in #Form
                                            Average in #Form

                                              kandi-Security Security

                                                summary
                                                Xamarin.Forms.Mocks has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                Xamarin.Forms.Mocks code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                Xamarin.Forms.Mocks Security
                                                  Best in #Form
                                                    Average in #Form
                                                    Xamarin.Forms.Mocks Security
                                                      Best in #Form
                                                        Average in #Form

                                                          kandi-License License

                                                            summary
                                                            Xamarin.Forms.Mocks is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            Xamarin.Forms.Mocks License
                                                              Best in #Form
                                                                Average in #Form
                                                                Xamarin.Forms.Mocks License
                                                                  Best in #Form
                                                                    Average in #Form

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        Xamarin.Forms.Mocks releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions are not available. Examples and code snippets are available.
                                                                        Xamarin.Forms.Mocks Reuse
                                                                          Best in #Form
                                                                            Average in #Form
                                                                            Xamarin.Forms.Mocks Reuse
                                                                              Best in #Form
                                                                                Average in #Form
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  Xamarin.Forms.Mocks Key Features

                                                                                  Library for running Xamarin.Forms inside of unit tests

                                                                                  Xamarin.Forms.Mocks Examples and Code Snippets

                                                                                  No Code Snippets are available at this moment for Xamarin.Forms.Mocks.
                                                                                  Community Discussions

                                                                                  Trending Discussions on Xamarin.Forms.Mocks

                                                                                  NUnit test for Xamarin.Forms ListViews with cell binding
                                                                                  chevron right

                                                                                  Trending Discussions on Xamarin.Forms.Mocks

                                                                                  QUESTION

                                                                                  NUnit test for Xamarin.Forms ListViews with cell binding
                                                                                  Asked 2017-Jul-20 at 03:33

                                                                                  I'm trying to write unit tests for a ListView with a custom DataTemplate. Although the cells are rendered as expected on iOS and Android, their bound properties are null when running NUnit tests.

                                                                                  The setup

                                                                                  To initiate Xamarin.Forms in an NUnit test project, I'm using Xamarin.Forms.Mocks. So the TestFixture looks as follows:

                                                                                  using NUnit.Framework;
                                                                                  using Xamarin.Forms;
                                                                                  using Xamarin.Forms.Mocks;
                                                                                  
                                                                                  namespace UnitTest
                                                                                  {
                                                                                      [TestFixture]
                                                                                      public class Test
                                                                                      {
                                                                                          [SetUp]
                                                                                          public void SetUp()
                                                                                          {
                                                                                              MockForms.Init();
                                                                                          }
                                                                                  

                                                                                  What works

                                                                                  One test, which is working well, creates a new DataTemplate with a custom StringCell bound to a string "foo":

                                                                                          class StringCell : ViewCell
                                                                                          {
                                                                                              public StringCell()
                                                                                              {
                                                                                                  var label = new Label();
                                                                                                  label.SetBinding(Label.TextProperty, ".");
                                                                                                  View = label;
                                                                                              }
                                                                                          }
                                                                                  
                                                                                          [Test]
                                                                                          public void ViewCellWithString()
                                                                                          {
                                                                                              var content = new DataTemplate(typeof(StringCell)).CreateContent();
                                                                                              (content as Cell).BindingContext = "foo";
                                                                                  
                                                                                              Assert.That(((content as ViewCell).View as Label).Text, Is.EqualTo("foo"));
                                                                                          }
                                                                                  

                                                                                  As expected, the rendered content is a ViewCell with a View of type Label with the Text "foo".

                                                                                  What doesn't work

                                                                                  A second test, however, fails: It creates a DataTemplate of type ItemCell bound to a custom object Item with a bindable property Name "bar".

                                                                                          class Item : BindableObject
                                                                                          {
                                                                                              public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(Item), null);
                                                                                  
                                                                                              public string Name {
                                                                                                  get { return (string)GetValue(NameProperty); }
                                                                                                  set { SetValue(NameProperty, value); }
                                                                                              }
                                                                                          }
                                                                                  
                                                                                          class ItemCell : ViewCell
                                                                                          {
                                                                                              public ItemCell()
                                                                                              {
                                                                                                  var label = new Label();
                                                                                                  label.SetBinding(Label.TextProperty, nameof(Item.NameProperty));
                                                                                                  View = label;
                                                                                              }
                                                                                          }
                                                                                  
                                                                                          [Test]
                                                                                          public void ViewCellWithItem()
                                                                                          {
                                                                                              var content = new DataTemplate(typeof(ItemCell)).CreateContent();
                                                                                              (content as Cell).BindingContext = new Item { Name = "bar" };
                                                                                  
                                                                                              Assert.That(((content as ViewCell).View as Label).Text, Is.EqualTo("bar"));
                                                                                          }
                                                                                  

                                                                                  This test fails, because the Label's Text property is null.

                                                                                  My question

                                                                                  What am I doing wrong? Shouldn't the binding to a string via "." behave similar to the binding to an Item via NameProperty? Or is there a better way to instantiate the view of a list view cell with binding properties for unit testing purposes?

                                                                                  ANSWER

                                                                                  Answered 2017-Jul-20 at 03:33

                                                                                  I just found the tiny but crucial mistake in my code:

                                                                                  Instead of

                                                                                  label.SetBinding(Label.TextProperty, nameof(Item.NameProperty));
                                                                                  

                                                                                  I need to write

                                                                                  label.SetBinding(Label.TextProperty, nameof(Item.Name));
                                                                                  

                                                                                  since nameof(Item.NameProperty) yields "NameProperty", but I need to bind to "Name".

                                                                                  Source https://stackoverflow.com/questions/45144350

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install Xamarin.Forms.Mocks

                                                                                  You can download it from GitHub.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/jonathanpeppers/Xamarin.Forms.Mocks.git

                                                                                • CLI

                                                                                  gh repo clone jonathanpeppers/Xamarin.Forms.Mocks

                                                                                • sshUrl

                                                                                  git@github.com:jonathanpeppers/Xamarin.Forms.Mocks.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Reuse Pre-built Kits with Xamarin.Forms.Mocks

                                                                                  Consider Popular Form Libraries

                                                                                  react-hook-form

                                                                                  by react-hook-form

                                                                                  black

                                                                                  by psf

                                                                                  redux-form

                                                                                  by redux-form

                                                                                  simple_form

                                                                                  by heartcombo

                                                                                  formily

                                                                                  by alibaba

                                                                                  Try Top Libraries by jonathanpeppers

                                                                                  glidex

                                                                                  by jonathanpeppersC#

                                                                                  spice

                                                                                  by jonathanpeppersC#

                                                                                  Xamarin.Android.Lite

                                                                                  by jonathanpeppersC#

                                                                                  boots

                                                                                  by jonathanpeppersC#

                                                                                  XPlatUtils

                                                                                  by jonathanpeppersC#

                                                                                  Compare Form Libraries with Highest Support

                                                                                  Xamarin.Forms

                                                                                  by xamarin

                                                                                  react-hook-form

                                                                                  by react-hook-form

                                                                                  redux-form

                                                                                  by redux-form

                                                                                  django-crispy-forms

                                                                                  by django-crispy-forms

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit