Exemple #1
0
        public void LogDiagnosticsEventTest()
        {
            DiagnosticsEventModel eventModel = new DiagnosticsEventModel
            {
                EventType       = this.rand.NextString(),
                SessionId       = this.rand.NextString(),
                EventProperties = new
                {
                    id   = this.rand.NextString(),
                    test = this.rand.NextString(),
                },
            };

            this.mockClient
            .Setup(x => x.Log(
                       It.IsAny <string>()))
            .Verifiable();

            this.client.LogDiagnosticsEvent(eventModel);

            this.mockClient
            .Verify(
                x => x.Log(
                    It.Is <string>(m => m == JsonConvert.SerializeObject(eventModel, Formatting.Indented))),
                Times.Once);
        }
        public void PostTest()
        {
            DiagnosticsEventModel eventModel = new DiagnosticsEventModel
            {
                EventType       = this.rand.NextString(),
                SessionId       = this.rand.NextString(),
                EventProperties = new
                {
                    id   = this.rand.NextString(),
                    test = this.rand.NextString(),
                },
            };

            this.mockClient
            .Setup(x => x.LogDiagnosticsEvent(
                       It.IsAny <DiagnosticsEventModel>()))
            .Verifiable();

            StatusCodeResult response = this.controller.Post(eventModel);

            this.mockClient
            .Verify(
                x => x.LogDiagnosticsEvent(
                    It.Is <DiagnosticsEventModel>(m => m.EventType == eventModel.EventType && m.SessionId == eventModel.SessionId && m.EventProperties == eventModel.EventProperties)),
                Times.Once);

            Assert.Equal(PostResponseStatusCode, response.StatusCode);
        }
        public void LogDiagnosticsEvent(DiagnosticsEventModel diagnosticsEvent)
        {
            if (diagnosticsEvent.IsEmpty())
            {
                throw new BadDiagnosticsEventException("The given DiagnosticsEventModel was null or had no content. Empty events will not be logged.");
            }

            try
            {
                string eventLog = JsonConvert.SerializeObject(diagnosticsEvent, Formatting.Indented);
                this.Log(eventLog);
            }
            catch (JsonSerializationException jse)
            {
                throw new BadDiagnosticsEventException(jse.Message, jse);
            }
        }
        public StatusCodeResult Post([FromBody] DiagnosticsEventModel diagnosticsEvent)
        {
            if (diagnosticsEvent == null)
            {
                throw new BadRequestException("The body of the request was null. Please include a json diagnostics event in the body of the request.");
            }

            try
            {
                this.diagnosticsClient.LogDiagnosticsEvent(diagnosticsEvent);
            }
            catch (BadDiagnosticsEventException e)
            {
                throw new BadRequestException(e.Message, e);
            }

            // Status Code 201 = Successfully Created
            return(new StatusCodeResult(201));
        }
Exemple #5
0
        public void LogDiagnosticsEventThrowsWhenLoggingFailsTest()
        {
            DiagnosticsEventModel eventModel = new DiagnosticsEventModel
            {
                EventType       = this.rand.NextString(),
                SessionId       = this.rand.NextString(),
                EventProperties = new
                {
                    id   = this.rand.NextString(),
                    test = this.rand.NextString(),
                },
            };

            this.mockClient
            .Setup(x => x.Log(
                       It.IsAny <string>()))
            .Throws(new Exception());

            Assert.Throws <Exception>(() => this.client.LogDiagnosticsEvent(eventModel));
        }
Exemple #6
0
        public void LogDiagnosticsEventThrowsWhenEmptyTest()
        {
            DiagnosticsEventModel blankModel = new DiagnosticsEventModel();

            Assert.Throws <BadDiagnosticsEventException>(() => this.client.LogDiagnosticsEvent(blankModel));
        }