Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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>());
        }
Ejemplo n.º 3
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>());
        }
Ejemplo n.º 4
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>();
        }
Ejemplo n.º 5
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>();
        }
Ejemplo n.º 6
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("/");
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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();
        }