public void SetViewsSuccessMessageVisibilityAndText() { var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IBreweryUpdateEventArgs>(); var result = new Mock <IDataModifiedResult>(); result.Setup(r => r.Successful).Returns(true); var service = new Mock <IBreweryService>(); service.Setup(s => s.UpdateBrewery(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(result.Object); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.BreweryUpdate += null, view.Object, args.Object); view.VerifySet(v => v.SuccessMessageText = It.IsAny <string>(), Times.Once); view.VerifySet(v => v.SuccessMessageVisible = true, Times.Once); }
public void CatchExceptionAndSetViewsErrorMessageCorrectly() { var expectedMessage = this.Fixture.Create <string>(); var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IBreweryUpdateEventArgs>(); var result = new Mock <IDataModifiedResult>(); result.Setup(r => r.Errors).Returns(new[] { expectedMessage }); result.Setup(r => r.Successful).Returns(false); var service = new Mock <IBreweryService>(); service.Setup(s => s.UpdateBrewery(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(result.Object); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.BreweryUpdate += null, view.Object, args.Object); view.VerifySet(v => v.ErrorMessageText = expectedMessage, Times.Once); view.VerifySet(v => v.ErrorMessageVisible = true, Times.Once); }
public void CallUpdateBreweryMethodOnceWithCorrectParams() { var expectedId = this.Fixture.Create <int>(); var expectedName = this.Fixture.Create <string>(); var expectedDescr = this.Fixture.Create <string>(); var expectedCountry = this.Fixture.Create <string>(); var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IBreweryUpdateEventArgs>(); args.Setup(a => a.Id).Returns(expectedId); args.Setup(a => a.Description).Returns(expectedDescr); args.Setup(a => a.Country).Returns(expectedCountry); args.Setup(a => a.Name).Returns(expectedName); var result = new Mock <IDataModifiedResult>(); result.Setup(r => r.Successful).Returns(true); var service = new Mock <IBreweryService>(); service.Setup(s => s.UpdateBrewery(expectedId, expectedName, expectedCountry, expectedDescr)) .Returns(result.Object); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.BreweryUpdate += null, view.Object, args.Object); service.Verify(s => s.UpdateBrewery(expectedId, expectedName, expectedCountry, expectedDescr), Times.Once); }
public void SetViewModelProperties_WhenServiceFindsBrewery() { var expectedBrewery = new Mock <IBrewery>(); var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var expectedId = this.Fixture.Create <int>().ToString(); var args = new Mock <IIdentifiableEventArgs <string> >(); args.Setup(a => a.Id).Returns(expectedId); var service = new Mock <IBreweryService>(); service.Setup(s => s.GetById(It.IsAny <object>())) .Returns(expectedBrewery.Object); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.Initialized += null, view.Object, args.Object); Assert.AreSame(expectedBrewery.Object, viewModel.Brewery); }
public void ShowErrors_ServiceDoesNotFindBrewery() { var expectedId = this.Fixture.Create <int>().ToString(); var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IIdentifiableEventArgs <string> >(); args.Setup(a => a.Id).Returns(expectedId); var service = new Mock <IBreweryService>(); service.Setup(s => s.GetById(It.IsAny <object>())) .Returns((IBrewery)null); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.Initialized += null, view.Object, args.Object); view.VerifySet(v => v.ErrorMessageText = It.IsAny <string>(), Times.Once); view.VerifySet(v => v.ErrorMessageVisible = true, Times.Once); }
public void CallServiceGetByIdMethodOnceWithCorrectParams_WhenIdIsValid() { var expectedId = this.Fixture.Create <int>().ToString(); var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IIdentifiableEventArgs <string> >(); args.Setup(a => a.Id).Returns(expectedId); var service = new Mock <IBreweryService>(); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.Initialized += null, view.Object, args.Object); service.Verify(s => s.GetById(int.Parse(expectedId)), Times.Once); }
public void ShowErrors_WhenIdIsInvalid() { var viewModel = new MockedSingleBreweryViewModel(); var view = new Mock <ISingleBreweryView>(); view.Setup(v => v.Model) .Returns(viewModel); var args = new Mock <IIdentifiableEventArgs <string> >(); args.Setup(a => a.Id).Returns("thisshouldalwaysbeinvalidID" + this.Fixture.Create <string>()); var service = new Mock <IBreweryService>(); var presenter = new BreweryPresenter(service.Object, view.Object); view.Raise(v => v.Initialized += null, view.Object, args.Object); view.VerifySet(v => v.ErrorMessageText = It.IsAny <string>(), Times.Once); view.VerifySet(v => v.ErrorMessageVisible = true, Times.Once); }