Example #1
0
            public async void Should_return_NotFound_when_phone_is_Invalid()
            {
                // Arrange
                var      invalidUserId   = 0;
                var      expirationDays  = "2";
                string   key             = "User_StatusCode_404_NotFound";
                var      localizedString = new LocalizedString(key, "Not Found");
                Contacts contact         = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(invalidUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"])
                .Returns(expirationDays);

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <NotFoundObjectResult>(result);
            }
Example #2
0
            public async void Should_return_BadRequest_when_contact_is_null()
            {
                // Arrange
                Contacts contact = new Contacts()
                {
                    Phone = null
                };
                string key             = "User_StatusCode_400_BadRequest";
                var    localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Assert
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <BadRequestObjectResult>(result);
            }
Example #3
0
            public async void Should_return_createdObjectResult_when_phone_is_valid()
            {
                // Arrange
                var      validUserId    = 1;
                var      expirationDays = "2";
                Contacts contact        = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(validUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"]).Returns(expirationDays);

                ForgotPassword forgotPassword = new ForgotPassword()
                {
                    UserID        = validUserId,
                    OTPExpiryTime = DateTime.UtcNow.AddDays(Convert.ToInt16(expirationDays)),
                    ResetOTP      = ControllerUnderTest.GetOTP(),
                    ResetTime     = DateTime.UtcNow,
                    CreatedDate   = DateTime.UtcNow
                };

                var expectedResult = forgotPassword;

                UserServiceMock.Setup(y => y.CreateAsync(forgotPassword))
                .ReturnsAsync(expectedResult);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                // Assert
                Assert.IsType <CreatedResult>(result);
            }