public void Should_assemble_domain_obj_containing_high_profile_user_password_rules_based_on_data_comming_from_db_and_external_user_behaviour_service() { var passwordHistoryDto = CreatePasswordHistoryDto(); var passwordHistoryDomainObj = PasswordHistoryRespository.ConvertToPasswordHistoryDomainObj(passwordHistoryDto, isHighProfileUser: true); passwordHistoryDomainObj.UserName.Should().Be(UserName); passwordHistoryDomainObj.CurrentPassword.Should().Be(new Password(CurrentPassword, DateTime.MinValue)); passwordHistoryDomainObj.PreviousPasswords.Select(psw => (psw.PasswordText, psw.CreatedAt)).Should().BeEquivalentTo(passwordHistoryDto.PreviousPasswords); //Notice how we don't make the BeOfType() assertion. It could be tempting to make it public in order to facilitate unit testing. We should not do //this, we should test through the public API so the tests are not too brittle by relying on implementation details. //passwordHistoryDomainObj.PasswordRules.Should().BeOfType<HighProfileUserPasswordRules>(); const string doesNotAddNewNonLetterCharacter = "new11Password22"; passwordHistoryDomainObj.CreateNewPassword(new Password(doesNotAddNewNonLetterCharacter, new DateTime(2020, 05, 05))) .Should().BeFalse(); const string containsOneOfThePreviousPasswords = "password2!"; passwordHistoryDomainObj.CreateNewPassword(new Password(containsOneOfThePreviousPasswords, new DateTime(2020, 05, 05))) .Should().BeFalse(); const string validPassword = "******"; passwordHistoryDomainObj.CreateNewPassword(new Password(validPassword, new DateTime(2020, 05, 05))) .Should().BeTrue(); }
public void Should_extract_relevant_information_from_password_history_domain_obj_to_be_saved_in_db() { var passwordHistoryDomainObj = CreatePasswordHistoryDomainObj(); var passwordHistoryDto = PasswordHistoryRespository.ConvertToPasswordHistoryDto(passwordHistoryDomainObj); passwordHistoryDto.UserName.Should().Be(UserName); passwordHistoryDto.CurrentPassword.Should().Be((CurrentPassword, DateTime.MinValue)); passwordHistoryDto.PreviousPasswords.Select(psw => new Password(psw.Item1, psw.Item2)).Should() .BeEquivalentTo(passwordHistoryDomainObj.PreviousPasswords); }