public void OrganizationEntityMapper_DomainWithoutMembers_ReturnsEntity(Organization organization, OrganizationMemberEntity orgMemberEntity) { //Arrange var memberMapper = new Mock <IMapper <OrganizationMember, OrganizationMemberEntity> >(); memberMapper.Setup(x => x.Map(It.IsAny <OrganizationMember>())).Returns(memberMapper.Object); memberMapper.Setup(x => x.ToOutFormat()).Returns(orgMemberEntity); var sut = new OrganizationEntityMapper(memberMapper.Object); //Act var actual = sut.Map(organization).ToOutFormat(); //Assert actual.Members.Should().HaveCount(0); memberMapper.Verify(x => x.Map(It.IsAny <OrganizationMember>()), Times.Never); }
public async Task UpdateOrganization_OrgWithMembers_Success( List <OrganizationEntity> list, Organization organization, OrganizationMember memb, Mock <IMapper <OrganizationMember, OrganizationMemberEntity> > mapMember, VatNumber newVatNumber, List <Email> mails) { // Arrange var orgMemberDomainMapper = new Mock <IMapper <OrganizationMemberEntity, OrganizationMember> >(); var i = 0; orgMemberDomainMapper.Setup(x => x.Map(It.IsAny <OrganizationMemberEntity>())).Returns(orgMemberDomainMapper.Object); orgMemberDomainMapper.Setup(x => x.ToOutFormat()).Returns(memb); mapMember.Setup(x => x.Map(It.IsAny <OrganizationMember>())).Returns(mapMember.Object); mapMember.Setup(x => x.ToOutFormat()).Returns(new OrganizationMemberEntity { Email = mails[i] }).Callback(() => i = i++); var mapDomain = new OrganizationDomainMapper(orgMemberDomainMapper.Object); var entityMapper = new OrganizationEntityMapper(mapMember.Object); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadWriteOrganizationRepository(context, entityMapper, mapDomain, mapMember.Object); context.Organizations.AddRange(list); context.Organizations.Add(entityMapper.Map(organization).ToOutFormat()); context.SaveChanges(); // Act organization.ChangeVatNumber(newVatNumber, DateTime.Now, "TestChanger"); await repo.UpdateAsync(organization); var actual = await context.Organizations.FindAsync(organization.Id.Id); // Assert actual.Id.Should().Be(organization.Id.Id); actual.VatNumber.Should().BeEquivalentTo(newVatNumber.VatNumberString); actual.ChangedBy.Should().Be("TestChanger"); }
public void OrganizationEntityMapper_Domain_ReturnsEntity(Organization organization, OrganizationMemberEntity orgMemberEntity) { //Arrange var memberMapper = new Mock <IMapper <OrganizationMember, OrganizationMemberEntity> >(); memberMapper.Setup(x => x.Map(It.IsAny <OrganizationMember>())).Returns(memberMapper.Object); memberMapper.Setup(x => x.ToOutFormat()).Returns(orgMemberEntity); var sut = new OrganizationEntityMapper(memberMapper.Object); //Act var actual = sut.Map(organization).ToOutFormat(); //Assert actual.Id.Should().Be(organization.Id.Id); actual.Name.Should().Be(organization.Name.Name); organization.Address.Should().BeEquivalentTo(actual, options => options.ExcludingMissingMembers()); organization.VatNumber.Should().BeEquivalentTo(actual, options => options.ExcludingMissingMembers()); actual.Website.Should().Be(organization.Website); actual.ChangeDate.Should().Be(organization.ChangeDate); actual.ChangedBy.Should().Be(organization.ChangedBy); }