コード例 #1
0
        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;
        }