public override Request.Submission ReadRecord(CsvReader reader) { var recordDefinition = new { name = string.Empty, surname = string.Empty, mail = string.Empty, city = string.Empty, your_knowledge = string.Empty, your_experience = string.Empty, how_did_you_know_us = string.Empty, rodo = string.Empty, phone = string.Empty }; var record = reader.GetRecord(recordDefinition); return(new Request.Submission() { FirstName = record.name.Trim(), LastName = record.surname.Trim(), Email = EmailAddress.Create(record.mail.Trim()).Value, PhoneNumber = string.IsNullOrWhiteSpace(record.phone) ? null : PhoneNumber.Create(record.phone.Trim()).Value, Cities = record.city .Split(new[] { ",", ";", "/" }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()).ToList(), Province = "N/A", AboutMe = $"{record.your_knowledge.Trim()}\n{record.your_experience.Trim()}\n{record.how_did_you_know_us.Trim()}" }); }
public async Task Handle_CustomerExist_AddIndividualCustomerEmailAddress( [Frozen] Mock <IRepository <Entities.IndividualCustomer> > customerRepoMock, AddIndividualCustomerEmailAddressCommandHandler sut, Entities.Person person, string accountNumber ) { //Arrange var command = new AddIndividualCustomerEmailAddressCommand { AccountNumber = accountNumber, EmailAddress = EmailAddress.Create("*****@*****.**").Value }; //Act customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetIndividualCustomerSpecification>(), It.IsAny <CancellationToken>() ) ) .ReturnsAsync(new Entities.IndividualCustomer(person)); var result = await sut.Handle(command, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.UpdateAsync( It.IsAny <Entities.IndividualCustomer>(), It.IsAny <CancellationToken>() )); }
public override Request.Submission ReadRecord(CsvReader reader) { var enrollment = new Request.Submission() { FirstName = ReadField(reader, "Imię i Nazwisko").Split(' ').First(), LastName = ReadField(reader, "Imię i Nazwisko").Split(' ').Skip(1).First(), Email = EmailAddress.Create(ReadField(reader, "Adres e-mail").Trim()).Value, PhoneNumber = PhoneNumber.Create(ReadField(reader, "Telefon").Trim()).Value, Cities = ReadField(reader, "Miasto") .Split(new[] { ",", ";", "/" }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()).ToList(), Province = ReadField(reader, "Województwo"), AboutMe = ReadField(reader, "Kilka zdań o sobie"), WhatDoYouExpectFromTheProject = ReadField(reader, "Czego oczekujesz od projektu") }; var dateFieldRaw = ReadField(reader, "Sygnatura czasowa"); if (DateTime.TryParse(dateFieldRaw, out DateTime date)) { enrollment.SubmissionDate = date; } return(enrollment); }
public void Handle_EmailAddressDoesNotExist_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.IndividualCustomer> > customerRepoMock, DeleteIndividualCustomerEmailAddressCommandHandler sut, Entities.Person person, string accountNumber ) { //Arrange var command = new DeleteIndividualCustomerEmailAddressCommand { AccountNumber = accountNumber, EmailAddress = EmailAddress.Create("*****@*****.**").Value }; customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetIndividualCustomerSpecification>(), It.IsAny <CancellationToken>() ) ) .ReturnsAsync(new Entities.IndividualCustomer(person)); //Act Func <Task> func = async() => await sut.Handle(command, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'emailAddress')"); }
public async Task <long> CreateUser(CreateUser createUser) { bool emailIsTaken = await IsEmailAddressTaken(createUser.EmailAddress); if (emailIsTaken) { throw new DomainException(DomainExceptions.User_with_given_email_address_already_exists); } User?createdUser = null; using (var transaction = await context.Database.BeginTransactionAsync()) { createdUser = new User(EmailAddress.Create(createUser.EmailAddress), Password.Create(createUser.Password)); createdUser.Name = createUser.Name; context.Users.Add(createdUser); await context.SaveChangesAsync(); context.AddEvent(createdUser.CreateEvent(), correlationIdProvider.TraceId); await context.SaveChangesAsync(); await transaction.CommitAsync(); } return(createdUser !.UserId); }
public void CreatingEmailAddressWithInvalidInput_Fails(string address) { var result = EmailAddress.Create(address); Assert.True(result.IsFailure); Assert.Equal(EmailAddress.InvalidEmailAddress, result.Error); }
public void GivenCorrectEmailAddress_ShouldCreateInstance( [Values("*****@*****.**", "*****@*****.**")] string emailAddress) { var instance = EmailAddress.Create(emailAddress); Assert.That(instance, Is.Not.Null); Assert.That(instance.Value, Is.EqualTo(emailAddress)); }
public override async Task <Unit> Handle(UpdateEmailMessageSender command, CancellationToken cancellationToken) { var message = await this.GetMessageById(command.Id); message.UpdateSender(EmailAddress.Create(command.Sender)); await this.emailRepository.UpdateMessageAsync(message); return(Unit.Value); }
public void Create_EmptyEmailAddress_Failure() { //Arrange //Act var result = EmailAddress.Create(""); //Assert result.Should().BeFailure(); }
public void Create_WithSpace_Failure() { //Arrange //Act var result = EmailAddress.Create("t [email protected]"); //Assert result.Should().BeFailure(); }
public void Create_NoAddSign_Failure() { //Arrange //Act var result = EmailAddress.Create("testtest.com"); //Assert result.Should().BeFailure(); }
private static void AddUser(UserManagementDbContext context, string email, string password, string name, UserRole role) { var user = new User(EmailAddress.Create(email), Password.Create(password)) { Name = name, Role = role }; context.Users.Add(user); context.SaveChanges(); }
public void Create_ValidEmailAddress_Success() { //Arrange //Act var result = EmailAddress.Create("*****@*****.**"); //Assert result.Should().BeSuccess(); }
public async Task Handle_CustomerAndContactExist_UpdateStoreCustomerContact( [Frozen] Mock <IRepository <Entities.StoreCustomer> > customerRepoMock, Entities.StoreCustomer customer, UpdateStoreCustomerContactCommandHandler sut, Entities.Person contactPerson, string accountNumber, string contactType ) { //Arrange var command = new UpdateStoreCustomerContactCommand { AccountNumber = accountNumber, CustomerContact = new StoreCustomerContactDto { ContactType = contactType, ContactPerson = new PersonDto { EmailAddresses = new List <EmailAddressDto> { new EmailAddressDto { EmailAddress = EmailAddress.Create("*****@*****.**").Value } } } } }; customer.AddContact( new Entities.StoreCustomerContact( command.CustomerContact.ContactType, contactPerson ) ); customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetStoreCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customer); //Act var result = await sut.Handle(command, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.UpdateAsync( It.IsAny <Entities.StoreCustomer>(), It.IsAny <CancellationToken>() )); }
public void TestValidate_CustomerNotFound_ValidationError( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, UpdateCustomerCommandValidator sut, UpdateCustomerCommand command, string accountNumber, List <CustomerAddressDto> addresses, string contactType, List <PersonPhoneDto> phoneNumbers ) { //Arrange var customerDto = new StoreCustomerDto { AccountNumber = accountNumber, Addresses = addresses, Contacts = new List <StoreCustomerContactDto> { new StoreCustomerContactDto { ContactType = contactType, ContactPerson = new PersonDto { EmailAddresses = new List <PersonEmailAddressDto> { new PersonEmailAddressDto { EmailAddress = EmailAddress.Create("*****@*****.**").Value } }, PhoneNumbers = phoneNumbers } } } }; command.Customer = customerDto; command.Customer.AccountNumber = command.Customer.AccountNumber.Substring(0, 10); customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Entities.StoreCustomer)null); //Act var result = sut.TestValidate(command); //Assert result.ShouldHaveValidationErrorFor(command => command.Customer.AccountNumber) .WithErrorMessage("Customer does not exist"); }
/// <summary> /// Convert a DbCustomer into a domain Customer /// </summary> public static Customer FromDbCustomer(DbCustomer sqlCustomer) { if (sqlCustomer == null) { return(null); } var id = CustomerId.Create(sqlCustomer.Id); var name = PersonalName.Create(sqlCustomer.FirstName, sqlCustomer.LastName); var email = EmailAddress.Create(sqlCustomer.Email); var cust = Customer.Create(id, name, email); return(cust); }
public Person CreatePerson() { var fullName = Fullname.Create("Billy", "The", "Goat"); var idNo = RSAIdentityNumber.Create("21021112341134"); var cellNo = CellphoneNumber.Create("27743389201"); var emailAddress = EmailAddress.Create("*****@*****.**"); var physicalAddress = new Address("4", "Table Mountain", "Cape Town", "7441", "Western Cape", "South Africa"); var postalAddress = new Address("4", "Table Mountain", "Cape Town", "7441", "Western Cape", "South Africa"); var workAddress = new Address("4", "Table Mountain", "Cape Town", "7441", "Western Cape", "South Africa"); var money = new Money(900000, "Coins", "ZAR"); var person = new Person(fullName, idNo, cellNo, emailAddress, physicalAddress, postalAddress, workAddress, money, false, "Some Stuff About Me", MaritalStatus.Married, Gender.Goat, DateTime.Today); return(person); }
/// <summary> /// Create a domain customer from a DTO or null if not valid. /// </summary> public static Customer DtoToCustomer(CustomerDto dto) { if (dto == null) { // dto can be null if deserialization fails return(null); } var id = CustomerId.Create(dto.Id); var name = PersonalName.Create(dto.FirstName, dto.LastName); var email = EmailAddress.Create(dto.Email); var cust = Customer.Create(id, name, email); return(cust); }
public async Task Handle_NewCustomer_ReturnCustomer( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, AddCustomerCommandHandler sut, string name, string contactType, List <CustomerAddressDto> addresses ) { // Arrange var customer = new StoreCustomerDto { Name = name, Addresses = addresses, Contacts = new List <StoreCustomerContactDto> { new StoreCustomerContactDto { ContactType = contactType, ContactPerson = new PersonDto { EmailAddresses = new List <PersonEmailAddressDto> { new PersonEmailAddressDto { EmailAddress = EmailAddress.Create("*****@*****.**").Value } }, PhoneNumbers = new List <PersonPhoneDto>() } } } }; //Act var result = await sut.Handle( new AddCustomerCommand { Customer = customer }, CancellationToken.None ); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.AddAsync( It.IsAny <Entities.Customer>(), It.IsAny <CancellationToken>() )); result.Should().BeEquivalentTo(customer); }
public async Task <Unit> Handle(CreateEmailMessage command, CancellationToken cancellationToken) { var messageBody = GetMessageBody(command.Body, command.IsHtmlBody); var sender = EmailAddress.Create(command.Sender); var recipients = command.Recipients? .Select(EmailAddress.Create) .Where(x => !(x is null)); var message = command.IsPendingEmail ? EmailMessage.CreatePending(command.Subject, messageBody, sender, recipients) : EmailMessage.Create(command.Subject, messageBody, sender, recipients); await this.repository.InsertMessageAsync(message); return(Unit.Value); }
internal Nomination ToNomination() { var nominee = Person.Create(PersonName.Create(NomineeName), OfficeLocation.FindByName(NomineeOfficeLocation), EmailAddress.Create(NomineeEmailAddress)); var companyValues = (CompanyValues ?? Enumerable.Empty <string>()) .Select(CompanyValue.FindByValue) .ToList(); return(new Nomination(Id, NomineeVotingIdentifier.Unknown, nominee, ValueObjects.AwardType.FindByAwardName(AwardType), PersonName.CreateForNominator(NominatorName, IsNominatorAnonymous), companyValues, NominationWriteUp.Create(nominee.Name, WriteUp), NominationWriteUpSummary.Create(WriteUpSummary))); }
public void Handle_CustomerDoesNotExist_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.StoreCustomer> > customerRepoMock, AddStoreCustomerContactCommandHandler sut, string accountNumber, string contactType ) { // Arrange var command = new AddStoreCustomerContactCommand { AccountNumber = accountNumber, CustomerContact = new StoreCustomerContactDto { ContactType = contactType, ContactPerson = new PersonDto { EmailAddresses = new List <EmailAddressDto> { new EmailAddressDto { EmailAddress = EmailAddress.Create("*****@*****.**").Value } } } } }; customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetStoreCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Entities.StoreCustomer)null); //Act Func <Task> func = async() => await sut.Handle(command, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'storeCustomer')"); }
public async Task Handle_CustomerExist_AddStoreCustomerContact( [Frozen] Mock <IRepository <Entities.StoreCustomer> > customerRepoMock, AddStoreCustomerContactCommandHandler sut, string accountNumber, string contactType ) { //Arrange var command = new AddStoreCustomerContactCommand { AccountNumber = accountNumber, CustomerContact = new StoreCustomerContactDto { ContactType = contactType, ContactPerson = new PersonDto { EmailAddresses = new List <EmailAddressDto> { new EmailAddressDto { EmailAddress = EmailAddress.Create("*****@*****.**").Value } } } } }; //Act var result = await sut.Handle(command, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.UpdateAsync( It.IsAny <Entities.StoreCustomer>(), It.IsAny <CancellationToken>() )); }
public void GivenNullEmailAddress_ShouldReturnNull() { var instance = EmailAddress.Create(null); Assert.That(instance, Is.Null); }
public void CreatingEmailAddressWithProperInput_Succeeds(string address) { var result = EmailAddress.Create(address); Assert.True(result.IsSuccess); }
public void GivenIncorrectEmailAddress_ShouldThrowException( [Values("fdsafds", "", "fdsa_pl", "testtest.com", "😀@test.com")] string emailAddress) { Assert.Catch <InvalidEmailAddressException>(() => { EmailAddress.Create(emailAddress); }); }
private static Domain.NominationListAggregate.ValueObjects.Person Convert(Person person) { return(Domain.NominationListAggregate.ValueObjects.Person.Create(PersonName.Create(person.Name), OfficeLocation.EiaTeamMember, EmailAddress.Create(person.EmailAddress))); }