Пример #1
0
        public void It_should_write_AuditInfo()
        {
            var auditInfo = new AuditInfo
                                {
                                    Request = new AuditInfo.InnerInfo()
                                    {
                                        CorrelationGuid = Guid.NewGuid(),
                                        Namespace = "RequestNamespace",
                                        Serialized = "RequestSerialized",
                                        Type = "RequestType",
                                        UtcTimestamp = DateTime.UtcNow
                                    },
                                    Response = new AuditInfo.InnerInfo()
                                    {
                                        CorrelationGuid = Guid.NewGuid(),
                                        Namespace = "ResponseNamespace",
                                        Serialized = "ResponseSerialized",
                                        Type = "ResponseType",
                                        UtcTimestamp = DateTime.UtcNow.AddDays(2)
                                    },
                                    Exception = "Exception",
                                    Message = "Message",
                                    Context =
                                        {
                                            { "key1", "value1" },
                                            { "key2", "value2" }
                                        }
                                };

            var service = new ClerkService();
            EndPointConfig.Kernel = Container.Kernel;

            using (var scope = new TransactionScope())
            {
                service.Write(auditInfo);
                scope.Complete();
            }

            using (var tx = Session.BeginTransaction())
            {
                var auditEntryModel = Session.QueryOver<AuditEntryModel>().Fetch(x => x.Context).Eager.List().First();

                Assert.That(auditEntryModel.RequestCorrelationGuid, Is.EqualTo(auditInfo.Request.CorrelationGuid));
                Assert.That(auditEntryModel.RequestNamespace, Is.EqualTo(auditInfo.Request.Namespace));
                Assert.That(auditEntryModel.RequestSerialized, Is.EqualTo(auditInfo.Request.Serialized));
                Assert.That(auditEntryModel.RequestType, Is.EqualTo(auditInfo.Request.Type));
                Assert.That(auditEntryModel.RequestUtcTimestamp, Is.EqualTo(auditInfo.Request.UtcTimestamp));

                Assert.That(auditEntryModel.ResponseCorrelationGuid, Is.EqualTo(auditInfo.Response.CorrelationGuid));
                Assert.That(auditEntryModel.ResponseNamespace, Is.EqualTo(auditInfo.Response.Namespace));
                Assert.That(auditEntryModel.ResponseSerialized, Is.EqualTo(auditInfo.Response.Serialized));
                Assert.That(auditEntryModel.ResponseType, Is.EqualTo(auditInfo.Response.Type));
                Assert.That(auditEntryModel.ResponseUtcTimestamp, Is.EqualTo(auditInfo.Response.UtcTimestamp));

                Assert.That(auditEntryModel.Exception, Is.EqualTo(auditInfo.Exception));
                Assert.That(auditEntryModel.Message, Is.EqualTo(auditInfo.Message));

                Assert.That(auditEntryModel.Context[0].ContextKey, Is.EqualTo("key1"));
                Assert.That(auditEntryModel.Context[0].ContextValue, Is.EqualTo("value1"));

                Assert.That(auditEntryModel.Context[1].ContextKey, Is.EqualTo("key2"));
                Assert.That(auditEntryModel.Context[1].ContextValue, Is.EqualTo("value2"));

                tx.Commit();
            }
        }
 public ClerkServiceUnreachableAlert(AuditInfo auditInfo)
 {
     AuditInfo = auditInfo;
 }
Пример #3
0
        public void It_should_strip_strings_if_too_large_where_needed()
        {
            var moreThan255Chars = new string('a', 300);
            var moreThan2000Chars = new string('a', 3000);
            Assert.That(() => moreThan255Chars.Length, Is.AtLeast(256));
            Assert.That(() => moreThan2000Chars.Length, Is.AtLeast(2001));
            var strippedMoreThan255Chars = moreThan255Chars.Substring(0, 255);
            var strippedMoreThan2000Chars = moreThan2000Chars.Substring(0, 2000);
            Assert.That(() => strippedMoreThan2000Chars.Length, Is.AtMost(2000));

            var auditInfo = new AuditInfo
            {
                Request = new AuditInfo.InnerInfo()
                {
                    CorrelationGuid = Guid.NewGuid(),
                    Namespace = moreThan255Chars,
                    Serialized = moreThan255Chars,
                    Type = moreThan255Chars
                },
                Response = new AuditInfo.InnerInfo()
                {
                    CorrelationGuid = Guid.NewGuid(),
                    Namespace = moreThan255Chars,
                    Serialized = moreThan255Chars,
                    Type = moreThan255Chars
                },
                Exception = moreThan255Chars,
                Message = moreThan2000Chars,
                Context = {
                    { moreThan255Chars, moreThan255Chars }
                }
            };

            var service = new ClerkService();
            EndPointConfig.Kernel = Container.Kernel;

            using (var scope = new TransactionScope())
            {
                service.Write(auditInfo);
                scope.Complete();
            }

            using (var tx = Session.BeginTransaction())
            {
                var auditEntryModel = Session.QueryOver<AuditEntryModel>().Fetch(x => x.Context).Eager.List().First();

                Assert.That(auditEntryModel.RequestCorrelationGuid, Is.EqualTo(auditInfo.Request.CorrelationGuid));
                Assert.That(auditEntryModel.RequestNamespace, Is.EqualTo(strippedMoreThan255Chars));
                Assert.That(auditEntryModel.RequestSerialized, Is.EqualTo(auditInfo.Request.Serialized));
                Assert.That(auditEntryModel.RequestType, Is.EqualTo(strippedMoreThan255Chars));

                Assert.That(auditEntryModel.ResponseCorrelationGuid, Is.EqualTo(auditInfo.Response.CorrelationGuid));
                Assert.That(auditEntryModel.ResponseNamespace, Is.EqualTo(strippedMoreThan255Chars));
                Assert.That(auditEntryModel.ResponseSerialized, Is.EqualTo(auditInfo.Response.Serialized));
                Assert.That(auditEntryModel.ResponseType, Is.EqualTo(strippedMoreThan255Chars));

                Assert.That(auditEntryModel.Exception, Is.EqualTo(auditInfo.Exception));
                Assert.That(auditEntryModel.Message, Is.EqualTo(strippedMoreThan2000Chars));

                Assert.That(auditEntryModel.Context[0].ContextKey, Is.EqualTo(strippedMoreThan255Chars));
                Assert.That(auditEntryModel.Context[0].ContextValue, Is.EqualTo(moreThan255Chars));
                tx.Commit();
            }
        }