Esempio n. 1
0
        public void QueryAsync_WhenQueryIsNull_ThrowsArgumentNullException()
        {
            QueryHandler sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("query"));
        }
Esempio n. 2
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasNotCalledOnContactRepository()
        {
            QueryHandler sut = CreateSut(false);

            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.IsAny <IEnumerable <IContact> >()), Times.Never);
        }
Esempio n. 3
0
        public async Task QueryAsync_WhenCalled_AssertBirthdayWithinDaysWasCalledOnGetContactWithBirthdayCollectionQuery()
        {
            QueryHandler sut = CreateSut();

            Mock <IGetContactWithBirthdayCollectionQuery> queryMock = CreateGetContactWithBirthdayCollectionQueryMock();
            await sut.QueryAsync(queryMock.Object);

            queryMock.Verify(m => m.BirthdayWithinDays, Times.Once);
        }
Esempio n. 4
0
        public async Task QueryAsync_WhenCalled_AssertGetContactsAsyncWasCalledOnMicrosoftGraphRepository()
        {
            QueryHandler sut = CreateSut();

            IRefreshableToken token = _fixture.BuildRefreshableTokenMock().Object;
            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock(refreshableToken: token).Object;
            await sut.QueryAsync(query);

            _microsoftGraphRepositoryMock.Verify(m => m.GetContactsAsync(It.Is <IRefreshableToken>(value => value == token)), Times.Once);
        }
Esempio n. 5
0
        public async Task QueryAsync_WhenCalledAndAppliedContactSupplementCollectionWasNotReturnedFromContactRepository_ReturnsEmptyContactCollection()
        {
            QueryHandler sut = CreateSut(hasAppliedContactSupplementCollection: false);

            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock().Object;
            IList <IContact> result = (await sut.QueryAsync(query)).ToList();

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.Empty);
        }
Esempio n. 6
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasCalledOnContactRepositoryWithContactCollectionFromMicrosoftGraphRepository()
        {
            IEnumerable <IContact> microsoftGraphContactCollection = _fixture.CreateMany <IContact>(_random.Next(5, 15)).ToList();
            QueryHandler           sut = CreateSut(microsoftGraphContactCollection: microsoftGraphContactCollection);

            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.Is <IEnumerable <IContact> >(value => value.Equals(microsoftGraphContactCollection))), Times.Once);
        }
Esempio n. 7
0
        public async Task QueryAsync_WhenCalledAndAppliedContactSupplementCollectionWasReturnedFromContactRepository_ReturnsContactWithBirthdayCollectionBasedOnAppliedContactSupplementCollection()
        {
            IEnumerable <IContact> appliedContactSupplementCollection = new List <IContact>
            {
                _fixture.BuildContactMock(hasBirthdayWithinDays: true).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: false).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: true).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: false).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: true).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: false).Object,
                _fixture.BuildContactMock(hasBirthdayWithinDays: true).Object
            };
            QueryHandler sut = CreateSut(appliedContactSupplementCollection: appliedContactSupplementCollection);

            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock().Object;
            IEnumerable <IContact> result = await sut.QueryAsync(query);

            Assert.That(result.All(contact => contact.HasBirthdayWithinDays(It.IsAny <int>())), Is.True);
        }
Esempio n. 8
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_AssertHasBirthdayWithinDaysWasNotCalledOnAnyContact()
        {
            IEnumerable <Mock <IContact> > microsoftGraphContactMockCollection = new List <Mock <IContact> >
            {
                _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock()
            };
            QueryHandler sut = CreateSut(false, microsoftGraphContactMockCollection.Select(m => m.Object).ToArray());

            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            foreach (Mock <IContact> contactMock in microsoftGraphContactMockCollection)
            {
                contactMock.Verify(m => m.HasBirthdayWithinDays(It.IsAny <int>()), Times.Never);
            }
        }
Esempio n. 9
0
        public async Task QueryAsync_WhenCalledAndAppliedContactSupplementCollectionWasReturnedFromContactRepository_AssertHasBirthdayWithinDaysWasCalledOnEachContactWithinAppliedContactSupplementCollectionFromContactRepository()
        {
            IEnumerable <Mock <IContact> > appliedContactSupplementMockCollection = new List <Mock <IContact> >
            {
                _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock()
            };
            QueryHandler sut = CreateSut(appliedContactSupplementCollection: appliedContactSupplementMockCollection.Select(m => m.Object).ToArray());

            int birthdayWithinDays = _fixture.Create <int>();
            IGetContactWithBirthdayCollectionQuery query = CreateGetContactWithBirthdayCollectionQueryMock(birthdayWithinDays).Object;
            await sut.QueryAsync(query);

            foreach (Mock <IContact> contactMock in appliedContactSupplementMockCollection)
            {
                contactMock.Verify(m => m.HasBirthdayWithinDays(It.Is <int>(value => value == birthdayWithinDays)), Times.Once);
            }
        }