Exemple #1
0
        public async Task <Auditor> TraceCall(CallTrace callTrace, int nthCall = 0)
        {
            await this.TraceStartup();

            var auditTrail      = this.Response.ApiCall.AuditTrail;
            var asyncAuditTrail = this.ResponseAsync.ApiCall.AuditTrail;

            auditTrail.Count.Should().Be(asyncAuditTrail.Count, "calling async should have the same audit trail length as the sync call");

            AssertTrailOnResponse(callTrace, auditTrail, true, nthCall);
            AssertTrailOnResponse(callTrace, asyncAuditTrail, false, nthCall);

            callTrace?.AssertPoolAfterCall?.Invoke(this._cluster.ConnectionPool);
            callTrace?.AssertPoolAfterCall?.Invoke(this._clusterAsync.ConnectionPool);
            return(new Auditor(_cluster, _clusterAsync));
        }
Exemple #2
0
        private static void AssertTrailOnResponse(CallTrace callTrace, List <Audit> auditTrail, bool sync, int nthCall)
        {
            var typeOfTrail   = (sync ? "synchronous" : "asynchronous") + " audit trail";
            var nthClientCall = (nthCall + 1).ToOrdinal();

            callTrace.Select(c => c.Event).Should().ContainInOrder(auditTrail.Select(a => a.Event), $"the {nthClientCall} client call's {typeOfTrail} should assert ALL audit trail items");
            foreach (var t in auditTrail.Select((a, i) => new { a, i }))
            {
                var i                 = t.i;
                var audit             = t.a;
                var nthAuditTrailItem = (i + 1).ToOrdinal();
                var because           = $"thats the {{0}} specified on the {nthAuditTrailItem} item in the {nthClientCall} client call's {typeOfTrail}";
                var c                 = callTrace[i];
                audit.Event.Should().Be(c.Event, string.Format(because, "event"));
                if (c.Port.HasValue)
                {
                    audit.Node.Uri.Port.Should().Be(c.Port.Value, string.Format(because, "port"));
                }
                c.SimpleAssert?.Invoke(audit);
                c.AssertWithBecause?.Invoke(string.Format(because, "custom assertion"), audit);
            }
        }