public ActionResult DeleteConfirmed(int id) { TestUserModel testModel = dbServices.Find(id); dbServices.Remove(testModel); return(RedirectToAction("Index")); }
public static string CompareUserProfiles(TestUserModel expected, TestUserModel actual) { var result = new StringBuilder(); if (!String.Equals(expected.Email, actual.Email)) { result.Append($"Users have different emails: '{expected.Email}' != '{actual.Email}'\n"); } if (!String.Equals(expected.FirstName, actual.FirstName)) { result.Append($"Users have different first names: '{expected.FirstName}' != '{actual.FirstName}'\n"); } if (!String.Equals(expected.LastName, actual.LastName)) { result.Append($"Users have different last names: '{expected.LastName}' != '{actual.LastName}'\n"); } if (actual.Id == null || Equals(actual.Id, String.Empty)) { result.Append("Actual profile should have id, but it was null or empty\n"); } if (actual.Password != null) { result.Append($"Actual profile should have null password, but it was '{actual.Password}'\n"); } return(result.ToString()); }
public void TestSmokeForNewUserMe() { var userModel = new TestUserModel() { Email = $"{TestStringHelper.RandomLatinString()}@example.com", Password = TestStringHelper.RandomLatinString(), FirstName = TestStringHelper.RandomLatinString(), LastName = TestStringHelper.RandomLatinString(), }; Given .NewUserData(userModel) .UserLoginCredentials(new TestLoginModel { Email = userModel.Email, Password = userModel.Password, }) .When .CreateUserRequestIsSend() .LoginRequestIsSend() .GetCurrentUserRequestIsSend() .Then .CurrentUserIsEqualTo(userModel) .LogoutIfSessionTokenIsPresent(); }
public void TestSmokeCreateNewProfile() { var profile = new TestUserModel { Email = $"{TestStringHelper.RandomLatinString()}@example.com", Password = TestStringHelper.RandomLatinString(), FirstName = TestStringHelper.RandomLatinString(), LastName = TestStringHelper.RandomLatinString(), }; Given .NewUserData(profile) .When .CreateUserRequestIsSend() .Then .LastRequestSuccessful(); Given .UserLoginCredentials(new TestLoginModel { Email = profile.Email, Password = profile.Password }) .When .LoginRequestIsSend() .GetCurrentUserRequestIsSend() .Then .CurrentUserIsEqualTo(profile) .LogoutIfSessionTokenIsPresent(); }
public void InitTestUser() { var facade = new ProfileApiFacade( Logger, Configuration.RootUrl); var testUser = new TestUserModel { Email = Configuration.UserName, Password = Configuration.Password, }; var response = facade.PostCreateNewProfile(testUser); if (response.StatusCode == HttpStatusCode.Conflict) { return; } if (response.StatusCode == HttpStatusCode.Created) { Assert.IsEmpty(ProfileHelper.CompareUserProfiles(testUser, response.Map <TestUserModel>())); return; } Assert.Fail("Test user was not created"); }
public static GivenStatement NewUserData(this GivenStatement givenStatement, TestUserModel userModel, string testKey = null) { givenStatement.GetStatementLogger() .Information($"[{{ContextStatement}}] Saving user model {userModel}", givenStatement.GetType().Name); givenStatement.AddData(userModel, testKey); return(givenStatement); }
public static void Add(TestUserModel testModel) { using (var context = new TestContext()) { context.Users.Add(testModel); context.SaveChanges(); } }
public static void Remove(TestUserModel testModel) { using (var context = new TestContext()) { context.Users.Attach(testModel); context.Users.Remove(testModel); context.SaveChanges(); } }
public void BaseNegativeCreateUserTest(TestUserModel profile) { Given .NewUserData(profile) .When .CreateUserRequestIsSend() .Then .ResponseHasCode(HttpStatusCode.BadRequest); }
public static void Edit(TestUserModel testModel, int id) { using (var context = new TestContext()) { testModel.UserID = id; context.Entry(testModel).State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Create([Bind(Include = "UserID,first_name,last_name")] TestUserModel testModel) { if (ModelState.IsValid) { dbServices.Add(testModel); dbServices.Save(); return(RedirectToAction("Index")); } return(View(testModel)); }
public ActionResult Edit([Bind(Include = "UserID,first_name,last_name")] TestUserModel testModel) { if (ModelState.IsValid) { var id = testModel.UserID; dbServices.Edit(testModel, id); return(RedirectToAction("Index")); } return(View(testModel)); }
// // GET: /Default1/Edit/5 public ActionResult Edit(int Id) { TestDbEntities obj = new TestDbEntities(); var data = obj.TblTests.FirstOrDefault(x => x.ID == Id); var model = new TestUserModel() { Id = data.ID, Name = data.Name, Address = data.Address }; return(View(model)); }
public HttpResponseMessage PostCreateNewProfile(TestUserModel user) { using (HttpClient client = HttpClientFactory.Create()) { client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue(CommonHttpConstants.ApplicationJsonMedia)); return(client.LogAndPost($"{BaseApiRoute}", new StringContent(user.ToString(), Encoding.UTF8, CommonHttpConstants.ApplicationJsonMedia), Logger)); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TestUserModel testModel = dbServices.Find(id); if (testModel == null) { return(HttpNotFound()); } return(View(testModel)); }
public void TestSaveUser() { var model = new TestUserModel { Id = 42, Username = "******", Email = "*****@*****.**", CreatedAt = new LocalDateTime(2020, 02, 29, 13, 37, 42) }; string sql = Query() .InsertInto("user") .InsertFrom(model) .ToParameterizedSql(); sql.Should().Be("insert into user (id, username, email, created_at) values (42, @0, @1, @2)"); }
public void TestCreateNewProfileWithGuid() { var profile = new TestUserModel { Email = $"{Guid.NewGuid().ToString()}@example.com", Password = Guid.NewGuid().ToString(), FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString(), }; Given .NewUserData(profile) .When .CreateUserRequestIsSend() .Then .ResponseHasCode(HttpStatusCode.BadRequest); }
public ActionResult Create(TestUserModel model) { try { TestDbEntities obj = new TestDbEntities(); TblTest tbl = new TblTest(); tbl.Address = model.Address; tbl.Name = model.Name; obj.TblTests.AddObject(tbl); obj.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(TestUserModel model) { try { TestDbEntities obj = new TestDbEntities(); // TODO: Add update logic here TblTest data = obj.TblTests.FirstOrDefault(x => x.ID == model.Id); data.Name = model.Name; data.Address = model.Address; obj.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public void BasePositiveCreateUserTest(TestUserModel profile) { Given .NewUserData(profile) .When .CreateUserRequestIsSend() .Then .LastRequestSuccessful(); Given .UserLoginCredentials(new TestLoginModel { Email = profile.Email, Password = profile.Password }) .When .LoginRequestIsSend() .GetCurrentUserRequestIsSend() .Then .CurrentUserIsEqualTo(profile) .LogoutIfSessionTokenIsPresent(); }
public static ThenStatement CurrentUserIsEqualTo(this ThenStatement thenStatement, TestUserModel expectedUser) { thenStatement.GetStatementLogger() .Information("[{ContextStatement}] Comparing 'GetMe' response with expected user model", thenStatement.GetType().Name); var currentUser = thenStatement.GetResultData <TestUserModel>(BddKeyConstants.CurrentUserResponse); Assert.IsEmpty(ProfileHelper.CompareUserProfiles(expectedUser, currentUser)); return(thenStatement); }
// // GET: /Default1/Create public ActionResult Create() { var model = new TestUserModel(); return(View(model)); }