@@ -100,6 +100,74 @@ public async Task ChangePassword_PassesStoreIdToLookup()
100100 _customerServiceMock . Verify ( c => c . GetCustomerByEmail ( "admin@admin.com" , "store-1" ) , Times . Once ) ;
101101 }
102102
103+ [ TestMethod ]
104+ public async Task ChangePassword_ForCustomer_ChangesThatCustomerWithoutLookup ( )
105+ {
106+ //Arrange
107+ var customer = new Customer { Id = "c1" , Email = "a@x.com" , PasswordFormatId = PasswordFormat . Clear , Password = "123456" } ;
108+ //Act
109+ await _customerManagerService . ChangePassword ( customer , PasswordFormat . Clear , "zxcvbn" ) ;
110+ //Assert
111+ Assert . AreEqual ( "zxcvbn" , customer . Password ) ;
112+ _customerServiceMock . Verify ( c => c . UpdateCustomerPassword ( customer ) , Times . Once ) ;
113+ //the whole-customer update would write back everything else the caller's copy holds
114+ _customerServiceMock . Verify ( c => c . UpdateCustomer ( It . IsAny < Customer > ( ) ) , Times . Never ) ;
115+ _customerServiceMock . Verify ( c => c . GetCustomerByEmail ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ) ;
116+ }
117+
118+ [ TestMethod ]
119+ public async Task ChangePassword_ImplementationBuiltForAnEarlierRelease_UsesItsExistingMethod ( )
120+ {
121+ ICustomerManagerService manager = new EarlierReleaseManager ( ) ;
122+
123+ await manager . ChangePassword ( new Customer { Email = "a@x.com" , StoreId = "store-1" } , PasswordFormat . Hashed , "new" ) ;
124+
125+ var implementation = ( EarlierReleaseManager ) manager ;
126+ Assert . AreEqual ( "a@x.com" , implementation . Request . Email ) ;
127+ Assert . AreEqual ( PasswordFormat . Hashed , implementation . Request . PasswordFormat ) ;
128+ Assert . AreEqual ( "new" , implementation . Request . NewPassword ) ;
129+ Assert . AreEqual ( "store-1" , implementation . StoreId ) ;
130+ }
131+
132+ [ TestMethod ]
133+ public void NewInterfaceMembers_HaveDefaultBodies_SoExistingImplementationsKeepLoading ( )
134+ {
135+ Assert . IsFalse ( typeof ( ICustomerService ) . GetMethod ( nameof ( ICustomerService . UpdateCustomerPassword ) ) ! . IsAbstract ) ;
136+ Assert . IsFalse ( typeof ( ICustomerManagerService ) . GetMethod ( nameof ( ICustomerManagerService . ChangePassword ) ,
137+ [ typeof ( Customer ) , typeof ( PasswordFormat ) , typeof ( string ) ] ) ! . IsAbstract ) ;
138+ }
139+
140+ private sealed class EarlierReleaseManager : ICustomerManagerService
141+ {
142+ public ChangePasswordRequest Request { get ; private set ; }
143+ public string StoreId { get ; private set ; }
144+
145+ public Task < CustomerLoginResults > LoginCustomer ( string usernameOrEmail , string password , string storeId = "" ) =>
146+ throw new NotImplementedException ( ) ;
147+
148+ public Task RegisterCustomer ( RegistrationRequest request ) => throw new NotImplementedException ( ) ;
149+
150+ public bool PasswordMatch ( PasswordFormat passwordFormat , string oldPassword , string newPassword ,
151+ string passwordSalt ) => throw new NotImplementedException ( ) ;
152+
153+ public Task ChangePassword ( ChangePasswordRequest request , string storeId = "" )
154+ {
155+ Request = request ;
156+ StoreId = storeId ;
157+ return Task . CompletedTask ;
158+ }
159+ }
160+
161+ [ TestMethod ]
162+ public async Task ChangePassword_UnknownEmail_Throws ( )
163+ {
164+ //Arrange
165+ var changepassword = new ChangePasswordRequest ( "nobody@x.com" , PasswordFormat . Clear , "zxcvbn" ) ;
166+ //Act + Assert
167+ await Assert . ThrowsExactlyAsync < ArgumentNullException > ( ( ) =>
168+ _customerManagerService . ChangePassword ( changepassword , "store-1" ) ) ;
169+ }
170+
103171 [ TestMethod ]
104172 public async Task ChangePasswordTest_Success ( )
105173 {
0 commit comments