public async Task GetAsync_Id_ReturnsOrganization( OrganizationEntity organizationEntity, List <OrganizationEntity> list, Organization organization, Mock <IMapper <OrganizationMember, OrganizationMemberEntity> > mapMember, Mock <IMapper <Organization, OrganizationEntity> > entityMapper) { // Arrange list.Add(organizationEntity); var mapDomain = new Mock <IMapper <OrganizationEntity, Organization> >(); mapDomain.Setup(x => x.Map(organizationEntity)).Returns(mapDomain.Object); mapDomain.Setup(x => x.ToOutFormat()).Returns(organization); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadWriteOrganizationRepository(context, entityMapper.Object, mapDomain.Object, mapMember.Object); context.Organizations.AddRange(list); context.SaveChanges(); // Act var Actual = await repo.GetAsync(organizationEntity.Id); // Arrange Actual.Should().BeOfType <Organization>(); }
public async Task AddOrganization_Success( Organization organization, OrganizationMemberEntity memb, Mock <IMapper <OrganizationMemberEntity, OrganizationMember> > orgMemberDomainMapper ) { // Arrange var mapMember = new Mock <IMapper <OrganizationMember, OrganizationMemberEntity> >(); mapMember.Setup(x => x.Map(It.IsAny <OrganizationMember>())).Returns(mapMember.Object); mapMember.Setup(x => x.ToOutFormat()).Returns(memb); 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); // Act await repo.AddOrganization(organization); var actual = await context.Organizations.FindAsync(organization.Id.Id); // Assert actual.Id.Should().Be(organization.Id.Id); organization.Address.Should().BeEquivalentTo(actual, options => options.ExcludingMissingMembers()); }
public async Task GetUserOrganizationByEmail_ReturnsDomainList(List <OrganizationEntity> organizations, OrganizationMemberEntity memberEntity, Organization organization) { var orgMembers = new List <OrganizationMemberEntity>(); // Arrange organizations.ForEach(x => orgMembers.Add( new OrganizationMemberEntity { OrganizationId = x.Id, Organization = x, Email = memberEntity.Email, Permission = memberEntity.Permission, UserName = memberEntity.UserName })); var mapDomain = new Mock <IMapper <OrganizationEntity, Organization> >(); mapDomain.Setup(x => x.Map(It.IsAny <OrganizationEntity>())).Returns(mapDomain.Object); mapDomain.Setup(x => x.ToOutFormat()).Returns(organization); var mapMemberDomain = new Mock <IMapper <OrganizationMemberEntity, OrganizationMember> >(); mapMemberDomain.Setup(x => x.Map(It.IsAny <OrganizationMemberEntity>())).Returns(mapMemberDomain.Object); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadOnlyOrganizationMemberRepository(context, mapMemberDomain.Object, mapDomain.Object); context.OrganizationMembers.AddRange(orgMembers); context.SaveChanges(); // Act var hest = await repo.GetUserOrganizationsByEmail(memberEntity.Email); // Arrange hest.Should().HaveCount(3); }
public void GetAsync_badId_ThrowsException(List <OrganizationEntity> list, OrganizationEntity organizationEntity) { // Arrange var mapDomain = new Mock <IMapper <OrganizationEntity, Organization> >(); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadOnlyOrganizationRepository(context, mapDomain.Object); context.Organizations.AddRange(list); context.SaveChanges(); // Act Func <Task> act = async() => await repo.GetAsync(organizationEntity.Id); // Arrange act.Should().Throw <EntityNotFoundException>(); }
public async Task GetAllAsync_ReturnsDomainList(List <OrganizationEntity> organizations, Organization org) { // Arrange var mapDomain = new Mock <IMapper <OrganizationEntity, Organization> >(); mapDomain.Setup(x => x.Map(It.IsAny <OrganizationEntity>())).Returns(mapDomain.Object); mapDomain.Setup(x => x.ToOutFormat()).Returns(org); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadOnlyOrganizationRepository(context, mapDomain.Object); context.Organizations.AddRange(organizations); context.SaveChanges(); // Act var hest = await repo.GetAllAsync(); // Arrange hest.Should().HaveCount(organizations.Count); }
public void UpdateOrganization_badEntity_ThrowsException( List <OrganizationEntity> list, Organization organization, Mock <IMapper <OrganizationMember, OrganizationMemberEntity> > mapMember, Mock <IMapper <Organization, OrganizationEntity> > entityMapper) { // Arrange var mapDomain = new Mock <IMapper <OrganizationEntity, Organization> >(); var db = new InMemoryDb <OrganizationDbContext>(); var context = new OrganizationDbContext(db.GetOptions()); var repo = new ReadWriteOrganizationRepository(context, entityMapper.Object, mapDomain.Object, mapMember.Object); context.Organizations.AddRange(list); context.SaveChanges(); // Act Func <Task> act = async() => await repo.UpdateAsync(organization); // Arrange act.Should().Throw <EntityNotFoundException>(); }
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"); }