public void AuthController_UpdateEmailId_IntegrationTest_AuthorizedServer() { //Arrange var username = "******"; RegisterModel registerModel = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Verified", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; EmailUpdateModel emailUpdateModel = new EmailUpdateModel { Email = "*****@*****.**" }; var expectedCode = "200"; var expectedMessage = "Email and username updated successfully"; //Insert test data var insert = TH.InsertRegiterModeldata(registerModel).Result; //Act var result = TH.GetAuthController().UpdateEmailId(emailUpdateModel, username) as Task <ActionResult>; var responseData = TH.DeserializedResponceData(result.Result.ToJson()); //Check updated data var updatedData = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", emailUpdateModel.Email), "Authentication", "Authentication").Result); //Assert Assert.IsNotNull(result.Result); Assert.AreEqual(responseData.Code, expectedCode); Assert.AreEqual(responseData.Message, expectedMessage); Assert.AreEqual(updatedData.Title, registerModel.Title); Assert.AreEqual(updatedData.FullName, registerModel.FullName); Assert.AreEqual(updatedData.UserName, emailUpdateModel.Email); Assert.AreEqual(updatedData.UserRole, registerModel.UserRole); Assert.AreEqual(updatedData.DialCode, registerModel.DialCode); Assert.AreEqual(updatedData.PhoneNumber, registerModel.PhoneNumber); Assert.AreEqual(updatedData.Email, emailUpdateModel.Email); Assert.AreEqual(updatedData.Password, registerModel.Password); Assert.AreEqual(updatedData.UserLocation, registerModel.UserLocation); Assert.AreEqual(updatedData.Status, registerModel.Status); Assert.AreEqual(updatedData.VerificationCode, registerModel.VerificationCode); //Delete inserted test data var checkData = MH.CheckForDatas("UserName", emailUpdateModel.Email, null, null, "Authentication", "Authentication"); if (checkData != null) { var delete = MH.DeleteSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", emailUpdateModel.Email), "Authentication", "Authentication"); } }
//[TestMethod] public void AuthController_RegisterVerification_IntegrationTest_AuthorizedServer() { //Arrange var username = "******"; var otp = "123456"; RegisterModel registerModel = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Registered", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; //Insert test data var insert = TH.InsertRegiterModeldata(registerModel).Result; //Act var result = TH.GetAuthController().RegisterVerification(username, otp) as ActionResult; var responseData = TH.DeserializedResponceData(result.ToJson()); //Check inserted data var insertedData = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication").Result); //Assert Assert.IsNotNull(result); Assert.AreEqual(insertedData.Title, registerModel.Title); Assert.AreEqual(insertedData.FullName, registerModel.FullName); Assert.AreEqual(insertedData.UserName, username); Assert.AreEqual(insertedData.UserRole, registerModel.UserRole); Assert.AreEqual(insertedData.DialCode, registerModel.DialCode); Assert.AreEqual(insertedData.PhoneNumber, registerModel.PhoneNumber); Assert.AreEqual(insertedData.Email, registerModel.Email); Assert.AreEqual(insertedData.Password, registerModel.Password); Assert.AreEqual(insertedData.UserLocation, registerModel.UserLocation); Assert.AreEqual(insertedData.Status, "Verified"); Assert.AreEqual(insertedData.OTPExp, registerModel.OTPExp); Assert.AreEqual(insertedData.VerificationCode, registerModel.VerificationCode); Assert.IsNull(insertedData.SocialId); Assert.AreEqual(insertedData.WrongAttemptCount, 0); //Delete inserted test data var checkData = MH.CheckForDatas("UserName", username, null, null, "Authentication", "Authentication"); if (checkData != null) { var delete = MH.DeleteSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication"); } }
public void AuthController_DeactivateAccount_IntegrationTest_AuthorizedServer() { //Arrange var username = "******"; var password = "******"; RegisterModel registerModel = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Verified", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; DeactivateAccountModel deactivateAccountModel = new DeactivateAccountModel { UserName = username, Password = password }; var expectedCode = "200"; var expectedMessage = "User Deactivated"; //Insert test data var insert = TH.InsertRegiterModeldata(registerModel).Result; //Act var result = TH.GetAuthController().DeactivateAccount(deactivateAccountModel) as ActionResult; var responseData = TH.DeserializedResponceData(result.ToJson()); //Check if user account is deactivated var checkData = MH.CheckForDatas("UserName", username, null, null, "Authentication", "Authentication"); //Assert Assert.IsNotNull(result); Assert.AreEqual(responseData.Code, expectedCode); Assert.AreEqual(responseData.Message, expectedMessage); Assert.IsNull(checkData); }
public void AuthController_ChangePasswordWhenLoggedIn_IntegrationTest_AuthorizedServer() { //Arrange var username = "******"; var oldPassword = "******"; var newPassword = "******"; RegisterModel registerModel = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Verified", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; ChangePasswordModel changePasswordModel = new ChangePasswordModel { UserName = username, OldPassword = oldPassword, NewPassword = newPassword }; bool checkPassword = false; var expectedCode = "200"; var expectedMessage = "Password Changed Successfully"; //Insert test data var insert = TH.InsertRegiterModeldata(registerModel).Result; //Act var result = TH.GetAuthController().ChangePasswordWhenLoggedIn(changePasswordModel) as ActionResult; var responseData = TH.DeserializedResponceData(result.ToJson()); //Check inserted data var insertedData = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication").Result); //Check updated password RegisterModel data = new RegisterModel { UserName = username, Password = newPassword }; if (passwordHasher.VerifyHashedPassword(data, insertedData.Password, newPassword).ToString() == "Success") { checkPassword = true; } //Assert Assert.IsNotNull(result); Assert.AreEqual(responseData.Code, expectedCode); Assert.AreEqual(responseData.Message, expectedMessage); Assert.AreEqual(insertedData.Title, registerModel.Title); Assert.AreEqual(insertedData.FullName, registerModel.FullName); Assert.AreEqual(insertedData.UserName, username); Assert.AreEqual(insertedData.UserRole, registerModel.UserRole); Assert.AreEqual(insertedData.DialCode, registerModel.DialCode); Assert.AreEqual(insertedData.PhoneNumber, registerModel.PhoneNumber); Assert.AreEqual(insertedData.Email, registerModel.Email); Assert.IsNotNull(insertedData.Password); Assert.AreEqual(insertedData.UserLocation, registerModel.UserLocation); Assert.AreEqual(insertedData.Status, registerModel.Status); Assert.IsNotNull(insertedData.VerificationCode); Assert.IsNull(insertedData.SocialId); Assert.AreEqual(checkPassword, true); //Delete inserted test data var checkData = MH.CheckForDatas("UserName", username, null, null, "Authentication", "Authentication"); if (checkData != null) { var delete = MH.DeleteSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication"); } }
//[TestMethod] public void AuthController_Login_IntegrationTest_AuthorizedServer() { //Arrange var username1 = "12341234"; var username2 = "*****@*****.**"; var password = "******"; RegisterModel registerModel1 = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username1, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Verified", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; RegisterModel registerModel2 = new RegisterModel { Title = "Mr", FullName = "SampleName", UserName = username2, UserRole = "User", DialCode = "+91", PhoneNumber = "12341234", Email = "*****@*****.**", Password = "******", UserLocation = "IN", Status = "Verified", OTPExp = DateTime.UtcNow.AddMinutes(4), VerificationCode = "AQAAAAEAACcQAAAAEDpGr4+u/Oik7F6OLHd3Tr03AX+jYRRqNeo48Il9md5wcPFBl+1xpDQLkimghNMogg==" }; LoginModel loginModel1 = new LoginModel { UserName = username1, Password = password }; //Model with incorrect password LoginModel loginModel2 = new LoginModel { UserName = username2, Password = "******" }; //Insert test data var insert1 = TH.InsertRegiterModeldata(registerModel1).Result; var insert2 = TH.InsertRegiterModeldata(registerModel2).Result; //Act var result1 = TH.GetAuthController().Login(loginModel1) as ActionResult; var responseData1 = TH.DeserializedResponceData(result1.ToJson()); var result2 = TH.GetAuthController().Login(loginModel2) as ActionResult; var responseData2 = TH.DeserializedResponceData(result2.ToJson()); //Check inserted data var insertedData1 = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username1), "Authentication", "Authentication").Result); var insertedData2 = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username2), "Authentication", "Authentication").Result); //Assert Assert.IsNotNull(result1); Assert.AreEqual(insertedData1.Title, registerModel1.Title); Assert.AreEqual(insertedData1.FullName, registerModel1.FullName); Assert.AreEqual(insertedData1.UserName, username1); Assert.AreEqual(insertedData1.UserRole, registerModel1.UserRole); Assert.AreEqual(insertedData1.DialCode, registerModel1.DialCode); Assert.AreEqual(insertedData1.PhoneNumber, registerModel1.PhoneNumber); Assert.AreEqual(insertedData1.Email, registerModel1.Email); Assert.AreEqual(insertedData1.Password, registerModel1.Password); Assert.AreEqual(insertedData1.UserLocation, registerModel1.UserLocation); Assert.AreEqual(insertedData1.Status, registerModel1.Status); Assert.AreEqual(insertedData1.VerificationCode, registerModel1.VerificationCode); Assert.IsNull(insertedData1.SocialId); Assert.AreEqual(insertedData1.WrongAttemptCount, 0); Assert.IsNotNull(result2); Assert.AreEqual(insertedData2.Title, registerModel2.Title); Assert.AreEqual(insertedData2.FullName, registerModel2.FullName); Assert.AreEqual(insertedData2.UserName, username2); Assert.AreEqual(insertedData2.UserRole, registerModel2.UserRole); Assert.AreEqual(insertedData2.DialCode, registerModel2.DialCode); Assert.AreEqual(insertedData2.PhoneNumber, registerModel2.PhoneNumber); Assert.AreEqual(insertedData2.Email, registerModel2.Email); Assert.AreEqual(insertedData2.Password, registerModel2.Password); Assert.AreEqual(insertedData2.UserLocation, registerModel2.UserLocation); Assert.AreEqual(insertedData2.Status, registerModel2.Status); Assert.AreEqual(insertedData2.VerificationCode, registerModel2.VerificationCode); Assert.IsNull(insertedData2.SocialId); Assert.AreEqual(insertedData2.WrongAttemptCount, 1); //Delete inserted test data var checkData1 = MH.CheckForDatas("UserName", username1, null, null, "Authentication", "Authentication"); if (checkData1 != null) { var delete = MH.DeleteSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username1), "Authentication", "Authentication"); } var checkData2 = MH.CheckForDatas("UserName", username2, null, null, "Authentication", "Authentication"); if (checkData2 != null) { var delete = MH.DeleteSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username2), "Authentication", "Authentication"); } }