public IHttpActionResult CreateFacility(FacilityRegisterModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Cad.CreateFacility(User.Identity.GetUserId(), model.Level, model.Number); } catch (ConnectedApartmentsException e) { return(BadRequest(e.Message)); } catch (Exception) { return(InternalServerError()); } return(GetResponse()); }
public CreateFacilityTests() { facade = new Mock <IFacade>(); var username = "******"; var identity = new GenericIdentity(username, ""); var nameIdentityClaim = new Claim(ClaimTypes.NameIdentifier, username); identity.AddClaim(nameIdentityClaim); var principal = new Mock <IPrincipal>(); principal.Setup(p => p.Identity).Returns(identity); principal.Setup(p => p.IsInRole("Tenant")).Returns(true); model = new FacilityRegisterModel() { Level = "3", Number = "1" }; controllerContext = new HttpControllerContext { RequestContext = { Principal = principal.Object } }; }