Picking up where we left off, I want to add unit tests to my program. Now, I know, I should have been using unit tests all along. I have no excuse and hang my head in shame.
To get started, I’ve decided to add xUnit through NuGet. Easy peasy. But it won’t work. The full explanation is here. Great article. Here, in a nutshell are the steps you need to perform:
- Create an xUnit test project in the same solution as ForgetMeNot
- Make sure it runs
- Add a reference to the ForgetMeNot project
- This wil not run yet. Here is where the fun begins
- First, open up the ForgetMeNot project and change the TargetFrameworks to
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
6. Replace the output statement with
<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>
7. Unload ForgetMeNot, reload it, close Visual Studio, open Visual Studio and voila! it will work
(The whys and wherefores are explained very well in the article referenced above)
NSubstitute for mocking
We are now almost ready to begin. I want to use mocking from the very beginning. Until about a weak ago, I’d have installed Moq, but I’m intrigued by NSubstitute, so I’m going to use that.
After assuring myself that the default xUnit test works, I’ll add a file called BuddyTests. In there I will add my first test: ShouldPopulateBuddies. I want to make sure that calling Init() will populate the list of buddies (actually, it could return no buddies, but right now I just want to get this test working).
[Fact]
public async Task ShouldPopulateBuddies()
{
var buddies = new List<Buddy>();
var buddy = new Buddy();
buddies.Add(buddy);
var buddyService = Substitute.For<IBuddyService>();
buddyService.GetBuddies().Returns(buddies);
var buddyListVM = new BuddyListViewModel(buddyService);
await buddyListVM.Init();
Assert.True( buddyListVM.Buddies?.Count > 0);
}
So what is going on here? First I create an empty list of Buddy objects and I create an instance of Buddy which I add to that list.
Next (and here is the cool part) I create a mock for my service with that one line
var buddyService = Substitute.For<IBuddyService>();
Remember that Substitute wants interfaces, so earlier I went to each class in my services, put the cursor on the class name and used Refactor->Extract->ExtractInterface which brought up this wonderful dialog box:

I clicked on Select Public to get the public methods and Its own file to put the new interface in a file named IBuddyService.cs. R# is even nice enough to tack the interface name onto the class declaration.
OK, enough digression. My next step is to tell the mock that when the BuddyService’s GetBuddies method is returned, it should return the list of Buddies we just created.
We are now ready to create an instance of the ViewModel and call init() on it. It will use the service we passed in (the mock) and will thus populate its list of buddies with our dummy list and the Assert will pass.
Cool, eh?
This also tells me that I need to handle the case when the list is empty. That means I need to look long and hard at Init() and possibly add another test to prove that the corner case does not cause a problem.
Wrapping Up
It turns out that simple unit tests with mocking is not all that hard to do; and nSubstitute has a lot less ceremony than Moq. I’m going to stay with it for a while and see if I run off a cliff.
Since all the source code changes are already in this blog post, I won’t update the online source until I’ve written some more tests.
Shout-out to Daniel Hindrikes for helping me get started on unit testing for MAUI
See next posting for more unit testing using Fluent asserts.






































Субстрат повсеместно используется в аграрном производстве для выращивания растений.
В парниках земля служит базой для салатных растений.
На открытых полях земля задействуется для высадки кормовых и масличных растений.
растительный грунт с доставкой цена
Субстраты необходимы для формирования лужаек и садового дизайна.
В питомниках грунт выполняет главную роль при получении саженцев.
Помимо этого грунт применяется для восстановления нарушенных территорий.
Субстрат активно применяется в аграрном производстве для выращивания растений.
В закрытых помещениях грунт служит базой для овощных культур.
На открытых полях земля используется для посева кормовых и масличных культур.
чернозем щелково
Грунтовые смеси необходимы для создания дёрна и ландшафтного оформления.
В дендрариях грунт играет главную функцию при получении саженцев.
Кроме того почва применяется для рекультивации нарушенных участков.
Wow that was strange. I just wrote an very long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say excellent blog!
Hello would you mind stating which blog platform you’re using? I’m going to start my own blog in the near future but I’m having a hard time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S Sorry for getting off-topic but I had to ask!
At this time it seems like WordPress is the best blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?
Wow that was odd. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say great blog!
Right now it appears like BlogEngine is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?
This piece of writing is in fact a fastidious one it assists new net viewers, who are wishing in favor of blogging.
Appreciating the time and energy you put into your website and detailed information you offer. It’s good to come across a blog every once in a while that isn’t the same unwanted rehashed material. Fantastic read! I’ve saved your site and I’m adding your RSS feeds to my Google account.
Hey! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new updates.
Greate post. Keep posting such kind of information on your page. Im really impressed by it.
I blog often and I genuinely thank you for your information. The article has truly peaked my interest. I will take a note of your site and keep checking for new information about once a week. I subscribed to your Feed as well.
At this time it sounds like Expression Engine is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?
Currently it seems like BlogEngine is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
It’s impressive that you are getting ideas from this post as well as from our discussion made here.
Hello there, You’ve done an incredible job. I’ll definitely digg it and in my view suggest to my friends. I’m confident they will be benefited from this website.
Hi there, I enjoy reading through your article post. I wanted to write a little comment to support you.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Peculiar article, just what I wanted to find.
Hey. Lost money once, learned from it with trusted casino but patience is key. opay
На данном сайте можно почерпнуть много практичной материалов.
Здесь собраны обзоры и инструкции под любой вкус.
Вы в состоянии изучить как базовую информацию, так и детальные данные.
Данный ресурс пригодится начинающим в своей практике.
https://fsfr-vkr.ru/read-full/615-sravnitelnyy-analiz-rtp-return-to-player-populyarnykh-slotov-raznykh-provayderov.html
Помимо этого здесь часто публикуются свежие материалы.
Предлагаем подробно прочитать размещённую здесь базу.
Следовательно, эта платформа является ценным хранилищем опыта.
At this time it sounds like Drupal is the top blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?
What’s Happening i’m new to this, I stumbled upon this I have discovered It positively helpful and it has helped me out loads. I am hoping to give a contribution & help other users like its aided me. Good job.
Excellent pieces. Keep posting such kind of info on your blog. Im really impressed by your blog.
Aw, this was a really good post. Taking a few minutes and actual effort to create a top notch article… but what can I say… I hesitate a lot and don’t seem to get nearly anything done.
Aw, this was an exceptionally good post. Finding the time and actual effort to generate a very good article… but what can I say… I procrastinate a lot and never seem to get anything done.
At this time it sounds like WordPress is the preferred blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?
Right now it sounds like Drupal is the preferred blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?
Currently it appears like Drupal is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?
Hey there, You have performed an excellent job. I will certainly digg it and individually recommend to my friends. I’m sure they’ll be benefited from this website.
Greate post. Keep writing such kind of info on your site. Im really impressed by your blog.
Right now it appears like Expression Engine is the best blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?
Currently it sounds like Drupal is the top blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Hello there, You’ve done an incredible job. I’ll certainly digg it and individually suggest to my friends. I’m confident they’ll be benefited from this web site.
At this time it seems like Expression Engine is the best blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?
Can I simply say what a comfort to uncover a person that really understands what they are talking about on the net. You actually know how to bring a problem to light and make it important. More people really need to read this and understand this side of the story. It’s surprising you are not more popular since you surely have the gift.
At this time it sounds like WordPress is the best blogging platform available right now. (from what I’ve read) Is that what you’re using on your blog?
Hi there, You have done a great job. I will definitely digg it and for my part recommend to my friends. I’m sure they’ll be benefited from this website.
Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say great blog!
узнать больше Здесь трипскан вход
Currently it appears like Movable Type is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
May I simply just say what a comfort to discover a person that really knows what they’re discussing online. You actually know how to bring an issue to light and make it important. More and more people really need to read this and understand this side of your story. It’s surprising you’re not more popular because you definitely have the gift.
Aw, this was a very nice post. Spending some time and actual effort to create a superb article… but what can I say… I hesitate a lot and don’t seem to get anything done.
Right now it seems like WordPress is the preferred blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?
mexican pharmacy prices: online mexican pharmacies – farmacia pharmacy mexico purchase online
Excellent post. Keep posting such kind of info on your page. Im really impressed by it.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.