public void Submit()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var port = ((IPEndPoint)listener.LocalEndpoint).Port;

            listener.BeginAcceptSocket(AcceptAndRead, listener);
            ExceptionDTO DTO = null;

            try
            {
                int a = 100;
                int b = 200;
                var c = a / (b - 200);
            }
            catch (Exception e)
            {
                DTO = new ExceptionDTO(e);
            }
            var e1 = new ErrorReportDTO("dsjklsdfl", DTO, new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri("http://localhost:" + port + "/receiver");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            sut.UploadReport(e1);
        }
        public void SubmitShouldCorrectlyBuild()
        {
            var          apiKey       = Guid.NewGuid();
            const string sharedSecret = "SomeSharedSecret";
            var          url          = new Uri("http://localhost");
            var          reporter     = new UploadToCoderr(url, apiKey.ToString(), sharedSecret);
            ExceptionDTO DTO          = null;

            try
            {
                int a = 100;
                int b = 200;
                var c = a / (b - 200);
            }
            catch (Exception e)
            {
                DTO = new ExceptionDTO(e);
            }

            ErrorReportDTO e1 = new ErrorReportDTO("dsadasdas", DTO,
                                                   new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var compress = reporter.CompressErrorReport(e1);
            var deflated = reporter.DeflateErrorReport(compress);

            Assert.True(compress.Length >= 200);
            Assert.Contains("dsadasdas", deflated);
        }
        public void Should_not_throw_exception_when_ThrowExceptions_is_true_and_feedback_upload_succeeds()
        {
            var uri         = new Uri($"http://localhost:{_listener.LocalPort}/coderr/");
            var feedbackDto = new FeedbackDTO {
                Description = "Hello world"
            };

            var sut = new UploadToCoderr(uri, "api", "secret", () => false, () => true);

            sut.UploadFeedback(feedbackDto);
        }
        public void Should_not_throw_exception_when_ThrowExceptions_is_true_and_report_upload_succeeds()
        {
            var uri           = new Uri($"http://localhost:{_listener.LocalPort}/coderr/");
            var collectionDto = new ContextCollectionDTO("MyName", new Dictionary <string, string> {
                { "Key", "Val" }
            });
            var report = new ErrorReportDTO("aaa", new ExceptionDTO(new Exception()), new[] { collectionDto });

            var sut = new UploadToCoderr(uri, "api", "secret", () => false, () => true);

            sut.UploadReport(report);
        }
示例#5
0
        public void should_queue_reports_when_specified()
        {
            var report = Substitute.For <ErrorReportDTO>();
            var uri    = new Uri("http://localhost");

            _config.QueueReportsAccessor = () => true;

            var sut = new UploadToCoderr(uri, "ada", "cesar", _config);

            sut.UploadReport(report);

            _config.ReportQueue.Received().Enqueue(Arg.Any <ErrorReportDTO>());
        }
        public void Should_throw_exception_when_ThrowExceptions_and_feedback_upload_fails()
        {
            _listener.Stop();
            var feedbackDto = new FeedbackDTO {
                Description = "Hello world"
            };

            var    uri    = new Uri($"http://localhost:{_listener.LocalPort}/coderr/");
            var    sut    = new UploadToCoderr(uri, "api", "secret", () => false, () => true);
            Action actual = () => sut.UploadFeedback(feedbackDto);

            actual.ShouldThrow <Exception>();
        }
示例#7
0
        public void should_queue_feedback_when_specified()
        {
            var dto = Substitute.For <FeedbackDTO>();
            var uri = new Uri("http://localhost");

            _config.QueueReportsAccessor = () => true;

            var sut = new UploadToCoderr(uri, "ada", "cesar", _config);

            sut.UploadFeedback(dto);

            _config.FeedbackQueue.Received().Enqueue(Arg.Any <FeedbackDTO>());
        }
示例#8
0
        public Reporter(Uri address, string appKey, string sharedSecret)
        {
            _config = new CoderrConfiguration();

            // Make sure that the collection exists so that other tests can use it.
            _config.ExceptionPreProcessor = context =>
                                            context.ContextCollections.GetCoderrCollection().Properties.Add("Hello", "Test");

            _config.EnvironmentName = "IntegrationTests";
            _uploader = new UploadToCoderr(address, appKey, sharedSecret);
            _config.Uploaders.Register(_uploader);
            _processor = new ExceptionProcessor(_config);
        }
示例#9
0
        public void should_pack_and_sign_an_entity_correctly()
        {
            var          apiKey       = Guid.NewGuid();
            const string sharedSecret = "SomeSharedSecret";
            var          url          = new Uri("http://localhost");
            var          reporter     = new UploadToCoderr(url, apiKey.ToString(), sharedSecret);
            var          dto          = CreateExceptionDTO();

            var e1 = new ErrorReportDTO("dsadasdas", dto,
                                        new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var message = reporter.CreateRequest("http://somewherre.com/report", e1);
        }
示例#10
0
        public void should_be_able_to_upload_correctly()
        {
            var listener = new ListenerStub();
            var dto      = CreateExceptionDTO();
            var e1       = new ErrorReportDTO("dsjklsdfl", dto,
                                              new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri($"http://localhost:{listener.ListenerPort}/");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            sut.UploadReport(e1);

            listener.Wait(5000).Should().BeTrue();
        }
示例#11
0
        public void should_throw_exceptions_when_upload_fails_when_configured()
        {
            _config.ThrowExceptionsAccessor = () => true;
            var dto = Substitute.For <FeedbackDTO>();
            var uri = new Uri("http://localhost");

            _config.UploadFunc = message => throw new InvalidOperationException("err");

            var    sut    = new UploadToCoderr(uri, "ada", "cesar", _config);
            Action actual = () => sut.UploadFeedback(dto);


            actual.ShouldThrow <InvalidOperationException>();
        }
示例#12
0
        private UploadToCoderr GetUploader(CodErrConfig codErrConfig)
        {
            if (codErrConfig != null && codErrConfig.IsConfigured())
            {
                var codErrUploader = new UploadToCoderr(new Uri(codErrConfig.ApiUrl), codErrConfig.AppKey, codErrConfig.AppSecret);

                codErrUploader.MaxQueueSize  = codErrConfig.MaxQueueSize;
                codErrUploader.MaxAttempts   = codErrConfig.MaxAttempts;
                codErrUploader.RetryInterval = codErrConfig.RetryInterval;

                return(codErrUploader);
            }

            return(null);
        }
示例#13
0
        public void should_always_throw_when_queing_is_configured_to_allow_retries()
        {
            _config.QueueReportsAccessor = () => true;
            var dto = Substitute.For <FeedbackDTO>();
            var uri = new Uri("http://localhost");

            _config.UploadFunc = message =>
            {
                throw new InvalidOperationException("err");
            };

            var    sut    = new UploadToCoderr(uri, "ada", "cesar", _config);
            Action actual = () => sut.UploadFeedbackNow(dto);


            actual.ShouldThrow <InvalidOperationException>();
        }
示例#14
0
        public void should_make_sure_that_the_uri_ends_with_a_slash()
        {
            var report             = Substitute.For <ErrorReportDTO>();
            HttpRequestMessage msg = null;
            var uri = new Uri("http://localhost");

            _config.UploadFunc = x =>
            {
                msg = x;
                return(Task.FromResult(new HttpResponseMessage()));
            };


            var sut = new UploadToCoderr(uri, "ada", "cesar", _config);

            sut.UploadReport(report);

            msg.RequestUri.ToString().EndsWith("/");
        }
示例#15
0
        //[Fact] //TODO: Readd
        public void should_report_invalid_app_key()
        {
            var listener = new ListenerStub("400 APP_KEY");
            var dto      = CreateExceptionDTO();
            var e1       = new ErrorReportDTO("dsjklsdfl", dto,
                                              new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri($"http://localhost:{listener.ListenerPort}/");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            try
            {
                sut.UploadReport(e1);
                listener.Wait(5000);
                throw new InvalidOperationException("Test failed");
            }
            catch (InvalidApplicationKeyException)
            {
            }
        }
示例#16
0
        public void should_be_able_to_upload_correctly()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var port = ((IPEndPoint)listener.LocalEndpoint).Port;

            listener.AcceptSocketAsync().ContinueWith(AcceptAndRead);
            var dto = CreateExceptionDTO();
            var e1  = new ErrorReportDTO("dsjklsdfl", dto,
                                         new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri("http://localhost:" + port + "/");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            sut.UploadReport(e1);
            _tcs.Task.Wait(1000);

            listener.Stop();
            _tcs.Task.Status.Should().Be(TaskStatus.RanToCompletion);
        }
示例#17
0
        public void should_report_invalid_app_key()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var port = ((IPEndPoint)listener.LocalEndpoint).Port;

            listener.AcceptSocketAsync().ContinueWith(AcceptAndRead);
            var dto = CreateExceptionDTO();
            var e1  = new ErrorReportDTO("dsjklsdfl", dto,
                                         new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            _statusCodeToReturn = "400 APP_KEY";

            var    url = new Uri("http://localhost:" + port + "/");
            var    sut = new UploadToCoderr(url, "cramply", "majs");
            Action e   = () => sut.UploadReport(e1);


            e.ShouldThrow <InvalidApplicationKeyException>();
            listener.Stop();
        }