1 00:00:06,540 --> 00:00:08,100 - In the previous section, 2 00:00:08,100 --> 00:00:11,490 we saw how to mock everything in the module. 3 00:00:11,490 --> 00:00:13,380 You just say, jest dot mock, 4 00:00:13,380 --> 00:00:16,020 and Jest will automatically create a mock version 5 00:00:16,020 --> 00:00:18,795 of every function in that file. 6 00:00:18,795 --> 00:00:21,480 So that works for any free function, 7 00:00:21,480 --> 00:00:23,970 any global function defined in that module, 8 00:00:23,970 --> 00:00:28,680 plus constructors in classes, plus methods in those classes. 9 00:00:28,680 --> 00:00:31,860 So basically every function in that file will be mocked 10 00:00:31,860 --> 00:00:34,383 with kind of like, a do nothing implementation. 11 00:00:35,370 --> 00:00:36,203 And that's fine. 12 00:00:36,203 --> 00:00:39,510 That's the easiest way to mock a module. 13 00:00:39,510 --> 00:00:42,900 It's also possible to define manual mocks. 14 00:00:42,900 --> 00:00:45,660 So rather than having automatically generated mocks, 15 00:00:45,660 --> 00:00:47,220 which are basically empty, 16 00:00:47,220 --> 00:00:50,230 you can define your own kind of stub implementation 17 00:00:51,330 --> 00:00:54,900 with methods that actually do something more useful. 18 00:00:54,900 --> 00:00:56,670 So that's what we're gonna look at in this section. 19 00:00:56,670 --> 00:00:58,380 So what you do is you create a folder, 20 00:00:58,380 --> 00:01:01,833 called underscore underscore mocks underscore underscore. 21 00:01:02,910 --> 00:01:06,090 In there, you implement mock or stub versions 22 00:01:06,090 --> 00:01:10,320 of the functions with some kind of useful behavior, 23 00:01:10,320 --> 00:01:12,300 instead of the real class. 24 00:01:12,300 --> 00:01:16,590 And then, you just basically tell Jest to mock the module. 25 00:01:16,590 --> 00:01:18,090 And because it looks 26 00:01:18,090 --> 00:01:20,430 for the underscore underscore mocks folder. 27 00:01:20,430 --> 00:01:24,180 And because it finds it, when you say Jest dot mock, 28 00:01:24,180 --> 00:01:26,940 instead of generating automatic mocks, 29 00:01:26,940 --> 00:01:28,230 which are kind of empty, 30 00:01:28,230 --> 00:01:30,150 Jest will use your mocks, instead. 31 00:01:30,150 --> 00:01:33,573 It'll use your mock functions instead of the real functions. 32 00:01:34,860 --> 00:01:37,820 Okay. So we're gonna see how to do that. 33 00:01:37,820 --> 00:01:41,373 If you go into the mocking classes, manual mock folder. 34 00:01:43,140 --> 00:01:45,600 Okay. So that's the folder you want to go into. 35 00:01:45,600 --> 00:01:48,000 If you open that folder in the code editor, 36 00:01:48,000 --> 00:01:49,320 it looks like this. 37 00:01:49,320 --> 00:01:51,030 Inside here, 38 00:01:51,030 --> 00:01:54,090 same classes as in the previous couple of sections, 39 00:01:54,090 --> 00:01:56,040 I've got a low level rest client. 40 00:01:56,040 --> 00:01:59,640 This is the real implementation of rest client, where, 41 00:01:59,640 --> 00:02:03,705 which basically calls into a rest service using Axios. 42 00:02:03,705 --> 00:02:04,538 Okay. 43 00:02:04,538 --> 00:02:08,700 So when I'm unit testing my other class product manager, 44 00:02:08,700 --> 00:02:11,640 I don't want these real functions to be invoked. 45 00:02:11,640 --> 00:02:13,860 Okay? Because unit testing is meant 46 00:02:13,860 --> 00:02:15,720 to focus on one class at a time. 47 00:02:15,720 --> 00:02:17,527 So what I'm gonna do is I'm gonna 48 00:02:17,527 --> 00:02:21,060 basically define mock versions of those functions. 49 00:02:21,060 --> 00:02:22,770 And I've done that in the mock folder. 50 00:02:22,770 --> 00:02:23,760 Have look in the mock folder, 51 00:02:23,760 --> 00:02:26,820 or underscore underscore mocks underscore underscore. 52 00:02:26,820 --> 00:02:30,210 I've defined mock versions of these functions, 53 00:02:30,210 --> 00:02:31,380 have a look in here. 54 00:02:31,380 --> 00:02:33,930 And these are the functions that would be used instead. 55 00:02:33,930 --> 00:02:38,930 So I've hard coded my kind of dummy or my stub rest client, 56 00:02:39,450 --> 00:02:43,200 so that the constructor just output a message to say, 57 00:02:43,200 --> 00:02:46,380 hi, this is the mock version of the constructor 58 00:02:46,380 --> 00:02:48,030 that's been called. 59 00:02:48,030 --> 00:02:49,950 I've got some hard coded data here. 60 00:02:49,950 --> 00:02:54,450 Last week, we went skiing in Austria and it was brilliant. 61 00:02:54,450 --> 00:02:56,700 I wish I was still there, but there we go. 62 00:02:56,700 --> 00:02:59,283 So anyway, skis, that's one product. 63 00:03:00,120 --> 00:03:03,281 There were 500 pairs of skis in stock, sorry. 64 00:03:03,281 --> 00:03:04,950 There are hundred pairs of skis in stock. 65 00:03:04,950 --> 00:03:07,770 And each pair of skis cost 500 pounds. 66 00:03:07,770 --> 00:03:11,070 There are five pairs of boots in stock, 67 00:03:11,070 --> 00:03:13,740 and each pair of boots cost 200 pounds. 68 00:03:13,740 --> 00:03:15,840 And there were three goggles in stock, 69 00:03:15,840 --> 00:03:16,980 which cost a hundred pound. 70 00:03:16,980 --> 00:03:18,270 Well, that's quite expensive. 71 00:03:18,270 --> 00:03:20,220 But that's a hard coded set of products. 72 00:03:20,220 --> 00:03:23,428 Imagine that's pretend data that we've got back 73 00:03:23,428 --> 00:03:25,350 from the rest service. 74 00:03:25,350 --> 00:03:27,690 So the delete function, 75 00:03:27,690 --> 00:03:29,850 when the delete function is called a rest client, 76 00:03:29,850 --> 00:03:33,060 it'll call this kind of manual mock version 77 00:03:33,060 --> 00:03:36,150 just to say, hello, this is the manual mock version 78 00:03:36,150 --> 00:03:37,353 of the delete function. 79 00:03:38,190 --> 00:03:39,660 The update function, again, 80 00:03:39,660 --> 00:03:42,000 it doesn't actually call using Axios. 81 00:03:42,000 --> 00:03:44,313 It just does something, a mock implementation. 82 00:03:45,330 --> 00:03:49,140 The get All function is a bit more interesting. 83 00:03:49,140 --> 00:03:51,030 It's meant to return a promise, 84 00:03:51,030 --> 00:03:53,343 but it turns a hard coded set of data. 85 00:03:54,270 --> 00:03:57,540 It says, this is the mock version of the get all method, 86 00:03:57,540 --> 00:03:58,830 which is going to dissolve. 87 00:03:58,830 --> 00:04:00,480 In other words, succeed, 88 00:04:00,480 --> 00:04:03,540 as if the rest service had actually returned that data. 89 00:04:03,540 --> 00:04:06,120 So rest client products, 90 00:04:06,120 --> 00:04:08,130 that's the products I just showed you up here. 91 00:04:08,130 --> 00:04:10,890 So it'll return that as hard coded data, 92 00:04:10,890 --> 00:04:13,860 rather than an actual rest service call. 93 00:04:13,860 --> 00:04:16,860 That's the purpose of defining manual mocks is 94 00:04:16,860 --> 00:04:21,120 that you can kind of give it some sensible default data 95 00:04:21,120 --> 00:04:23,820 for the context of your unit tests, 96 00:04:23,820 --> 00:04:26,610 if you wanna get the product by ID. 97 00:04:26,610 --> 00:04:28,650 Okay, so what it does, it basically, 98 00:04:28,650 --> 00:04:33,300 it sees if my array at the top contains the ID. 99 00:04:33,300 --> 00:04:35,009 When you call the find function, 100 00:04:35,009 --> 00:04:38,760 it either returns a product or it returns null. 101 00:04:38,760 --> 00:04:43,140 So if the product matches, then it returns that product. 102 00:04:43,140 --> 00:04:45,780 And if the product, basically if the ID is invalid, 103 00:04:45,780 --> 00:04:47,520 then it rejects. 104 00:04:47,520 --> 00:04:51,210 So this promise will either succeed with the product 105 00:04:51,210 --> 00:04:52,290 that's being requested, 106 00:04:52,290 --> 00:04:55,230 or it'll reject with an error to say, 107 00:04:55,230 --> 00:04:58,350 unrecognized product, basically invalid ID. 108 00:04:58,350 --> 00:05:00,600 So these are the mock versions 109 00:05:00,600 --> 00:05:01,433 that are going to be used 110 00:05:01,433 --> 00:05:03,867 when my product manager has a rest client. 111 00:05:03,867 --> 00:05:06,210 And it'll be used in these mock versions 112 00:05:06,210 --> 00:05:08,100 rather than the real functions, 113 00:05:08,100 --> 00:05:09,990 or rather than the automatic mocks. 114 00:05:09,990 --> 00:05:11,880 These are a bit more work 115 00:05:11,880 --> 00:05:13,470 but may be useful 116 00:05:13,470 --> 00:05:16,470 to provide some kind of testable behavior 117 00:05:16,470 --> 00:05:18,840 that you can make use of. 118 00:05:18,840 --> 00:05:21,270 Okay, so we've just seen the mock folder. 119 00:05:21,270 --> 00:05:24,150 And I've just shown you the manual mock implementation, 120 00:05:24,150 --> 00:05:28,260 sometimes called stub of the rest client module. 121 00:05:28,260 --> 00:05:32,910 So we can now use those mock functions in our tests. 122 00:05:32,910 --> 00:05:35,670 Okay. So here's a simple test. 123 00:05:35,670 --> 00:05:37,350 Have a look at this. 124 00:05:37,350 --> 00:05:38,190 On the first line, 125 00:05:38,190 --> 00:05:40,350 I've imported the product manager library 126 00:05:40,350 --> 00:05:41,460 'cause I'm going to be, you know, 127 00:05:41,460 --> 00:05:42,540 using that class. 128 00:05:42,540 --> 00:05:45,420 Second line, I've imported the rest client module, 129 00:05:45,420 --> 00:05:48,270 and then I've mocked the rest client module. 130 00:05:48,270 --> 00:05:49,800 In this simple test here, 131 00:05:49,800 --> 00:05:51,750 when I call the, 132 00:05:51,750 --> 00:05:54,390 when I create a product manager object, 133 00:05:54,390 --> 00:05:56,610 let me just remind you about that. 134 00:05:56,610 --> 00:05:58,310 When you create a product manager, 135 00:05:59,430 --> 00:06:00,900 the first thing it does is 136 00:06:00,900 --> 00:06:02,700 to basically create a rest client. 137 00:06:02,700 --> 00:06:05,670 Now that is going to call my stub version 138 00:06:05,670 --> 00:06:07,260 of the rest client constructor. 139 00:06:07,260 --> 00:06:10,140 When I create a product manager, 140 00:06:10,140 --> 00:06:13,650 it's gonna call the rest client mock constructor. 141 00:06:13,650 --> 00:06:17,253 It's gonna call this constructor up here. 142 00:06:18,300 --> 00:06:21,232 Okay, so I should see, displayed on the console, 143 00:06:21,232 --> 00:06:23,400 a message to say, the manual mock 144 00:06:23,400 --> 00:06:25,920 for the rest client constructor has been called. 145 00:06:25,920 --> 00:06:28,710 That should appear when I run the test. 146 00:06:28,710 --> 00:06:32,190 Okay. So we mock the rest client module. 147 00:06:32,190 --> 00:06:37,190 So it'll ordinarily, it would create, you know, empty mocks 148 00:06:37,620 --> 00:06:39,960 but just looks and sees 149 00:06:39,960 --> 00:06:42,480 that I've got an underscore underscore mocks 150 00:06:42,480 --> 00:06:44,190 underscore underscore folder. 151 00:06:44,190 --> 00:06:46,620 And instead of generating automatic mocks, 152 00:06:46,620 --> 00:06:49,320 it uses my manually implemented mocks, instead. 153 00:06:49,320 --> 00:06:51,360 In other words, it'll use the mocks 154 00:06:51,360 --> 00:06:52,743 that I've defined in here, 155 00:06:54,270 --> 00:06:56,940 rather than generating automatic empty mocks 156 00:06:56,940 --> 00:06:59,460 and use my stub functions instead. 157 00:06:59,460 --> 00:07:01,470 So when I create a product manager object, 158 00:07:01,470 --> 00:07:04,110 it calls the rest client constructor internally. 159 00:07:04,110 --> 00:07:06,630 It calls my mock implementation 160 00:07:06,630 --> 00:07:09,150 of the rest client constructor. 161 00:07:09,150 --> 00:07:10,590 So when I run that test, 162 00:07:10,590 --> 00:07:12,360 that's how you run this particular test. 163 00:07:12,360 --> 00:07:16,353 What you'll see, the important thing here, is this bit. 164 00:07:17,370 --> 00:07:19,740 When I created my product manager, 165 00:07:19,740 --> 00:07:21,240 it created the rest client. 166 00:07:21,240 --> 00:07:25,080 It called my mock version of the rest client constructor, 167 00:07:25,080 --> 00:07:29,430 and my mock client constructor displayed this message, 168 00:07:29,430 --> 00:07:33,810 manual mock rest client construct a cold. 169 00:07:33,810 --> 00:07:35,580 Okay, and it shows me it was called 170 00:07:35,580 --> 00:07:38,133 in my mock implementation of rest client. 171 00:07:38,970 --> 00:07:40,710 So that's that proves the point. 172 00:07:40,710 --> 00:07:42,120 And we could end it there actually, 173 00:07:42,120 --> 00:07:44,880 but I'm gonna go on with the couple of more examples, 174 00:07:44,880 --> 00:07:46,470 have a look at this. 175 00:07:46,470 --> 00:07:50,760 I'm gonna invoke the remove products method. 176 00:07:50,760 --> 00:07:53,940 So when I create the product manager, 177 00:07:53,940 --> 00:07:56,340 and then I say remove products, 178 00:07:56,340 --> 00:07:57,930 when you call remove products, 179 00:07:57,930 --> 00:08:00,420 now let me just remind you how that method works. 180 00:08:00,420 --> 00:08:05,420 When you call remove products on the product manager, 181 00:08:06,420 --> 00:08:10,050 it activates through the list of products, 182 00:08:10,050 --> 00:08:13,500 and it basically calls rest client delete. 183 00:08:13,500 --> 00:08:16,200 So if I pass in three ideas here, 184 00:08:16,200 --> 00:08:18,990 it'll call the rest client delete function three times, 185 00:08:18,990 --> 00:08:21,990 and it's gonna call my mock version of that function. 186 00:08:21,990 --> 00:08:25,650 So my mock delete function is gonna be called three times. 187 00:08:25,650 --> 00:08:26,970 So three times, 188 00:08:26,970 --> 00:08:30,360 we should see this console message appearing. 189 00:08:30,360 --> 00:08:33,000 Okay, to say, you know, deleted product one o one, 190 00:08:33,000 --> 00:08:36,480 deleted product one o two, deleted product one o three. 191 00:08:36,480 --> 00:08:38,940 Okay, so I call remove products 192 00:08:38,940 --> 00:08:40,410 on the product manager object. 193 00:08:40,410 --> 00:08:43,980 It will call the delete method three times 194 00:08:43,980 --> 00:08:48,240 on my rest client, on my rest client manual mock. 195 00:08:48,240 --> 00:08:50,880 So I should see that, you know, 196 00:08:50,880 --> 00:08:54,720 when my mock version of the delete method is invoked 197 00:08:54,720 --> 00:08:56,520 basically when this mock version, 198 00:08:56,520 --> 00:09:00,120 my mock version of delete is invoked three times, 199 00:09:00,120 --> 00:09:02,160 I should see this message appearing 200 00:09:02,160 --> 00:09:04,293 in the console when I run my test. 201 00:09:05,375 --> 00:09:06,723 So there we go. 202 00:09:07,740 --> 00:09:10,470 But first of all, it created the product manager, 203 00:09:10,470 --> 00:09:12,300 which created the rest client. 204 00:09:12,300 --> 00:09:14,820 And there's my mock rest client constructor. 205 00:09:14,820 --> 00:09:17,850 But here are the three calls to the delete function 206 00:09:17,850 --> 00:09:22,020 to delete product one o one, one o two, one o three. 207 00:09:22,020 --> 00:09:24,060 Okay, so right in manual mocks, 208 00:09:24,060 --> 00:09:28,020 gives you a chance to have some more substantive tests 209 00:09:28,020 --> 00:09:29,870 in your higher level, if you want to. 210 00:09:31,320 --> 00:09:33,213 Okay. What about this one? 211 00:09:34,170 --> 00:09:35,760 I've created the product manager, 212 00:09:35,760 --> 00:09:38,970 and I'm trying to get the stock account, right? 213 00:09:38,970 --> 00:09:40,260 Okay, so I need to remind you 214 00:09:40,260 --> 00:09:43,350 how the get stock count method works first. 215 00:09:43,350 --> 00:09:47,310 So in my product manager, get stock account. 216 00:09:47,310 --> 00:09:51,000 It gets all products from the rest client. 217 00:09:51,000 --> 00:09:55,020 That's going to invoke my mock version of get All. 218 00:09:55,020 --> 00:09:55,923 What does that do? 219 00:09:57,000 --> 00:10:00,720 The mock version of get All and basically returns. 220 00:10:00,720 --> 00:10:02,790 Well, first of all, it displays a message to say, 221 00:10:02,790 --> 00:10:05,880 hello, this is the manual mock version 222 00:10:05,880 --> 00:10:09,420 of the get All function, and it returns these products. 223 00:10:09,420 --> 00:10:14,340 So it mocks this return from rest service effectively. 224 00:10:14,340 --> 00:10:15,750 It's going to return, well,` 225 00:10:15,750 --> 00:10:18,690 I've got 10 pairs of skis in stock. 226 00:10:18,690 --> 00:10:20,700 I've got five boots in stock. 227 00:10:20,700 --> 00:10:23,040 Five pairs of boots, hopefully, and three goggles. 228 00:10:23,040 --> 00:10:26,310 So all together, if you add these stocks together, 229 00:10:26,310 --> 00:10:29,130 that's 18 products, isn't it? 230 00:10:29,130 --> 00:10:33,690 So when I call get stock level on those products, 231 00:10:33,690 --> 00:10:34,980 the result that should come back, 232 00:10:34,980 --> 00:10:37,413 it should say there are 18 products in stock. 233 00:10:38,820 --> 00:10:42,780 So when I call get stock count on that hard coded data, 234 00:10:42,780 --> 00:10:46,050 the result I get back for my get stock count should be 235 00:10:46,050 --> 00:10:48,810 based on that hard coded ski related data 236 00:10:48,810 --> 00:10:50,733 that there were 18 products in stock. 237 00:10:51,690 --> 00:10:55,200 So call get stock count on product manager. 238 00:10:55,200 --> 00:10:57,390 It calls the rest client. 239 00:10:57,390 --> 00:10:59,973 The rest client returns those three products, 240 00:11:01,402 --> 00:11:02,790 totaled 18 in stock. 241 00:11:02,790 --> 00:11:04,050 We verify that the, 242 00:11:04,050 --> 00:11:06,600 my stock count method has worked properly. 243 00:11:06,600 --> 00:11:08,400 Now, I actually found my test quite handy here 244 00:11:08,400 --> 00:11:10,590 because when I was writing my get stock count method 245 00:11:10,590 --> 00:11:14,970 originally, I basically got the algorithm run. 246 00:11:14,970 --> 00:11:17,580 So my unit test actually helped me to realize 247 00:11:17,580 --> 00:11:20,820 that I'd implemented my get stock count method incorrectly. 248 00:11:20,820 --> 00:11:23,940 So unit testing actually helped me to write this demo 249 00:11:23,940 --> 00:11:26,280 which is quite ironic, I thought. 250 00:11:26,280 --> 00:11:28,530 So we can run that test. 251 00:11:28,530 --> 00:11:31,890 And of course it works and it shows 252 00:11:31,890 --> 00:11:36,890 that my get all method was invoked in my mock API. 253 00:11:36,900 --> 00:11:40,740 I mean, that's just there for proof of concept, really. 254 00:11:40,740 --> 00:11:42,810 The main thing is that it be turned 18 255 00:11:42,810 --> 00:11:44,643 from my get stock count method. 256 00:11:45,930 --> 00:11:49,017 So three additional tests in the test suite, 257 00:11:49,017 --> 00:11:51,330 the get stock value. 258 00:11:51,330 --> 00:11:53,580 What we just saw was the get the stock count. 259 00:11:53,580 --> 00:11:55,770 There's also a test to get the stock value. 260 00:11:55,770 --> 00:11:58,983 You know, the total value in pounds of my stock. 261 00:12:00,060 --> 00:12:03,750 To get the price of a product with a valid ID, 262 00:12:03,750 --> 00:12:06,930 and to get the price of a product with an invalid ID. 263 00:12:06,930 --> 00:12:08,700 Okay, so let's take a quick look at 264 00:12:08,700 --> 00:12:12,213 how those tests work is gonna be the same idea as before. 265 00:12:13,335 --> 00:12:18,335 So in my test, let's spool down. 266 00:12:18,780 --> 00:12:23,760 So this method here get stock value works. 267 00:12:23,760 --> 00:12:25,230 Create the product manager, 268 00:12:25,230 --> 00:12:28,110 which creates a dummy rest client. 269 00:12:28,110 --> 00:12:31,650 When I say, get stock value, get stock value. 270 00:12:31,650 --> 00:12:33,780 Well, the first thing that get stock value does 271 00:12:33,780 --> 00:12:35,820 is to get all products. 272 00:12:35,820 --> 00:12:36,653 Okay? 273 00:12:36,653 --> 00:12:40,530 And as we know in our mock version of get all products, 274 00:12:40,530 --> 00:12:42,060 it returns these products here. 275 00:12:42,060 --> 00:12:45,030 And if you actually add the numbers together, 276 00:12:45,030 --> 00:12:48,330 if I've got 500 skis at 10, sorry, 277 00:12:48,330 --> 00:12:52,110 10 skis at 500 each, that's 5,000 pounds. 278 00:12:52,110 --> 00:12:55,260 I've got five boots of 200, that's another thousand. 279 00:12:55,260 --> 00:12:59,340 So that's 6,000 total plus three times a hundred. 280 00:12:59,340 --> 00:13:03,450 So that should be the total value should be 6,300. 281 00:13:03,450 --> 00:13:06,240 From that stock that gets returned, 282 00:13:06,240 --> 00:13:10,290 from my get All method when it returns those products. 283 00:13:10,290 --> 00:13:12,300 When it returns those products there, 284 00:13:12,300 --> 00:13:15,630 in my algorithm to calculate the total stock value. 285 00:13:15,630 --> 00:13:18,723 I think the number should that come back as 6,300. 286 00:13:20,850 --> 00:13:24,600 Okay, so when I call get stock value, 287 00:13:24,600 --> 00:13:27,150 the result I should get back should be 6,300 288 00:13:27,150 --> 00:13:30,273 if my code in that method is correct. 289 00:13:32,190 --> 00:13:35,400 My product manager also has a get price of method. 290 00:13:35,400 --> 00:13:37,590 I give it an ID, and it'll tell me the price 291 00:13:37,590 --> 00:13:39,060 of that product. 292 00:13:39,060 --> 00:13:40,510 So let's have a look at that. 293 00:13:42,300 --> 00:13:45,390 Get price of, it takes an ID. 294 00:13:45,390 --> 00:13:48,903 It calls the get by ID method on rest client, 295 00:13:49,770 --> 00:13:54,360 which will either return a product or an exception. 296 00:13:54,360 --> 00:13:57,390 So if the ID is valid, 297 00:13:57,390 --> 00:14:01,390 it'll return the product there, basically. 298 00:14:03,690 --> 00:14:05,760 When the product is when the promise is resolved, 299 00:14:05,760 --> 00:14:07,800 that would be the product that I was looking for. 300 00:14:07,800 --> 00:14:10,113 Product one o one, I return the price. 301 00:14:11,430 --> 00:14:13,170 But if the idea is invalid, 302 00:14:13,170 --> 00:14:17,190 then it becomes a price of zero, indicating invalid product, 303 00:14:17,190 --> 00:14:18,990 I don't know the price. 304 00:14:18,990 --> 00:14:21,167 So let's get price method. 305 00:14:21,167 --> 00:14:24,390 If I give it a valid ID, it should return the price. 306 00:14:24,390 --> 00:14:27,420 If I give it an invalid ID, it should return zero. 307 00:14:27,420 --> 00:14:30,450 So my unit tests for both of those scenarios, 308 00:14:30,450 --> 00:14:34,290 if I pass in a valid ID, one o one is valid, 309 00:14:34,290 --> 00:14:36,330 it'll tell, and that's the skis, by the way, 310 00:14:36,330 --> 00:14:39,150 it should give me back a result of 500. 311 00:14:39,150 --> 00:14:41,730 If I pass in an invalid price 312 00:14:41,730 --> 00:14:43,430 and only follow the logic through, 313 00:14:44,385 --> 00:14:46,500 then that should result a zero to indicate that, 314 00:14:46,500 --> 00:14:48,300 you know, the product was invalid. 315 00:14:48,300 --> 00:14:51,870 So right then manual mocks takes a bit more effort. 316 00:14:51,870 --> 00:14:53,070 You know, you basically have to mock 317 00:14:53,070 --> 00:14:54,483 the methods of interest. 318 00:14:55,320 --> 00:14:58,715 But the benefit of doing it, is that you have some real data 319 00:14:58,715 --> 00:15:00,870 that you can then use in your higher level. 320 00:15:00,870 --> 00:15:04,920 I have some real data here that I've returned from get All. 321 00:15:04,920 --> 00:15:07,860 So in my high level code that I'm testing, 322 00:15:07,860 --> 00:15:09,480 when I say get All, 323 00:15:09,480 --> 00:15:12,360 I've got some real data with real numbers 324 00:15:12,360 --> 00:15:16,436 that I can test my algorithm on to see if it works. 325 00:15:16,436 --> 00:15:20,310 So sometimes it's too much effort 326 00:15:20,310 --> 00:15:22,200 to define these mock classes. 327 00:15:22,200 --> 00:15:25,413 But I think in this case, it's actually proved it's worth.