public async Task GivenICreateUser_AndTheUserDoesNotHaveIdentity_ThenIShouldGetAFailedResultAsync() { // arrange MemberUserStore sut = CreateSut(); var fakeUser = new MemberIdentityUser(); IMemberType fakeMemberType = new MemberType(new MockShortStringHelper(), 77); IMember mockMember = Mock.Of <IMember>(m => m.Name == "fakeName" && m.Email == "*****@*****.**" && m.Username == "fakeUsername" && m.RawPasswordValue == "fakePassword" && m.ContentTypeAlias == fakeMemberType.Alias && m.HasIdentity == false); _mockMemberService.Setup(x => x.CreateMember(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(mockMember); _mockMemberService.Setup(x => x.Save(mockMember)); // act IdentityResult actual = await sut.CreateAsync(null); // assert Assert.IsFalse(actual.Succeeded); Assert.IsTrue(actual.Errors.Any(x => x.Code == "IdentityErrorUserStore" && x.Description == "Value cannot be null. (Parameter 'user')")); _mockMemberService.VerifyNoOtherCalls(); }
public async Task GivenICreateANewUser_AndTheUserIsPopulatedCorrectly_ThenIShouldGetASuccessResultAsync() { // arrange MemberUserStore sut = CreateSut(); var fakeUser = new MemberIdentityUser(); IMemberType fakeMemberType = new MemberType(new MockShortStringHelper(), 77); IMember mockMember = Mock.Of <IMember>(m => m.Name == "fakeName" && m.Email == "*****@*****.**" && m.Username == "fakeUsername" && m.RawPasswordValue == "fakePassword" && m.Comments == "hello" && m.ContentTypeAlias == fakeMemberType.Alias && m.HasIdentity == true); _mockMemberService.Setup(x => x.CreateMember(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(mockMember); _mockMemberService.Setup(x => x.Save(mockMember)); // act IdentityResult identityResult = await sut.CreateAsync(fakeUser, CancellationToken.None); // assert Assert.IsTrue(identityResult.Succeeded); Assert.IsTrue(!identityResult.Errors.Any()); _mockMemberService.Verify(x => x.CreateMember(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); _mockMemberService.Verify(x => x.Save(mockMember)); }
public async Task GivenICreateUser_AndTheUserIsNull_ThenIShouldGetAFailedResultAsync() { // arrange MemberUserStore sut = CreateSut(); // act IdentityResult actual = await sut.CreateAsync(null); // assert Assert.IsFalse(actual.Succeeded); Assert.IsTrue(actual.Errors.Any(x => x.Code == "IdentityErrorUserStore" && x.Description == "Value cannot be null. (Parameter 'user')")); _mockMemberService.VerifyNoOtherCalls(); }