Exemplo n.º 1
0
        public IHttpActionResult CreateApartment(ApartmentBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Cad.CreateApartment(model.Level, model.Number, model.TenantsAllowed, model.FacingDirection,
                                    User.Identity.GetUserId());
            }
            catch (ConnectedApartmentsException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
            return(GetResponse());
        }
Exemplo n.º 2
0
        public CreateApartmentTests()
        {
            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 ApartmentBindingModel()
            {
                FacingDirection = "North", Level = "3", Number = "1", TenantsAllowed = 2
            };

            controllerContext = new HttpControllerContext {
                RequestContext = { Principal = principal.Object }
            };
        }