Example #1
0
        public IHttpActionResult ChangeApartment(ChangeApartmentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Cad.ChangeApartment(model.UserId, model.ApartmentId);
            }
            catch (ConnectedApartmentsException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(GetResponse());
        }
        public ChangeApartmentTests()
        {
            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 ChangeApartmentModel()
            {
                ApartmentId = 2, UserId = "3445"
            };

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