public void PostShouldValidateModelStateByIvo() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Post(TestObjectFactory.GetInvalidModel())) .ShouldHave() .InvalidModelState(); }
public void TestAuthorizedAttribute() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor <IProjectsService>(TestObjectFactory.GetProjectsService()) .Calling(c => c.Get()) .ShouldHave() .ActionAttributes(a => a.RestrictingForAuthorizedRequests()); }
public void GetShouldHaveCorsEnabled() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Get()) .ShouldHave() .ActionAttributes(attr => attr.ContainingAttributeOfType <EnableCorsAttribute>()); }
public void PostShouldReturnBadRequestWithInvalidModelByIvo() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor <IProjectsService>(TestObjectFactory.GetProjectsService()) .Calling(c => c.Get()) .ShouldReturn() .Ok() .WithResponseModelOfType <List <SoftwareProjectDetailsResponseModel> >(); }
public void GetShouldReturnNotFoundWhenProjectIsNull() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .WithAuthenticatedUser() .Calling(c => c.Get(0)) .ShouldReturn() .NotFound(); }
public void GetByIdShouldReturnBadRequestWithNullId() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Get(null)) .ShouldReturn() .BadRequest() .WithErrorMessage("Project name cannot be null or empty."); }
public void PostShouldReturnBadRequestWithInvalidModel() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Post(TestObjectFactory.GetInvalidModel())) .ShouldReturn() .BadRequest() .WithModelStateFor <SaveProjectRequestModel>() .ContainingModelStateErrorFor(m => m.Name); }
public void GetShouldReturnOkWithProperResponse() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Get()) .ShouldReturn() .Ok() .WithResponseModelOfType <List <SoftwareProjectDetailsResponseModel> >() .Passing(pr => pr.Count == 1); }
public void PostShouldReturnBadRequestWithInvalidModel() { var controller = new ProjectsController(TestObjectFactory.GetProjectsService()); controller.Configuration = new HttpConfiguration(); var model = TestObjectFactory.GetInvalidModel(); controller.Validate(model); var result = controller.Post(model); Assert.AreEqual(typeof(InvalidModelStateResult), result.GetType()); }
public void PostShouldValidateModelState() { var controller = new ProjectsController(TestObjectFactory.GetProjectsService()); controller.Configuration = new HttpConfiguration(); var model = TestObjectFactory.GetInvalidModel(); controller.Validate(model); var result = controller.Post(model); Assert.IsFalse(controller.ModelState.IsValid); }
public void GetShouldReturnOkWhenProjectIsNotNull() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .WithAuthenticatedUser() .Calling(c => c.Get("Valid")) .ShouldReturn() .Ok() .WithResponseModelOfType <SoftwareProjectDetailsResponseModel>() .Passing(pr => { Assert.AreEqual(new DateTime(2015, 11, 5, 23, 47, 12), pr.CreatedOn); Assert.AreEqual("Test", pr.Name); Assert.AreEqual(0, pr.TotalUsers); }); }
public void PostShouldValidateModelState() { MyWebApi .Controller <ProjectsController>() .WithResolvedDependencyFor(TestObjectFactory.GetProjectsService()) .Calling(c => c.Post(TestObjectFactory.GetInvalidModel())) .ShouldHave() .InvalidModelState(); //var controller = new ProjectsController(TestObjectFactory.GetProjectsService()); //controller.Configuration = new HttpConfiguration(); //var model = TestObjectFactory.GetInvalidModel(); //controller.Validate(model); //var result = controller.Post(model); //Assert.IsFalse(controller.ModelState.IsValid); }
public void Init() { this.controller = MyWebApi .Controller <ProjectsController>() .WithResolvedDependencies(TestObjectFactory.GetProjectsService()); }