Exemple #1
0
        public void GenerateThrowsExceptionIfThereAreNoAvalaiableNumbers()
        {
            var virtualNumberAssociationRepo = MockVirtualNumberDataSource
                                               .GetRepository <VirtualNumberAssociation, VirtualNumberContext>();

            var virtualNumberRepo = MockVirtualNumberDataSource.GetRepository <VirtualNumber, VirtualNumberContext>();

            virtualNumberRepo.Setup(repo => repo.Get())
            .Returns(MockVirtualNumberDataSource.VirtualNumbers.Where(
                         x => x.Purpose is FreeJobApplication).AsQueryable());

            virtualNumberAssociationRepo.Setup(
                repo => repo.Get())
            .Returns(MockVirtualNumberDataSource.GetFreeJobAssociations.Select(j => j.Object).AsQueryable());

            var virtualNumberService = new VirtualNumberAssociationService(
                virtualNumberAssociationRepo.Object,
                virtualNumberRepo.Object,
                new Mock <IRepository <User, VirtualNumberContext> >().Object);

            Assert.Throws <ApplicationException>(() =>
            {
                var virtualNumberRequest = new Mock <IVirtualNumberRequest>();

                virtualNumberRequest.Setup(x => x.PurposeId).Returns(1);
                virtualNumberRequest.Setup(v => v.Caller).Returns(new User(new BabajobUserType(), 1));


                virtualNumberService.Generate(virtualNumberRequest.Object);
            });
        }
Exemple #2
0
        public void GenerateReturnsANumberIfAvailable()
        {
            var virtualNumberRepo            = MockVirtualNumberDataSource.GetRepository <VirtualNumber, VirtualNumberContext>();
            var virtualNumberAssociationRepo = MockVirtualNumberDataSource
                                               .GetRepository <VirtualNumberAssociation, VirtualNumberContext>();

            virtualNumberRepo.Setup(repo => repo.Get())
            .Returns(MockVirtualNumberDataSource.VirtualNumbers.AsQueryable());

            virtualNumberAssociationRepo.Setup(
                repo => repo.Get())
            .Returns(Enumerable.Empty <VirtualNumberAssociation>().AsQueryable());

            var virtualNumberService = new VirtualNumberAssociationService(
                virtualNumberAssociationRepo.Object,
                virtualNumberRepo.Object,
                new Mock <IRepository <User, VirtualNumberContext> >().Object);

            var virtualNumberRequest = new Mock <IVirtualNumberRequest>();

            virtualNumberRequest.Setup(x => x.PurposeId).Returns(1);

            var number = virtualNumberService
                         .Generate(virtualNumberRequest.Object);

            Assert.AreEqual(
                number.VirtualNumber.VirtualPhoneNumber.Number,
                MockVirtualNumberDataSource.FreeJobApplicationNumber1);
        }