Monday, April 24, 2017

Upgrading Angular CLI to version 4

I have only just started using Angular 2 so it isn't a huge burden to go straight to version 4. If you have the CLI then Yakov Fain has a good and short set of instructions on removing the existing version and installing v.4. Which worked for me:

https://yakovfain.com/2017/02/05/upgrading-to-the-latest-angular-cli/

I'm not enough of a user to know if the '@' symbol is always needed but the following three command lines seem to do the trick

ng uninstall @angular/cli -g
ng cache clean
ng install @angular/cli -g

Wednesday, February 22, 2017

cannot convert from 'Moq.Mock<IOrderDataService>' to 'IOrderDataService'

As a way of trying to solidify (no pun intended) test driven development in my head, I have been following along the Telerik blog
"Thirty Days of TDD Day 12: working with stubs"
www.telerik.com/blogs/30-days-of-tdd-day-12-working-with-stubs
I already have a couple of Mocking frameworks installed and I'm sure JustMock is great but my registry is messed up enough already so
I thought I'd translate to Moq and see how I went.
Wehn I try to run the tests I can the very obscure error


Error    2    Argument 1: cannot convert from 'Moq.Mock'<TddStore.Core.IOrderDataService>' to 'TddStore.Core.IOrderDataService'

apparently this is a fairly common Moq beginner error and posting the error here in case it will save somebody a few minutes


              var orderDataService = new Mock();
              orderDataService.Setup(x => x.Save(It.IsAny())).Returns(expectedOrderId);

              var orderService = new OrderService(orderDataService);


and instead it should be
var orderService = new OrderService(orderDataService.Object);

As always Stack Overlow saved the day, once I figured out how to word a search

http://stackoverflow.com/questions/7011572/passing-moq-mock-objects-to-constructor