Beispiel #1
0
        public void ChangeOrganizationMemberPermission_Fail(
            ChangeOrganizationMemberPermissionDto changeDto,
            Organization organization,
            Mock <IMapper <OrganizationDto, Organization> > mapper)
        {
            //Arrange
            var member1 = organization.Members[0];

            changeDto.OrganizationId = organization.Id.Id;

            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.GetAsync(changeDto.OrganizationId)).ReturnsAsync(organization);

            //repo.Setup(x => x.UpdateAsync(organization));

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            Func <Task> actual = async() => await service.ChangeOrganizationMemberPermission(changeDto);


            //Assert
            actual.Should().Throw <ArgumentException>();
        }
Beispiel #2
0
        public async Task ChangeOrganizationMemberPermission_Success(
            Organization organization,
            Mock <IMapper <OrganizationDto, Organization> > mapper)
        {
            //Arrange
            var member1   = organization.Members[0];
            var changeDto = new ChangeOrganizationMemberPermissionDto {
                OrganizationId = organization.Id.Id,
                Email          = member1.Email.ActualEmail,
                Permission     = Permission.SuperAdmin,
                ChangeDate     = DateTime.Now,
                ChangedBy      = "tester"
            };

            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.GetAsync(changeDto.OrganizationId)).ReturnsAsync(organization);

            repo.Setup(x => x.UpdateAsync(organization));

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            await service.ChangeOrganizationMemberPermission(changeDto);

            var actualMember = organization.Members[0];

            //Assert
            organization.ChangedBy.Should().Be(changeDto.ChangedBy);
            organization.ChangeDate.Should().Be(changeDto.ChangeDate);

            actualMember.Email.ActualEmail.Should().Be(changeDto.Email);
            actualMember.Permission.Should().Be(changeDto.Permission);
        }
Beispiel #3
0
        public async Task AddOrganizationMember_Success(
            Organization organization,
            OrganizationMemberDto changeDto,
            Mock <IMapper <OrganizationDto, Organization> > mapper)
        {
            //Arrange
            changeDto.OrganizationId = organization.Id.Id;
            OrganizationMember addedMember = null;

            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.GetAsync(changeDto.OrganizationId)).ReturnsAsync(organization);

            repo.Setup(x => x.UpdateAsync(organization)).Callback(() => addedMember = organization.Members.First(x => x.Email.ActualEmail == changeDto.Email));

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            await service.AddOrganizationMember(changeDto);

            //Assert
            organization.ChangedBy.Should().Be(changeDto.ChangedBy);
            organization.ChangeDate.Should().Be(changeDto.ChangeDate);

            addedMember.Email.ActualEmail.Should().Be(changeDto.Email);
            addedMember.UserName.Should().Be(changeDto.UserName);
        }
        public async Task AddOrganization_Success(OrganizationDto organizationDto, Organization organization)
        {
            //Arrange
            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.AddOrganization(It.IsAny <Organization>()));

            var mapper = new Mock <IMapper <OrganizationDto, Organization> >();

            mapper.Setup(m => m.Map(organizationDto)).Returns(mapper.Object);
            mapper.Setup(m => m.ToOutFormat()).Returns(organization);

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            await service.AddOrganization(organizationDto);

            //Assert
            repo.Verify(x => x.AddOrganization(organization), Times.Once);
        }
Beispiel #5
0
        public async Task ChangeOrganizationAddress_Success(
            ChangeOrganizationAddressDto changeDto,
            Organization organization,
            Mock <IMapper <OrganizationDto, Organization> > mapper)
        {
            //Arrange
            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.GetAsync(changeDto.Id)).ReturnsAsync(organization);

            repo.Setup(x => x.UpdateAsync(organization));

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            await service.ChangeOrganizationAddress(changeDto);

            //Assert
            organization.Address.Should().BeEquivalentTo(changeDto, options => options.ExcludingMissingMembers());
        }
Beispiel #6
0
        public async Task ChangeOrganizationWebsite_Success(
            ChangeOrganizationWebsiteDto changeDto,
            Organization organization,
            Mock <IMapper <OrganizationDto, Organization> > mapper)
        {
            //Arrange
            var repo = new Mock <IReadWriteOrganizationRepository>();

            repo.Setup(x => x.GetAsync(changeDto.Id)).ReturnsAsync(organization);

            repo.Setup(x => x.UpdateAsync(organization));

            var service = new OrganizationWorkerService(repo.Object, mapper.Object);

            //Act
            await service.ChangeOrganizationWebsite(changeDto);

            //Assert
            organization.Website.Should().Be(changeDto.Website);
        }