Пример #1
0
        public virtual void TestDetailerMessage()
        {
            string        message = "Detailed message";
            TestException e       = new TestException(message, new Exception("The reason!"));

            Assert.IsGreaterOrEqual(0, e.ToString().IndexOf(message));
        }
        public void CreateTest()
        {
            TestException ex;

            try
            {
                ex = new TestException("message", new Exception("inner message"), new Dictionary <string, string>(), "help", "source", "stack", 155);
                throw ex;
            }
            catch (TestException e)
            {
                ex = e;
            }
            var bMessage       = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bBaseMessage   = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bText          = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bType          = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bStack         = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bSource        = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bMethodName    = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bModuleName    = _mockFactory.Create <BsonValue>(MockBehavior.Loose);
            var bModuleVersion = _mockFactory.Create <BsonValue>(MockBehavior.Loose);

            var assembly = ex.TargetSite.Module.Assembly.GetName();
            var version  = assembly.Version?.ToString();

            _structConverter.Setup(x => x.BsonString(ex.Message)).Returns(bMessage.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.GetBaseException().Message)).Returns(bBaseMessage.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.ToString())).Returns(bText.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.GetType().ToString())).Returns(bType.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.StackTrace)).Returns(bStack.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.Source)).Returns(bSource.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(ex.TargetSite.Name)).Returns(bMethodName.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(assembly.Name)).Returns(bModuleName.Object).Verifiable();
            _structConverter.Setup(x => x.BsonString(version)).Returns(bModuleVersion.Object).Verifiable();


            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "Message", bMessage.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "BaseMessage", bBaseMessage.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "Text", bText.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "Type", bType.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "Stack", bStack.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "ErrorCode", It.IsAny <BsonValue>()))
            .Callback((BsonDocument bd, string s, BsonValue v) => Assert.AreEqual(ex.ErrorCode, v.AsInt32))
            .Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "Source", bSource.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "MethodName", bMethodName.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "ModuleName", bModuleName.Object)).Verifiable();
            _valueAppender.Setup(x => x.Append(It.IsAny <BsonDocument>(), "ModuleVersion", bModuleVersion.Object)).Verifiable();


            var actual = Create().Create(ex) as BsonDocument;
        }
Пример #3
0
        protected virtual TestObject[] GetMapObjects(string type, TestProperty[] properties)
        {
            try
            {
                TestException exception = null;
                if (!TryGetObjectsFromPool(type, properties, out _lastObjects, out exception))
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }

                    throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), exception.ToString()));
                }
            }
            catch (TestException)
            {
                throw;
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();

                if (properties != null && properties.Length > 0)
                {
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }
                }

                throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), ex.ToString()));
            }

            return _lastObjects;
        }