Example #1
0
 public CheckAccessFunctions(ITokenValidator tokenValidator, IJsonHttpContentValidator jsonHttpContentValidator, IMicrosoftGraphRepository microsoftGraphRepository, IAuthorizationRepository authorizationRepository)
 {
     this.tokenValidator           = tokenValidator ?? throw new ArgumentNullException(nameof(tokenValidator));
     this.jsonHttpContentValidator = jsonHttpContentValidator ?? throw new ArgumentNullException(nameof(jsonHttpContentValidator));
     this.microsoftGraphRepository = microsoftGraphRepository ?? throw new ArgumentNullException(nameof(microsoftGraphRepository));
     this.authorizationRepository  = authorizationRepository ?? throw new ArgumentNullException(nameof(authorizationRepository));
 }
 public ConferenceCallFunctions(IJsonTextSerializer jsonTextSerializer, ITokenValidator tokenValidator, IDataRepository <User> userRepository, IMicrosoftGraphRepository microsoftGraphRepository)
 {
     this.jsonTextSerializer       = jsonTextSerializer ?? throw new ArgumentNullException(nameof(jsonTextSerializer));
     this.tokenValidator           = tokenValidator ?? throw new ArgumentNullException(nameof(tokenValidator));
     this.userRepository           = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
     this.microsoftGraphRepository = microsoftGraphRepository ?? throw new ArgumentNullException(nameof(microsoftGraphRepository));
 }
Example #3
0
        public Task <IContact> GetExistingContactAsync(IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository)
        {
            NullGuard.NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository));

            return(GetContactAsync(microsoftGraphRepository, contactRepository));
        }
Example #4
0
        protected Task <IContact> GetContactAsync(IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository)
        {
            NullGuard.NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository));

            return(Task.Run(() => ExternalIdentifier.GetContact(ToToken(), microsoftGraphRepository, contactRepository, ref _contact)));
        }
        public override IValidator Validate(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(validator, nameof(validator))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository))
            .NotNull(accountingRepository, nameof(accountingRepository));

            Name?.Validate(validator);
            Address?.Validate(validator);
            Company?.Validate(validator);

            if (Birthday.HasValue)
            {
                validator.DateTime.ShouldBePastDateOrToday(Birthday.Value, GetType(), nameof(Birthday));
            }

            return(base.Validate(validator, microsoftGraphRepository, contactRepository, accountingRepository)
                   .Object.ShouldNotBeNull(Name, GetType(), nameof(Name))
                   .ValidatePhoneNumber(HomePhone, GetType(), nameof(HomePhone), true)
                   .ValidatePhoneNumber(MobilePhone, GetType(), nameof(MobilePhone), true)
                   .ValidateMailAddress(MailAddress, GetType(), nameof(MailAddress), true)
                   .ValidateContactGroupIdentifier(ContactGroupIdentifier, GetType(), nameof(ContactGroupIdentifier))
                   .Object.ShouldBeKnownValue(ContactGroupIdentifier, contactGroupIdentifier => Task.Run(async() => await GetContactGroupAsync(contactRepository) != null), GetType(), nameof(ContactGroupIdentifier))
                   .String.ShouldHaveMinLength(Acquaintance, 1, GetType(), nameof(Acquaintance), true)
                   .String.ShouldHaveMaxLength(Acquaintance, 4096, GetType(), nameof(Acquaintance), true)
                   .ValidateUrl(PersonalHomePage, GetType(), nameof(PersonalHomePage))
                   .Integer.ShouldBeBetween(LendingLimit, 1, 365, GetType(), nameof(LendingLimit))
                   .ValidatePaymentTermIdentifier(PaymentTermIdentifier, GetType(), nameof(PaymentTermIdentifier))
                   .Object.ShouldBeKnownValue(PaymentTermIdentifier, paymentTermIdentifier => Task.Run(async() => await GetPaymentTermAsync(accountingRepository) != null), GetType(), nameof(PaymentTermIdentifier)));
        }
Example #6
0
        public void UpdateContactAsync_WhenContactIsNull_ThrowsArgumentNullException()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.UpdateContactAsync(_fixture.BuildRefreshableTokenMock().Object, null));

            Assert.That(result.ParamName, Is.EqualTo("contact"));
        }
Example #7
0
        public void GetContactsAsync_WhenRefreshableTokenIsNull_ThrowsArgumentNullException()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.GetContactsAsync(null));

            Assert.That(result.ParamName, Is.EqualTo("refreshableToken"));
        }
Example #8
0
        public async Task GetContactsAsync_WhenCalled_ReturnsContacts()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            IEnumerable <IContact> result = await sut.GetContactsAsync(CreateToken());

            Assert.That(result.Count(), Is.GreaterThan(0));
        }
Example #9
0
        public void DeleteContactAsync_WhenIdentifierIsWhiteSpace_ThrowsArgumentNullException()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.DeleteContactAsync(_fixture.BuildRefreshableTokenMock().Object, " "));

            Assert.That(result.ParamName, Is.EqualTo("identifier"));
        }
        public async Task GetContactAsync_WhenCalled_ReturnsContact(string identifier)
        {
            IMicrosoftGraphRepository sut = CreateSut();

            IContact result = await sut.GetContactAsync(CreateToken(), identifier);

            Assert.That(result, Is.Not.Null);
        }
        protected ContactQueryHandlerBase(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository)
        {
            NullGuard.NotNull(validator, nameof(validator))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository));

            Validator = validator;
            MicrosoftGraphRepository = microsoftGraphRepository;
            ContactRepository        = contactRepository;
        }
Example #12
0
        public async Task DeleteContactAsync_WhenCalled_DeletesContact()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            IName    name    = new PersonName("Albert", "Johnson");
            IContact contact = new Contact(name);

            IContact createdContact = await sut.CreateContactAsync(CreateToken(), contact);

            await sut.DeleteContactAsync(CreateToken(), createdContact.ExternalIdentifier);
        }
Example #13
0
        public override IValidator Validate(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(validator, nameof(validator))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository))
            .NotNull(accountingRepository, nameof(accountingRepository));

            return(base.Validate(validator, microsoftGraphRepository, contactRepository, accountingRepository)
                   .ValidateExternalIdentifier(ExternalIdentifier, GetType(), nameof(ExternalIdentifier))
                   .Object.ShouldBeKnownValue(ExternalIdentifier, externalIdentifier => Task.Run(async() => await GetContactAsync(microsoftGraphRepository, contactRepository) != null), GetType(), nameof(ExternalIdentifier)));
        }
        public virtual IValidator Validate(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(validator, nameof(validator))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository))
            .NotNull(accountingRepository, nameof(accountingRepository));

            return(validator.ValidateTokenType(TokenType, GetType(), nameof(TokenType))
                   .ValidateAccessToken(AccessToken, GetType(), nameof(AccessToken))
                   .ValidateRefreshToken(RefreshToken, GetType(), nameof(RefreshToken))
                   .ValidateExpires(Expires, GetType(), nameof(Expires)));
        }
Example #15
0
        protected ContactCommandHandlerBase(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
        {
            NullGuard.NotNull(validator, nameof(validator))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository))
            .NotNull(accountingRepository, nameof(accountingRepository));

            Validator = validator;
            MicrosoftGraphRepository = microsoftGraphRepository;
            ContactRepository        = contactRepository;
            AccountingRepository     = accountingRepository;
        }
Example #16
0
        public async Task CreateContactAsync_WhenCalled_CreatesContact()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            IName    name    = new PersonName("Albert", "Johnson");
            IContact contact = new Contact(name);

            IContact result = await sut.CreateContactAsync(CreateToken(), contact);

            try
            {
                Assert.That(result, Is.Not.Null);
            }
            finally
            {
                await sut.DeleteContactAsync(CreateToken(), result.ExternalIdentifier);
            }
        }
Example #17
0
        public async Task UpdateContactAsync_WhenCalled_CreatesContact()
        {
            IMicrosoftGraphRepository sut = CreateSut();

            IName    name    = new PersonName("Albert", "Johnson");
            IContact contact = new Contact(name);

            IContact createdContact = await sut.CreateContactAsync(CreateToken(), contact);

            try
            {
                createdContact.Address.StreetLine1 = "1234, Johnson Street";
                createdContact.Address.StreetLine2 = "Johnson Town";
                createdContact.Address.PostalCode  = "12345";
                createdContact.Address.City        = "Petersburg";
                createdContact.Address.State       = "TX";
                createdContact.Birthday            = new DateTime(1970, 7, 15);
                createdContact.HomePhone           = "+1 123 4444 5555";
                createdContact.MailAddress         = "*****@*****.**";
                IContact updatedContact = await sut.UpdateContactAsync(CreateToken(), createdContact);

                Assert.That(updatedContact, Is.Not.Null);

                updatedContact.Address.StreetLine1 = null;
                updatedContact.Address.StreetLine2 = null;
                updatedContact.Address.PostalCode  = null;
                updatedContact.Address.City        = null;
                updatedContact.Address.State       = null;
                updatedContact.Birthday            = null;
                updatedContact.HomePhone           = null;
                updatedContact.MailAddress         = null;
                updatedContact = await sut.UpdateContactAsync(CreateToken(), updatedContact);

                Assert.That(updatedContact, Is.Not.Null);
            }
            finally
            {
                await sut.DeleteContactAsync(CreateToken(), createdContact.ExternalIdentifier);
            }
        }
Example #18
0
 public GetContactCollectionQueryHandler(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository)
     : base(validator, microsoftGraphRepository, contactRepository)
 {
 }
 public Sut(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
     : base(validator, microsoftGraphRepository, contactRepository, accountingRepository)
 {
 }
Example #20
0
        public AcquireTokenForMicrosoftGraphCommandHandler(IMicrosoftGraphRepository microsoftGraphRepository)
        {
            NullGuard.NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository));

            _microsoftGraphRepository = microsoftGraphRepository;
        }
 public AuthorizationRepository(IMicrosoftGraphRepository microsoftGraphRepository, IDataRepository <Thing> thingRepository)
 {
     this.microsoftGraphRepository = microsoftGraphRepository ?? throw new ArgumentNullException(nameof(microsoftGraphRepository));
     this.thingRepository          = thingRepository ?? throw new ArgumentNullException(nameof(thingRepository));
 }
Example #22
0
 public CreateContactCommandHandler(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, IAccountingRepository accountingRepository)
     : base(validator, microsoftGraphRepository, contactRepository, accountingRepository)
 {
 }
        public GetAuthorizeUriForMicrosoftGraphQueryHandler(IMicrosoftGraphRepository microsoftGraphRepository)
        {
            NullGuard.NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository));

            _microsoftGraphRepository = microsoftGraphRepository;
        }
Example #24
0
 public Sut(IValidator validator, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, object result = null)
     : base(validator, microsoftGraphRepository, contactRepository)
 {
     _result = result ?? new object();
 }
        internal static IContact GetContact(this string externalIdentifier, IRefreshableToken token, IMicrosoftGraphRepository microsoftGraphRepository, IContactRepository contactRepository, ref IContact contact)
        {
            NullGuard.NotNullOrWhiteSpace(externalIdentifier, nameof(externalIdentifier))
            .NotNull(token, nameof(token))
            .NotNull(microsoftGraphRepository, nameof(microsoftGraphRepository))
            .NotNull(contactRepository, nameof(contactRepository));

            if (contact != null)
            {
                return(contact);
            }

            contact = microsoftGraphRepository.GetContactAsync(token, externalIdentifier).GetAwaiter().GetResult();

            return(contact == null ? null : contactRepository.ApplyContactSupplementAsync(contact).GetAwaiter().GetResult());
        }