Example #1
0
        public async Task testAddUserwithNoPassword()
        {
            using (var context = new LanguageAPIContext(options))
            {
                //Given
                UserInfo user = new UserInfo()
                {
                    username = "******",
                    password = ""
                };
                //When
                UserInfoController userInfoController = new UserInfoController(context);
                IActionResult      result             = await userInfoController.RegisterUser(user);

                var userExists = await context.UserInfo.Where(u =>
                                                              u.username == user.username
                                                              ).AnyAsync();

                var dbUser = await context.UserInfo.Where(u =>
                                                          u.username == user.username
                                                          ).FirstOrDefaultAsync();

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(UnprocessableEntityResult));
                Assert.IsTrue(!userExists);

                Assert.IsNull(dbUser);


                context.SaveChanges();
            }
        }
Example #2
0
        public async Task testRegisterExistingUser()
        {
            using (var context = new LanguageAPIContext(options)){
                //Given
                UserInfo user = new UserInfo()
                {
                    username = "******",
                    password = "******"
                };

                //When
                UserInfoController userInfoController = new UserInfoController(context);
                IActionResult      result             = await userInfoController.RegisterUser(user);

                //Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ConflictResult));

                var userList = await context.UserInfo.Where(l => l.username == user.username).ToListAsync();

                Assert.AreEqual(1, userList.Count);
            }
        }