Published on May 27, 2018 by Michiel Wouters

Code at beginning of lesson:
github.com/MichWouters/MagicMirror-Tutorial/tree/backend-chapter-3

Code at end of lesson:
github.com/MichWouters/MagicMirror-Tutorial/tree/backend-chapter-4

In today’s tutorial we will write Integration Tests for the DataLayer allowing us to finally check if our code is actually working. After this we’ll complete the Datalayer by adding Traffic Information, courtesy of Google Maps and write tests for that API as well.

Google Maps Api Url:
maps.googleapis.com/maps/api/distancematrix/json

Google Maps API key:
AIzaSyBGoN7HTIWBLk6N9CqEqvJsV_KGFmwt8tw

Please note that this key is on a freemium plan and availability cannot be guaranteed. If availability is important, do consider registering an account and creating a private API Key.
For more information visit:
cloud.google.com/maps-platform/

Today’s Topics:
– Integration Tests vs Unit Tests
– Triple-A Testing
– Debugging
– Interfaces
– Google Maps Api

Leave a Reply

9 Comments on "Magic Mirror BE – Part 4 – Testing the DataLayer"

Notify of
avatar

Nick White
Guest
Nick White
14 days 10 hours ago

Gonna sound stupid, but where can I get the physical part, not sure if it actually exists, but the physical part that is shown in the preview for the video?

Michiel Wouters
Guest
Michiel Wouters
22 days 18 hours ago

00:06: Introduction
00:26: Today's Topics
01:21: Unit Tests vs Integration Tests
02:58: Start coding
03:20: Testing the Weather Repo
03:53: The [Fact] Attribute
05:27: Three A's in Testing
06:15: Writing the first test
07:03: Why an incomplete test should fail.
08:51: Debugging
12:03: Unhappy Path
14:51: Testing as documentation
16:12: Advantages of writing tests
17:34: Program to an Abstraction rather than a concrete Type
18:51: Interfaces (Theory)
22:39: Generate an Interface from an existing class
24:37: Expand DataLayer to also retrieve Traffic data
24:57: Google Maps Api
26:00: Expanding DataAccessConfig.cs
26:50: Generating Traffic Entities
28:11: ITrafficRepo.cs
28:54: TrafficRepo.cs
32:58: Testing the Traffic Repo
36:32: What lies on the horizon?37:04: Outro

Marshall Beeler
Guest
Marshall Beeler
24 days 21 hours ago

I run the test after adding the first Assert section, just like you, at 8:42, and my test fails. Comes back null. Where as yours passes. I have checked my code, i have looked at your code. Heck I have even copied your code into mine and it always comes back Null for me. And yours always passes. What am i missing?Message: Assert.Equal() Failure
Expected: London
Actual: (null)

Marshall Beeler
Guest
Marshall Beeler
24 days 17 hours ago

Strange. I copied it straight from my account on Wunderground. I just went and regenerated the key and tried again and still the same. Dont understand. This API works with my MagicMirror². Oh well. Guess i will work with openweather.Thanks for checking it out though.

Michiel Wouters
Guest
Michiel Wouters
24 days 18 hours ago

Looks like there is indeed an issue with your Api Key. Upon debugging I can see that you are able to connect to the Wunderground Api but it returns an error message: 'This key does not exist'.When I navigate to the Api via browser it states that free keys are no longer available. If you paid for this key your best bet would be to contact the Wunderground people. If not, OpenWeatherMap provides a good free alternative.

Michiel Wouters
Guest
Michiel Wouters
24 days 18 hours ago

Hi Marshall,Have you tried debugging your test and seeing if any data comes through? If a connection cannot be made, the result will be null.Can you show me your code on Githbub or Pastebin? I'll take a look at it.Thanks.

Marshall Beeler
Guest
Marshall Beeler
24 days 20 hours ago

Here have a look. I think my url and api setup for Wunderground doesnt work. I cant seem to figure out how to get it to work though. Any thoughts?github.com/fumunda/MagicMirror.IoT

Janko
Guest
Janko
27 days 10 hours ago

very good video!

Michiel Wouters
Guest
Michiel Wouters
26 days 21 hours ago

Thank you!

wpDiscuz