Пример #1
0
        public void CreatePatron()
        {
            var newPatron = new Patron
            {
                FirstName = "TestUser",
                LastName = "TestUser",
                DateOfBirth = DateTime.Now
            };

            var req = new HttpRequestMessage();
            //req.SetOwinContext(new OwinContext());
            var patronController = new PatronController {Request = req};
            //var accountController = new AccountController() { Request = new HttpRequestMessage(), UserManager = req.GetOwinContext().GetUserManager<ApplicationUserManager>() };
            patronController.Request.SetConfiguration(new HttpConfiguration());
            /*accountController.Request.SetConfiguration(new HttpConfiguration());
            accountController.Create(new RegisterBindingModel
            {
                Email = "potato",
                Password = "******",
                ConfirmPassword = "******"
            });*/

            var response = patronController.Create(newPatron);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.Created, "Patron not created.");
        }
Пример #2
0
        public HttpResponseMessage Create(Patron patron)
        {
            ApiResponse response = new ApiResponse(Request);
            try
            {
                var patronContext = new Database();
                patronContext.Patrons.Add(patron);
                patronContext.SaveChanges();

                response.data = response.DefaultSuccessResponse;
                return response.GenerateResponse(HttpStatusCode.Created);
            }
            catch(Exception e)
            {
                response.errors.Add(new InvalidPatron { source = e });
                return response.GenerateResponse(HttpStatusCode.BadRequest);
            }
        }