예제 #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);
            }
예제 #2
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);
            }