public void TestUserViewModel_AddUser()
        {
            UsersViewModel model = new UsersViewModel(new UsersWindow());

            model.Add();
            model.IsNew                 = true;
            model.SelectedUser.Name     = "Unit Test";
            model.SelectedUser.Email    = "*****@*****.**";
            model.SelectedUser.Password = "******";
            model.Save();

            WarehouseDbContext ctx = new WarehouseDbContext();
            var user = ctx.Users.SingleOrDefault(u => u.Name == "Unit Test");

            Assert.AreNotEqual(null, user, "User added !");

            //remove unit test user
            ctx.Users.Remove(user);
            ctx.SaveChanges();
        }
Example #2
0
        public ActionResult Register(UsersViewModel request)
        {
            var user     = request.Save(db);
            var userJson = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(user);

            var httpRequest = WebRequest.CreateHttp("http://localhost:27433/api/session/CreateUser");

            httpRequest.Method = "POST";
            using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
            {
                streamWriter.Write(userJson);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }