Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.9 kB
4
Indexable
Never
         [Test]
        [TestCase("pavan","pavan@123")]
        [TestCase("sjfa","sdfg")]
        [TestCase("bharadwaj","bharadwaj@123")]
        [TestCase("1234", "1234@123")]
        public async Task Test(string Username,string Password)
        {
            try{
            //Arrange
            var Dbcontext = new Mock<TemplateContext>();
            var mockrepo = new Mock<IRepo>(Dbcontext.Object);
            var vaildUser = new Login {AdminId = 1 ,Username = "bharadwaj" , Password = "bharadwaj@123", AdminAccess = true};
            var vaildAdmin = new Login {AdminId = 2,Username = "pavan" , Password = "pavan@123" , AdminAccess = false };
            var invalidLogin = new Login { AdminId = 3, Username = "1234", Password = "1234@123", AdminAccess = false };
            mockrepo.Setup(repo => repo.ValidateUser(vaildAdmin.Username,vaildAdmin.Password)).ReturnsAsync("Admin");
            mockrepo.Setup(repo => repo.ValidateUser(vaildUser.Username,vaildUser.Password)).ReturnsAsync("user");
            mockrepo.Setup(repo => repo.ValidateUser(invalidLogin.Username, invalidLogin.Password)).Throws(new Exception("error"));
            //Act
            //var repo = new IRepo(mockrepo.Object);
            IRepo IRepo = new IRepo();
            var temp = await IRepo.ValidateUser(Username,Password);
            //Assert
            Console.WriteLine(temp);
            
            switch(temp){
                
                case "admin":
                case "users" :
                case null :
                    Assert.Pass();
                    break;
                default:
                    Assert.Fail();
                    break;
            }
        }
        catch(Exception er){
            Console.WriteLine(er.Message);
            Assert.Pass();
        }
        }
Leave a Comment