public void TheWidgetShouldBePersisted() { //Arrange var value = new DomainWidget { Name = "Test Widget", Description = "A test widget", Manufacturer = "Radix2" }; var mockRepository = new Mock<IRepository>(); mockRepository .Setup(x => x.Create(It.IsAny<Widget>())); var widgetService = new WidgetService(mockRepository.Object); //Act widgetService.Post(value); //Assert mockRepository.Verify(v=>v.Create(It.IsAny<Widget>())); }
public void TheServiceShouldThrowAnExceptionIfWidgetModelIsNotValid() { //Arrange var mockRepository = new Mock<IRepository>(); mockRepository .Setup(x => x.Create(It.IsAny<Widget>())) .Throws(new Exception()); var mockWidgetService = new WidgetService(mockRepository.Object); //Act mockWidgetService.Post(new Domain.Models.Widgets.Widget()); //Assert }