Example #1
0
        private GeoDependencyException CreateAndLogDependencyException(Exception exception)
        {
            var geoDependencyException = new GeoDependencyException(exception);

            this.loggingBroker.LogError(geoDependencyException);

            return(geoDependencyException);
        }
        public void ShouldThrowDependencyExceptionOnRetrieveAllIfSqlExceptionWasThrownAndLogIt()
        {
            SqlException sqlException = CreateSqlException();
            var          expectedGeoDependencyException = new GeoDependencyException(sqlException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllGeos())
            .Throws(sqlException);

            // when . then
            Assert.Throws <GeoDependencyException>(() => this.geoService.RetrieveAllGeos());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectAllGeos(),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogCritical(It.Is(SameExceptionAs(expectedGeoDependencyException))),
                                          Times.Once);
        }
        public void ShouldThrowDependencyExceptionOnRetrieveAllIfStorageFailsAndLogIt()
        {
            // given
            var dbUpdateException = new DbUpdateException();
            var expectedGeoDependencyException = new GeoDependencyException(dbUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllGeos())
            .Throws(dbUpdateException);

            // when . then
            Assert.Throws <GeoDependencyException>(() => this.geoService.RetrieveAllGeos());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectAllGeos(),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(expectedGeoDependencyException))),
                                          Times.Once);
        }
        public void ShouldThrowEmptyGeosExceptionOnRetrieveIfStorageWasEmptyAndLogIt()
        {
            // given
            IQueryable <Geo> emptyGeos         = new List <Geo>().AsQueryable();
            IQueryable <Geo> storageGeos       = emptyGeos;
            var emptyGeosException             = new EmptyGeosException();
            var expectedGeoDependencyException = new GeoDependencyException(emptyGeosException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllGeos())
            .Returns(storageGeos);

            // when . then
            Assert.Throws <GeoDependencyException>(() => this.geoService.RetrieveAllGeos());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectAllGeos(),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogCritical(It.Is(SameExceptionAs(expectedGeoDependencyException))),
                                          Times.Once);
        }