protected void VerifyPropSet(string vmPropName, string breweryPropName)
        {
            Brewery brewery = Models.Brewery();
            BreweryDetailsViewModel vmUT = new BreweryDetailsViewModel(brewery);

            vmUT.GetType().GetProperty(vmPropName).GetValue(vmUT).ShouldEqual(brewery.GetType().GetProperty(breweryPropName).GetValue(brewery));
        }
Example #2
0
        public void ReturnCorrectResult_WhenUpdateIsSuccessful()
        {
            // Arrange
            var sut        = this.MockingKernel.Get <BreweriesController>();
            var model      = new EditBreweryBindingModel();
            var expected   = new BreweryDetailsViewModel();
            var dataResult = new Mock <IDataModifiedResult>();

            dataResult.Setup(r => r.Successful)
            .Returns(true);
            var breweryService = this.MockingKernel.GetMock <IBreweryService>();

            breweryService.Setup(s => s.UpdateBrewery(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(dataResult.Object);
            var mapper = this.MockingKernel.GetMock <IMapper>();

            mapper.Setup(m => m.Map <IBrewery, BreweryDetailsViewModel>(It.IsAny <IBrewery>()))
            .Returns(expected);

            // Act
            var result = sut.Details(model) as PartialViewResult;

            // Assert
            Assert.IsNotNull(result);
            StringAssert.Contains("_Details", result.ViewName);
            var actual = result.Model as BreweryDetailsViewModel;

            Assert.AreSame(expected, actual);
        }
Example #3
0
        public override void Execute(InvokerArgs args)
        {
            BreweryDetailsViewModel VM = (args as ViewModelInvokerArgs).ViewModelAs <BreweryDetailsViewModel> ();

            WebService.BeersReceived += (object sender, EventArgs e) => {
                VM.Beers = new ObservableCollection <Beer> ((e as BeersReceivedEventArgs).Beers);
                VM.Ready = true;
            };
            WebService.Execute(VM.BreweryShortname);
        }
        protected void VerifyActionInclusion(string action, string propName)
        {
            Brewery brewery = Models.Brewery();
            BreweryDetailsViewModel vmUT = new BreweryDetailsViewModel(brewery);

            vmUT.Actions.ShouldContain(action);

            brewery.GetType().GetProperty(propName).SetValue(brewery, null);
            vmUT = new BreweryDetailsViewModel(brewery);
            vmUT.Actions.ShouldNotContain(action);

            brewery.GetType().GetProperty(propName).SetValue(brewery, "");
            vmUT = new BreweryDetailsViewModel(brewery);
            vmUT.Actions.ShouldNotContain(action);
        }
Example #5
0
        public void Setters_ShouldSetPropertiesCorrectly()
        {
            // Arrange
            var sut         = new BreweryDetailsViewModel();
            var createModel = new Mock <CreateBeerBindingModel>();
            var editModel   = new Mock <EditBreweryBindingModel>();
            var beers       = new List <Beer>();

            // Act
            sut.CreateModel = createModel.Object;
            sut.EditModel   = editModel.Object;
            sut.Beers       = beers;

            // Assert
            Assert.AreSame(beers, sut.Beers);
            Assert.AreSame(createModel.Object, sut.CreateModel);
            Assert.AreSame(editModel.Object, sut.EditModel);
        }
Example #6
0
        public void Return_CorrectViewResult_WhenRequestIsNotAjax()
        {
            // Arrange
            var expectedModel = new BreweryDetailsViewModel();
            var sut           = this.MockingKernel.Get <BreweriesController>(RegularContextName);
            var mapper        = this.MockingKernel.GetMock <IMapper>();

            mapper.Setup(m => m.Map <IBrewery, BreweryDetailsViewModel>(It.IsAny <IBrewery>()))
            .Returns(expectedModel);

            // Act
            var result = sut.Details(It.IsAny <int>()) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            var actual = result.Model as BreweryDetailsViewModel;

            Assert.AreSame(expectedModel, actual);
            Assert.AreEqual(string.Empty, result.ViewName);
        }
 public void Init()
 {
     TestBrewery = Models.Brewery();
     ViewModelUT = new BreweryDetailsViewModel(TestBrewery);
 }