public void TestValidUserShouldBePassedToRepository() { var repositoryMock = new Mock <IUserRepository>(); repositoryMock.Setup(m => m.Create(It.IsAny <User>())).Callback( (User user) => { Assert.IsNotEmpty(user.UserUuid.Value); Assert.AreEqual("*****@*****.**", user.Email.Value); Assert.AreEqual("Test", user.Name.Value); Assert.AreEqual("Test Surname", user.Surname.Value); Assert.AreEqual(987234321, user.PhoneNumber.Value); Assert.AreEqual(12345, user.PostalCode.Value); Assert.AreEqual("es", user.CountryCode.Value); Assert.False(user.IsSamePassword(new HashedPassword("YWJjMTIz"))); Assert.AreEqual(1, user.DomainEvents.Count); }); var createUser = new CreateUser(repositoryMock.Object, new HashPassword()); createUser.Handle( new Email("*****@*****.**"), new Password("abc123"), new Name("Test"), new Surname("Test Surname"), new PhoneNumber(987234321), new PostalCode(12345), new CountryCode("es") ); Assert.Pass(); }
public async Task HandleWithValidCreateRequestCallSaveAsExpectedResultAsync() { // Arrange var userModel = new UserModel { Id = 299536, FirstName = "Thirumalai" }; var config = new MapperConfiguration(m => { m.CreateMap <UserDetail, UserModel>(); m.CreateMap <UserModel, UserDetail>(); }); var mapper = new Mapper(config); var UserList = MockUserListResponse().ToList().AsQueryable(); repository = new Mock <IRepository>(); repository.Setup(m => m.Query <UserDetail>()) .Returns(UserList); underTest = new CreateUser(repository.Object, mapper); request = new CreateUserRequest(userModel); // Act CancellationToken cancellationToken; var result = await underTest.Handle(request, cancellationToken); // Assert Assert.NotNull(result); Assert.Equal(userModel.Id, result.Id); Assert.Equal(userModel.FirstName, result.FirstName); }
public async Task WhenCreateUserCommandDispatched() { _request = new Fixture().Create <CreateUser.Command>(); var database = Substitute.For <IMongoDatabase>(); _collection = Substitute.For <IMongoCollection <CreateUser.Command> >(); database.GetCollection <CreateUser.Command>("users").Returns(_collection); var mediator = Substitute.For <IMediator>(); mediator.Send(Arg.Is <FindBankDetailsByAccountNumber.Query>(x => x.AccountNumber == _request.BankDetails.AccountNumber), CancellationToken.None).Returns(Maybe <BankDetails> .Some(new BankDetails())); var handler = new CreateUser(database, mediator, null); _result = await handler.Handle(_request, CancellationToken.None); }