Exemple #1
0
       public async Task<IHttpActionResult> Register(AccountBindingModel model)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (model == null || model.Email == null || model.Password == null)
                return BadRequest("Parameters cannot be null");

            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);
            
            if (!result.Succeeded)
                return BadRequest(result.Errors.Aggregate("", (current, error) => current + (error + ", ")));
            
            return Ok("ok");

        }
Exemple #2
0
        public async Task<IHttpActionResult> Delete(AccountBindingModel model)
        {

            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (model == null || model.Email == null || model.Password == null)
                return BadRequest("Parameters cannot be null");

          ApplicationUser user = await UserManager.FindAsync(model.Email, model.Password);

            if (user == null)
                return BadRequest("User not found");

            var result = await UserManager.DeleteAsync(user);

            if (!result.Succeeded)
              return BadRequest(result.Errors.Aggregate("", (current, error) => current + (error + ", ")));

            return Ok("ok");
        }
Exemple #3
0
        public void Delete()
        {

            var controller = InitController();

            CancellationTokenSource cs = new CancellationTokenSource();
            CancellationToken t = cs.Token;


            // Test 1
            var model = new AccountBindingModel { Email = "*****@*****.**", Password = "******" };
            var result = controller.Delete(model);
            var response = result.Result.ExecuteAsync(t).Result;
            var code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);

            // Test 2
            model = new AccountBindingModel { Email = "*****@*****.**", Password = "******" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            // if user was deleted BadRequest else OK
            Assert.IsTrue(HttpStatusCode.OK == code || HttpStatusCode.BadRequest == code);

           
            // Test 2
            model = new AccountBindingModel { Email = "*****@*****.**", Password = "" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);

            // Test 3
            model = new AccountBindingModel { Email = "", Password = "" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);

            // Test 4
            model = new AccountBindingModel { Email = "", Password = "******" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);

            // Test 5
            model = new AccountBindingModel { Email = "dd" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);
            var value = response.Content.ReadAsStringAsync().Result;
            Assert.IsTrue(value.Contains("Parameters cannot be null"));

            // Test 6
            model = new AccountBindingModel { Password = "******" };
            result = controller.Delete(model);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);
            value = response.Content.ReadAsStringAsync().Result;
            Assert.IsTrue(value.Contains("Parameters cannot be null"));

            // Test 7
            result = controller.Delete(null);
            response = result.Result.ExecuteAsync(t).Result;
            code = response.StatusCode;

            Assert.AreEqual(HttpStatusCode.BadRequest, code);
            value = response.Content.ReadAsStringAsync().Result;
            Assert.IsTrue(value.Contains("Parameters cannot be null"));


        }