TDD test class for ViewModel class, architecture, what do you think?What do you think of this chained producer/consumer/adapter (pattern?)What do you think of my EventAggregator implementation in C#?Mocking the class under test with private method callsWhat do you think of this improvement of Linq's GroupBy method?Mock/unit test for this IRepositoryService method/classWhat can I do better in this ViewModel Creator?Unit testing - test class inheritance vs single test classHard-to-test 3 Tier ArchitectureImplementing ViewModel design pattern using DI in a MVP-VM architectureA reusable Previous/Next Contact Collection ViewModel class

Redundant comparison & "if" before assignment

How did Rebekah know that Esau was planning to kill his brother in Genesis 27:42?

Why Shazam when there is already Superman?

Is the U.S. Code copyrighted by the Government?

Added a new user on Ubuntu, set password not working?

What are the purposes of autoencoders?

Problem with TransformedDistribution

Why does the Sun have different day lengths, but not the gas giants?

Why did the EU agree to delay the Brexit deadline?

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

On a tidally locked planet, would time be quantized?

Not using 's' for he/she/it

Closed-form expression for certain product

Open a doc from terminal, but not by its name

Removing files under particular conditions (number of files, file age)

What does routing an IP address mean?

250 Floor Tower

Why electric field inside a cavity of a non-conducting sphere not zero?

C++ debug of nlohmann json using GDB

Are the IPv6 address space and IPv4 address space completely disjoint?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

How should I respond when I lied about my education and the company finds out through background check?

Creepy dinosaur pc game identification

Are paving bricks differently sized for sand bedding vs mortar bedding?



TDD test class for ViewModel class, architecture, what do you think?


What do you think of this chained producer/consumer/adapter (pattern?)What do you think of my EventAggregator implementation in C#?Mocking the class under test with private method callsWhat do you think of this improvement of Linq's GroupBy method?Mock/unit test for this IRepositoryService method/classWhat can I do better in this ViewModel Creator?Unit testing - test class inheritance vs single test classHard-to-test 3 Tier ArchitectureImplementing ViewModel design pattern using DI in a MVP-VM architectureA reusable Previous/Next Contact Collection ViewModel class













0












$begingroup$


Currently I am writing my first TDD application. The project is in Xamarin.Forms and tested in xUnit.



I am wondering, that maybe more experienced developers will have any comments or suggestions regarding the code or architecture, before I will continue with next View Models, to avoid corrections.



I am using also Autofac and Moq.



Test class:
https://github.com/przemyslawbak/Flashcards/blob/master/Flascards.UnitTests/ViewModels/MainPageViewModelTests.cs



public class MainPageViewModelTests
w pliku



Tested View Model class:
https://github.com/przemyslawbak/Flashcards/blob/master/Flashcards/Flashcards/ViewModels/MainPageViewModel.cs



public interface IMainPageViewModel

void LoadGroups();

public class MainPageViewModel : ViewModelBase, IMainPageViewModel

List<Phrase> oldPhrases = new List<Phrase>(); //verification for PopulateDb method;
private Func<IPhraseEditViewModel> _phraseEditVmCreator;
private IMainDataProvider _dataProvider;
public string FileLocation get; set;
public ObservableCollection<string> Groups get; set;
public List<Phrase> LoadedPhrases get; set;
public bool PhraseEdit get; set;
public IPhraseEditViewModel SelectedPhraseEditViewModel get; set;
public MainPageViewModel(IMainDataProvider dataProvider,
Func<IPhraseEditViewModel> phraseditVmCreator) //ctor

_dataProvider = dataProvider;
_phraseEditVmCreator = phraseditVmCreator;
Groups = new ObservableCollection<string>();
LoadedPhrases = new List<Phrase>();
//commands tests
AddPhraseCommand = new DelegateCommand(OnNewPhraseExecute);
LoadFile = new DelegateCommand(OnLoadFileExecute);


public ICommand AddPhraseCommand get; private set;
public ICommand LoadFile get; private set;

private void OnNewPhraseExecute(object obj)

SelectedPhraseEditViewModel = CreateAndLoadPhraseEditViewModel(null);


private IPhraseEditViewModel CreateAndLoadPhraseEditViewModel(int? phraseId)

//Application.Current.MainPage.Navigation.PushAsync(new PhraseEditPage());
var phraseEditVm = _phraseEditVmCreator();
PhraseEdit = true;
phraseEditVm.LoadPhrase(phraseId);
return phraseEditVm;

private async void OnLoadFileExecute(object obj)

LoadedPhrases.Clear();
FileLocation = await _dataProvider.PickUpFile();
LoadedPhrases = LoadFromFile(FileLocation);
PopulateDb(LoadedPhrases);
LoadGroups();

public void LoadGroups() //loads group list from the DB

Groups.Clear();
foreach (var group in _dataProvider.GetGroups())

Groups.Add(group);


public List<Phrase> LoadFromFile(string filePath)

if (filePath != "")
'))

int fieldCount = csv.FieldCount;
string[] headers = csv.GetFieldHeaders();
for (int i = 0; i < fieldCount; i++)

myPhraseMap[headers[i]] = i;

while (csv.ReadNextRecord())

Phrase phrase = new Phrase

Name = csv[myPhraseMap["Name"]],
Definition = csv[myPhraseMap["Definition"]],
Category = csv[myPhraseMap["Category"]],
Group = csv[myPhraseMap["Group"]],
Priority = csv[myPhraseMap["Priority"]],
Learned = false
;
LoadedPhrases.Add(phrase);



else

LoadedPhrases.Clear();

return LoadedPhrases;

public void PopulateDb(List<Phrase> phrases)

if (oldPhrases != phrases) //populates only if collection is new

foreach (var item in phrases)

_dataProvider.SavePhrase(item);

oldPhrases = phrases;





GH repository of the project:
https://github.com/przemyslawbak/Flashcards/tree/master/Flashcards/Flashcards









share







New contributor




bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    0












    $begingroup$


    Currently I am writing my first TDD application. The project is in Xamarin.Forms and tested in xUnit.



    I am wondering, that maybe more experienced developers will have any comments or suggestions regarding the code or architecture, before I will continue with next View Models, to avoid corrections.



    I am using also Autofac and Moq.



    Test class:
    https://github.com/przemyslawbak/Flashcards/blob/master/Flascards.UnitTests/ViewModels/MainPageViewModelTests.cs



    public class MainPageViewModelTests
    w pliku



    Tested View Model class:
    https://github.com/przemyslawbak/Flashcards/blob/master/Flashcards/Flashcards/ViewModels/MainPageViewModel.cs



    public interface IMainPageViewModel

    void LoadGroups();

    public class MainPageViewModel : ViewModelBase, IMainPageViewModel

    List<Phrase> oldPhrases = new List<Phrase>(); //verification for PopulateDb method;
    private Func<IPhraseEditViewModel> _phraseEditVmCreator;
    private IMainDataProvider _dataProvider;
    public string FileLocation get; set;
    public ObservableCollection<string> Groups get; set;
    public List<Phrase> LoadedPhrases get; set;
    public bool PhraseEdit get; set;
    public IPhraseEditViewModel SelectedPhraseEditViewModel get; set;
    public MainPageViewModel(IMainDataProvider dataProvider,
    Func<IPhraseEditViewModel> phraseditVmCreator) //ctor

    _dataProvider = dataProvider;
    _phraseEditVmCreator = phraseditVmCreator;
    Groups = new ObservableCollection<string>();
    LoadedPhrases = new List<Phrase>();
    //commands tests
    AddPhraseCommand = new DelegateCommand(OnNewPhraseExecute);
    LoadFile = new DelegateCommand(OnLoadFileExecute);


    public ICommand AddPhraseCommand get; private set;
    public ICommand LoadFile get; private set;

    private void OnNewPhraseExecute(object obj)

    SelectedPhraseEditViewModel = CreateAndLoadPhraseEditViewModel(null);


    private IPhraseEditViewModel CreateAndLoadPhraseEditViewModel(int? phraseId)

    //Application.Current.MainPage.Navigation.PushAsync(new PhraseEditPage());
    var phraseEditVm = _phraseEditVmCreator();
    PhraseEdit = true;
    phraseEditVm.LoadPhrase(phraseId);
    return phraseEditVm;

    private async void OnLoadFileExecute(object obj)

    LoadedPhrases.Clear();
    FileLocation = await _dataProvider.PickUpFile();
    LoadedPhrases = LoadFromFile(FileLocation);
    PopulateDb(LoadedPhrases);
    LoadGroups();

    public void LoadGroups() //loads group list from the DB

    Groups.Clear();
    foreach (var group in _dataProvider.GetGroups())

    Groups.Add(group);


    public List<Phrase> LoadFromFile(string filePath)

    if (filePath != "")
    '))

    int fieldCount = csv.FieldCount;
    string[] headers = csv.GetFieldHeaders();
    for (int i = 0; i < fieldCount; i++)

    myPhraseMap[headers[i]] = i;

    while (csv.ReadNextRecord())

    Phrase phrase = new Phrase

    Name = csv[myPhraseMap["Name"]],
    Definition = csv[myPhraseMap["Definition"]],
    Category = csv[myPhraseMap["Category"]],
    Group = csv[myPhraseMap["Group"]],
    Priority = csv[myPhraseMap["Priority"]],
    Learned = false
    ;
    LoadedPhrases.Add(phrase);



    else

    LoadedPhrases.Clear();

    return LoadedPhrases;

    public void PopulateDb(List<Phrase> phrases)

    if (oldPhrases != phrases) //populates only if collection is new

    foreach (var item in phrases)

    _dataProvider.SavePhrase(item);

    oldPhrases = phrases;





    GH repository of the project:
    https://github.com/przemyslawbak/Flashcards/tree/master/Flashcards/Flashcards









    share







    New contributor




    bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $begingroup$


      Currently I am writing my first TDD application. The project is in Xamarin.Forms and tested in xUnit.



      I am wondering, that maybe more experienced developers will have any comments or suggestions regarding the code or architecture, before I will continue with next View Models, to avoid corrections.



      I am using also Autofac and Moq.



      Test class:
      https://github.com/przemyslawbak/Flashcards/blob/master/Flascards.UnitTests/ViewModels/MainPageViewModelTests.cs



      public class MainPageViewModelTests
      w pliku



      Tested View Model class:
      https://github.com/przemyslawbak/Flashcards/blob/master/Flashcards/Flashcards/ViewModels/MainPageViewModel.cs



      public interface IMainPageViewModel

      void LoadGroups();

      public class MainPageViewModel : ViewModelBase, IMainPageViewModel

      List<Phrase> oldPhrases = new List<Phrase>(); //verification for PopulateDb method;
      private Func<IPhraseEditViewModel> _phraseEditVmCreator;
      private IMainDataProvider _dataProvider;
      public string FileLocation get; set;
      public ObservableCollection<string> Groups get; set;
      public List<Phrase> LoadedPhrases get; set;
      public bool PhraseEdit get; set;
      public IPhraseEditViewModel SelectedPhraseEditViewModel get; set;
      public MainPageViewModel(IMainDataProvider dataProvider,
      Func<IPhraseEditViewModel> phraseditVmCreator) //ctor

      _dataProvider = dataProvider;
      _phraseEditVmCreator = phraseditVmCreator;
      Groups = new ObservableCollection<string>();
      LoadedPhrases = new List<Phrase>();
      //commands tests
      AddPhraseCommand = new DelegateCommand(OnNewPhraseExecute);
      LoadFile = new DelegateCommand(OnLoadFileExecute);


      public ICommand AddPhraseCommand get; private set;
      public ICommand LoadFile get; private set;

      private void OnNewPhraseExecute(object obj)

      SelectedPhraseEditViewModel = CreateAndLoadPhraseEditViewModel(null);


      private IPhraseEditViewModel CreateAndLoadPhraseEditViewModel(int? phraseId)

      //Application.Current.MainPage.Navigation.PushAsync(new PhraseEditPage());
      var phraseEditVm = _phraseEditVmCreator();
      PhraseEdit = true;
      phraseEditVm.LoadPhrase(phraseId);
      return phraseEditVm;

      private async void OnLoadFileExecute(object obj)

      LoadedPhrases.Clear();
      FileLocation = await _dataProvider.PickUpFile();
      LoadedPhrases = LoadFromFile(FileLocation);
      PopulateDb(LoadedPhrases);
      LoadGroups();

      public void LoadGroups() //loads group list from the DB

      Groups.Clear();
      foreach (var group in _dataProvider.GetGroups())

      Groups.Add(group);


      public List<Phrase> LoadFromFile(string filePath)

      if (filePath != "")
      '))

      int fieldCount = csv.FieldCount;
      string[] headers = csv.GetFieldHeaders();
      for (int i = 0; i < fieldCount; i++)

      myPhraseMap[headers[i]] = i;

      while (csv.ReadNextRecord())

      Phrase phrase = new Phrase

      Name = csv[myPhraseMap["Name"]],
      Definition = csv[myPhraseMap["Definition"]],
      Category = csv[myPhraseMap["Category"]],
      Group = csv[myPhraseMap["Group"]],
      Priority = csv[myPhraseMap["Priority"]],
      Learned = false
      ;
      LoadedPhrases.Add(phrase);



      else

      LoadedPhrases.Clear();

      return LoadedPhrases;

      public void PopulateDb(List<Phrase> phrases)

      if (oldPhrases != phrases) //populates only if collection is new

      foreach (var item in phrases)

      _dataProvider.SavePhrase(item);

      oldPhrases = phrases;





      GH repository of the project:
      https://github.com/przemyslawbak/Flashcards/tree/master/Flashcards/Flashcards









      share







      New contributor




      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Currently I am writing my first TDD application. The project is in Xamarin.Forms and tested in xUnit.



      I am wondering, that maybe more experienced developers will have any comments or suggestions regarding the code or architecture, before I will continue with next View Models, to avoid corrections.



      I am using also Autofac and Moq.



      Test class:
      https://github.com/przemyslawbak/Flashcards/blob/master/Flascards.UnitTests/ViewModels/MainPageViewModelTests.cs



      public class MainPageViewModelTests
      w pliku



      Tested View Model class:
      https://github.com/przemyslawbak/Flashcards/blob/master/Flashcards/Flashcards/ViewModels/MainPageViewModel.cs



      public interface IMainPageViewModel

      void LoadGroups();

      public class MainPageViewModel : ViewModelBase, IMainPageViewModel

      List<Phrase> oldPhrases = new List<Phrase>(); //verification for PopulateDb method;
      private Func<IPhraseEditViewModel> _phraseEditVmCreator;
      private IMainDataProvider _dataProvider;
      public string FileLocation get; set;
      public ObservableCollection<string> Groups get; set;
      public List<Phrase> LoadedPhrases get; set;
      public bool PhraseEdit get; set;
      public IPhraseEditViewModel SelectedPhraseEditViewModel get; set;
      public MainPageViewModel(IMainDataProvider dataProvider,
      Func<IPhraseEditViewModel> phraseditVmCreator) //ctor

      _dataProvider = dataProvider;
      _phraseEditVmCreator = phraseditVmCreator;
      Groups = new ObservableCollection<string>();
      LoadedPhrases = new List<Phrase>();
      //commands tests
      AddPhraseCommand = new DelegateCommand(OnNewPhraseExecute);
      LoadFile = new DelegateCommand(OnLoadFileExecute);


      public ICommand AddPhraseCommand get; private set;
      public ICommand LoadFile get; private set;

      private void OnNewPhraseExecute(object obj)

      SelectedPhraseEditViewModel = CreateAndLoadPhraseEditViewModel(null);


      private IPhraseEditViewModel CreateAndLoadPhraseEditViewModel(int? phraseId)

      //Application.Current.MainPage.Navigation.PushAsync(new PhraseEditPage());
      var phraseEditVm = _phraseEditVmCreator();
      PhraseEdit = true;
      phraseEditVm.LoadPhrase(phraseId);
      return phraseEditVm;

      private async void OnLoadFileExecute(object obj)

      LoadedPhrases.Clear();
      FileLocation = await _dataProvider.PickUpFile();
      LoadedPhrases = LoadFromFile(FileLocation);
      PopulateDb(LoadedPhrases);
      LoadGroups();

      public void LoadGroups() //loads group list from the DB

      Groups.Clear();
      foreach (var group in _dataProvider.GetGroups())

      Groups.Add(group);


      public List<Phrase> LoadFromFile(string filePath)

      if (filePath != "")
      '))

      int fieldCount = csv.FieldCount;
      string[] headers = csv.GetFieldHeaders();
      for (int i = 0; i < fieldCount; i++)

      myPhraseMap[headers[i]] = i;

      while (csv.ReadNextRecord())

      Phrase phrase = new Phrase

      Name = csv[myPhraseMap["Name"]],
      Definition = csv[myPhraseMap["Definition"]],
      Category = csv[myPhraseMap["Category"]],
      Group = csv[myPhraseMap["Group"]],
      Priority = csv[myPhraseMap["Priority"]],
      Learned = false
      ;
      LoadedPhrases.Add(phrase);



      else

      LoadedPhrases.Clear();

      return LoadedPhrases;

      public void PopulateDb(List<Phrase> phrases)

      if (oldPhrases != phrases) //populates only if collection is new

      foreach (var item in phrases)

      _dataProvider.SavePhrase(item);

      oldPhrases = phrases;





      GH repository of the project:
      https://github.com/przemyslawbak/Flashcards/tree/master/Flashcards/Flashcards







      c# xamarin moq





      share







      New contributor




      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      bakunetbakunet

      1




      1




      New contributor




      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      bakunet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          bakunet is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216079%2ftdd-test-class-for-viewmodel-class-architecture-what-do-you-think%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          bakunet is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          bakunet is a new contributor. Be nice, and check out our Code of Conduct.












          bakunet is a new contributor. Be nice, and check out our Code of Conduct.











          bakunet is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216079%2ftdd-test-class-for-viewmodel-class-architecture-what-do-you-think%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          बाताम इन्हें भी देखें सन्दर्भ दिक्चालन सूची1°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.033331°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.03333

          Why is the 'in' operator throwing an error with a string literal instead of logging false?Why can't I use switch statement on a String?Python join: why is it string.join(list) instead of list.join(string)?Multiline String Literal in C#Why does comparing strings using either '==' or 'is' sometimes produce a different result?How to initialize an array's length in javascript?How can I print literal curly-brace characters in python string and also use .format on it?Why does ++[[]][+[]]+[+[]] return the string “10”?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?jQuery.inArray(), how to use it right?

          How can we generalize the fact of finite dimensional vector space to an infinte dimensional case?$k[x]$-module and cyclic module over a finite dimensional vector spaceSubspace of a finite dimensional space is finite dimensionalIf V is an infinite-dimensional vector space, and S is an infinite-dimensional subspace of V, must the dimension of V/S be finite? ExplainWhy is an infinite dimensional space so different than a finite dimensional one?base for finite dimensional vector space is not infinite dimensional vector space?Any finite-dimensional vector space is the dual space of anotherHaving Trouble Understanding Meaning Of A Finite-Dimensional Vector SpaceProve that “Every subspaces of a finite-dimensional vector space is finite-dimensional”Ring as a finite dimensional Vector space over a field KQuestion regarding basis and dimension