public void BrewariesController_GetAll() { BreweriesController controller = new BreweriesController(new FakeRepositories.FakeBrewaryRepository()); ViewResult result = controller.Index() as ViewResult; Assert.IsNotNull(result); }
public void ShouldGiveHttpNotFoundWhenIdNotExistsDelete() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); sut.WithCallTo(x => x.Delete(1)).ShouldGiveHttpStatus(HttpStatusCode.NotFound); }
public void ShouldGiveBadRequestErrorWhenIdIsNullEdit() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); sut.WithCallTo(x => x.Edit(null as int?)).ShouldGiveHttpStatus(HttpStatusCode.BadRequest); }
public void ShouldGiveBreweryWhenIdExists() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); fakeRepository.Setup(x => x.GetById(2)).Returns(new Brewery { Name = "Aas" }); sut.WithCallTo(x => x.Details(2)) .ShouldRenderDefaultView() .WithModel<Brewery>(x => x.Name.Equals("Aas")); }
public void BrewariesController_AddAction() { BreweriesController controller = new BreweriesController(new FakeRepositories.FakeBrewaryRepository()); Brewery brew = new Brewery() { Name = "Sleeman", Address = "Oakville", YTDSales = 500, BreweryId = 5 }; System.Web.Mvc.RedirectToRouteResult result = controller.Create(brew) as System.Web.Mvc.RedirectToRouteResult; Assert.IsNotNull(result); }
public void BrewariesController_Edit() { BreweriesController controller = new BreweriesController(new FakeRepositories.FakeBrewaryRepository()); Brewery brew = new Brewery() { Name = "Molson", Address = "Toronto", YTDSales = 5030, BreweryId = 1 }; System.Web.Mvc.RedirectToRouteResult result = controller.Create(brew) as System.Web.Mvc.RedirectToRouteResult; System.Web.Mvc.RedirectToRouteResult edit = controller.Edit(brew) as System.Web.Mvc.RedirectToRouteResult; Assert.IsNotNull(result); Assert.IsNotNull(edit); }
public void TestInitialize() { mock = new Mock <IMockBreweryRepository>(); breweries = new List <Brewery> { new Brewery { BreweryId = 1, Name = "One", City = "Barrie", Url = "http://one.ca", Logo = "one.gif" }, new Brewery { BreweryId = 2, Name = "Two", City = "Barrie", Url = "http://two.ca", Logo = "two.gif" }, new Brewery { BreweryId = 2, Name = "Three", City = "Barrie", Url = "http://three.ca", Logo = "three.gif" } }; mock.Setup(m => m.Breweries).Returns(breweries.AsQueryable()); controller = new BreweriesController(mock.Object); }
public void BrewariesController_Delete() { BreweriesController controller = new BreweriesController(new FakeRepositories.FakeBrewaryRepository()); Brewery brew = new Brewery() { Name = "Molson", Address = "Toronto", YTDSales = 5030, BreweryId = 1 }; System.Web.Mvc.RedirectToRouteResult result = controller.Create(brew) as System.Web.Mvc.RedirectToRouteResult; System.Web.Mvc.RedirectToRouteResult deleteResult = controller.DeleteConfirmed(1) as System.Web.Mvc.RedirectToRouteResult; System.Web.Mvc.RedirectToRouteResult model = controller.Details(1) as System.Web.Mvc.RedirectToRouteResult; Assert.IsNotNull(result); Assert.IsNotNull(deleteResult); Assert.IsNull(model); }
public void ShouldRenderCreateView() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); sut.WithCallTo(x => x.Create()).ShouldRenderDefaultView(); }
public void ShouldRenderIndexViewAfterCreatingNewBrewery() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); sut.WithCallTo(x => x.Create(new Brewery())).ShouldRedirectToRoute(""); }
public void ShouldRenderEditViewWhenBreweryHasBeenEdited() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); fakeRepository.Setup(x => x.GetById(2)).Returns(new Brewery()); sut.WithCallTo(x => x.Edit(2)).ShouldRenderDefaultView(); }
public void ShouldRenderDefaultViewWhenInvalidModelState() { var fakeRepository = new Mock<IRepository<Brewery>>(); var sut = new BreweriesController(fakeRepository.Object); sut.ModelState.AddModelError("1", "Error"); sut.WithCallTo(x => x.Create(new Brewery())).ShouldRenderDefaultView(); }