Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            TestUserModel testModel = dbServices.Find(id);

            dbServices.Remove(testModel);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 public static void Add(TestUserModel testModel)
 {
     using (var context = new TestContext())
     {
         context.Users.Add(testModel);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public static void Remove(TestUserModel testModel)
 {
     using (var context = new TestContext())
     {
         context.Users.Attach(testModel);
         context.Users.Remove(testModel);
         context.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public void BaseNegativeCreateUserTest(TestUserModel profile)
 {
     Given
     .NewUserData(profile)
     .When
     .CreateUserRequestIsSend()
     .Then
     .ResponseHasCode(HttpStatusCode.BadRequest);
 }
Exemplo n.º 10
0
 public static void Edit(TestUserModel testModel, int id)
 {
     using (var context = new TestContext())
     {
         testModel.UserID = id;
         context.Entry(testModel).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
 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));
 }
Exemplo n.º 13
0
        //
        // 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));
        }
Exemplo n.º 14
0
        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));
            }
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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)");
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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());
            }
        }
Exemplo n.º 19
0
        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());
            }
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        //
        // GET: /Default1/Create

        public ActionResult Create()
        {
            var model = new TestUserModel();

            return(View(model));
        }