public void Should_SaveMailMessageToRepositoryAndCreateAndSaveInquiry_WhenClientSendMessageToEmployeeWithCarbonCopyToOurSystem()
{
//arrange
var mailMessage = new MailMessage
{
Body = "a",
Date = Clock.Now,
Subject = "s",
Sender = new MailAddress("[email protected]", "client"),
Receivers =
new List<MailAddress> {new MailAddress("[email protected]", "employee")},
};
aeEmailClient.GetUnreadMessages().Returns(new List<MailMessage>
{
mailMessage
}.AsQueryable());
var employeePerson = new Person
{
Email = "[email protected]",
FirstName = "employee",
Role = PersonRole.Employee
};
repository.Query<Person>().ReturnsForAnyArgs(new List<Person>
{
employeePerson,
new Person
{
Email="[email protected]",
FirstName = "client",
Role = PersonRole.Client
}
}.AsQueryable());
repository.Query<User>().ReturnsForAnyArgs(new List<User>
{
new User
{
RelatedPerson = employeePerson,
CurrentTeam = new Team
{
Name = "1"
}
}
}.AsQueryable());
repository.Query<Inquiry>().ReturnsForAnyArgs(new List<Inquiry>().AsQueryable());
//act
mailMessagePersister.ProcessMessage(aeEmailClient, EventArgs.Empty);
//assert
repository.Received().Save(Arg.Is<Entities.MailMessage>(x => x.Sender.Email == "[email protected]"
&& x.Receivers.Any(receiver => receiver.Email == "[email protected]")
&& x.Receivers.Count == 1));
repository.Received().Save(Arg.Is<Inquiry>(x=>x.Subject=="s" &&
x.ReferenceDate==null &&
x.Client.Email=="[email protected]" &&
x.Client.FirstName=="client" &&
x.Client.Role==PersonRole.Client));
}