();
20 | Session["Password"] = "y u store password?";
21 | Session["Secret"] = "A23A854F3DD64CC9BEC6D498A2C097D8";
22 | Session["secret"] = "another secret :o";
23 |
24 | var vars = Request.ServerVariables.AllKeys.Select(k => k + " => " + Request.ServerVariables[k]);
25 |
26 | ViewBag.Vars = string.Join("\n", vars);
27 |
28 | return View();
29 | }
30 |
31 | public ActionResult Error()
32 | {
33 | var ex = new Exception("An error has occurred upon request");
34 | ex.Data["arbitrary_data"] = DateTime.UtcNow;
35 | throw ex;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="RollbarSharp.Mvc4Test.MvcApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Http;
2 | using System.Web.Mvc;
3 | using System.Web.Routing;
4 |
5 | namespace RollbarSharp.Mvc4Test
6 | {
7 | // Note: For instructions on enabling IIS6 or IIS7 classic mode,
8 | // visit http://go.microsoft.com/?LinkId=9394801
9 | public class MvcApplication : System.Web.HttpApplication
10 | {
11 | protected void Application_Start()
12 | {
13 | AreaRegistration.RegisterAllAreas();
14 |
15 | WebApiConfig.Register(GlobalConfiguration.Configuration);
16 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
17 | RouteConfig.RegisterRoutes(RouteTable.Routes);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RollbarSharp.Mvc4Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RollbarSharp.Mvc4Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("37888abd-6a2b-4776-a2a7-6273a55eef79")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/RollbarSharp.Mvc4Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 |
8 |
9 | 2.0
10 | {18636614-E998-4A78-86A4-37BFA9300F8E}
11 | {E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
12 | Library
13 | Properties
14 | RollbarSharp.Mvc4Test
15 | RollbarSharp.Mvc4Test
16 | v4.5
17 | false
18 | false
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | true
28 | full
29 | false
30 | bin\
31 | DEBUG;TRACE
32 | prompt
33 | 4
34 | false
35 |
36 |
37 | pdbonly
38 | true
39 | bin\
40 | TRACE
41 | prompt
42 | 4
43 | false
44 |
45 |
46 |
47 |
48 | ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
49 | True
50 |
51 |
52 | ..\..\packages\Newtonsoft.Json.5.0.1\lib\net45\Newtonsoft.Json.dll
53 | True
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll
66 | True
67 |
68 |
69 | ..\..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll
70 | True
71 |
72 |
73 | ..\..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll
74 | True
75 |
76 |
77 | ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll
78 | True
79 |
80 |
81 | ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll
82 | True
83 |
84 |
85 | ..\..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll
86 | True
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | True
97 | ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll
98 |
99 |
100 | ..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll
101 |
102 |
103 | True
104 | ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll
105 |
106 |
107 | ..\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll
108 |
109 |
110 | ..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll
111 |
112 |
113 |
114 | ..\RollbarSharp\bin\$(Configuration)\RollbarSharp.dll
115 |
116 |
117 |
118 |
119 |
120 |
121 | Global.asax
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | Web.config
133 |
134 |
135 | Web.config
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | {43a8b009-ca64-4d25-845a-fe2a53890fbc}
148 | RollbarSharp
149 |
150 |
151 |
152 |
153 |
154 |
155 | 10.0
156 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | False
169 | True
170 | 51558
171 | /
172 |
173 |
174 | False
175 | False
176 |
177 |
178 | False
179 |
180 |
181 |
182 |
183 |
189 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/RollbarSharp.Mvc4Test.v2.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 | 1000
3 | false
4 | false
5 | false
6 | true
7 | false
8 | false
9 | false
10 | false
11 | false
12 | true
13 | true
14 | false
15 | true
16 | true
17 | true
18 | 60000
19 |
20 |
21 |
22 | AutoDetect
23 | STA
24 | x86
25 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Views/Main/Home.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewBag.Title = "Index";
3 | }
4 |
5 | Index
6 |
7 | Welcome, @User.Identity.Name
8 |
9 | @ViewBag.Vars
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Views/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
39 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Mvc4Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RollbarSharp.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RollbarSharp.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("995de97c-1e1d-45ae-a52e-8558f5b04502")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/RollbarClientTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Net;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using NUnit.Framework;
7 | using RollbarSharp.Builders;
8 |
9 | namespace RollbarSharp.Tests
10 | {
11 | [TestFixture]
12 | public class RollbarClientTest
13 | {
14 | [Test]
15 | public void when_serializing_message_notice_result_should_not_be_empty()
16 | {
17 | var client = new RollbarClient();
18 | var notice = client.NoticeBuilder.CreateMessageNotice("Hello");
19 |
20 | notice.Server.Host = "miker";
21 | notice.Request.Url = "http://localhost/hej";
22 | notice.Request.Method = "GET";
23 |
24 | var serialized = client.Serialize(notice);
25 |
26 | Assert.IsNotNullOrEmpty(serialized);
27 | }
28 |
29 | [Test]
30 | public void when_serializing_exception_notice_result_should_not_be_empty()
31 | {
32 | var client = new RollbarClient();
33 | Exception exception = new NotImplementedException();
34 |
35 | var notice = client.NoticeBuilder.CreateExceptionNotice(exception);
36 | notice.Server.Host = "miker";
37 | notice.Request.Url = "http://localhost/hej";
38 | notice.Request.Method = "GET";
39 | notice.Request.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
40 | notice.Request.UserIp = "67.90.39.34";
41 | notice.Person.Id = "123";
42 | notice.Person.Username = Environment.UserName;
43 |
44 | var serialized = client.Serialize(notice);
45 |
46 | Assert.IsNotNullOrEmpty(serialized);
47 | }
48 |
49 | [Test]
50 | public void when_calling_send_exception_task_returns_and_can_be_used()
51 | {
52 | var client = new RollbarClient();
53 | Exception exception = new NotImplementedException();
54 |
55 | var task = client.SendException(exception);
56 |
57 | Assert.IsNotNull(task);
58 | Assert.DoesNotThrow(() => task.Wait(0));
59 | }
60 |
61 | [Test]
62 | public void when_calling_send_critical_exception_task_returns_and_can_be_used()
63 | {
64 | var client = new RollbarClient();
65 | Exception exception = new NotImplementedException();
66 |
67 | var task = client.SendCriticalException(exception);
68 |
69 | Assert.IsNotNull(task);
70 | Assert.DoesNotThrow(() => task.Wait(0));
71 | }
72 |
73 |
74 | [Test]
75 | public void when_calling_send_error_exception_task_returns_and_can_be_used()
76 | {
77 | var client = new RollbarClient();
78 | Exception exception = new NotImplementedException();
79 |
80 | var task = client.SendErrorException(exception);
81 |
82 | Assert.IsNotNull(task);
83 | Assert.DoesNotThrow(() => task.Wait(0));
84 | }
85 |
86 | [Test]
87 | public void when_calling_send_warning_exception_task_returns_and_can_be_used()
88 | {
89 | var client = new RollbarClient();
90 | Exception exception = new NotImplementedException();
91 |
92 | var task = client.SendWarningException(exception);
93 |
94 | Assert.IsNotNull(task);
95 | Assert.DoesNotThrow(() => task.Wait(0));
96 | }
97 |
98 | [Test]
99 | public void when_calling_send_critical_message_task_returns_and_can_be_used()
100 | {
101 | var client = new RollbarClient();
102 | var message = "";
103 |
104 | var task = client.SendCriticalMessage(message);
105 |
106 | Assert.IsNotNull(task);
107 | Assert.DoesNotThrow(() => task.Wait(0));
108 | }
109 |
110 | [Test]
111 | public void when_calling_send_error_message_task_returns_and_can_be_used()
112 | {
113 | var client = new RollbarClient();
114 | var message = "";
115 |
116 | var task = client.SendErrorMessage(message);
117 |
118 | Assert.IsNotNull(task);
119 | Assert.DoesNotThrow(() => task.Wait(0));
120 | }
121 |
122 | [Test]
123 | public void when_calling_send_warning_message_task_returns_and_can_be_used()
124 | {
125 | var client = new RollbarClient();
126 | var message = "";
127 |
128 | var task = client.SendWarningMessage(message);
129 |
130 | Assert.IsNotNull(task);
131 | Assert.DoesNotThrow(() => task.Wait(0));
132 | }
133 |
134 | [Test]
135 | public void when_calling_send_info_message_task_returns_and_can_be_used()
136 | {
137 | var client = new RollbarClient();
138 | var message = "";
139 |
140 | var task = client.SendInfoMessage(message);
141 |
142 | Assert.IsNotNull(task);
143 | Assert.DoesNotThrow(() => task.Wait(0));
144 | }
145 |
146 | [Test]
147 | public void when_calling_send_debug_message_task_returns_and_can_be_used()
148 | {
149 | var client = new RollbarClient();
150 | var message = "";
151 |
152 | var task = client.SendDebugMessage(message);
153 |
154 | Assert.IsNotNull(task);
155 | Assert.DoesNotThrow(() => task.Wait(0));
156 | }
157 |
158 | [Test]
159 | public void when_calling_send_message_task_returns_and_can_be_used()
160 | {
161 | var client = new RollbarClient();
162 | var message = "";
163 |
164 | var task = client.SendMessage(message, "info");
165 |
166 | Assert.IsNotNull(task);
167 | Assert.DoesNotThrow(() => task.Wait(0));
168 | }
169 |
170 | [Test]
171 | public void when_calling_send_task_returns_and_can_be_used()
172 | {
173 | var client = new RollbarClient();
174 | var message = "";
175 |
176 | var notice = new DataModelBuilder().CreateMessageNotice(message, "debug");
177 |
178 | var task = client.Send(notice, null);
179 |
180 | Assert.IsNotNull(task);
181 | Assert.DoesNotThrow(() => task.Wait(0));
182 | }
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/RollbarSharp.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {898D9D95-D956-4284-82D5-6BFDBFDE14EB}
8 | Library
9 | Properties
10 | RollbarSharp.Tests
11 | RollbarSharp.Tests
12 | v4.5
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | false
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 | false
34 |
35 |
36 |
37 |
38 | ..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll
39 | True
40 |
41 |
42 | ..\RollbarSharp\bin\$(Configuration)\RollbarSharp.dll
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | Code
52 |
53 |
54 | Code
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | {43a8b009-ca64-4d25-845a-fe2a53890fbc}
65 | RollbarSharp
66 |
67 |
68 |
69 |
76 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/RollbarSharp.Tests.v2.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 | 1000
3 | false
4 | false
5 | false
6 | true
7 | false
8 | false
9 | false
10 | false
11 | false
12 | true
13 | true
14 | false
15 | true
16 | true
17 | true
18 | 60000
19 |
20 |
21 |
22 | AutoDetect
23 | STA
24 | x86
25 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/Serialization/ExceptionModelTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NUnit.Framework;
3 | using RollbarSharp.Builders;
4 |
5 | namespace RollbarSharp.Tests.Serialization
6 | {
7 | [TestFixture]
8 | public class ExceptionModelTest
9 | {
10 | [Test]
11 | public void when_creating_from_manually_created_exception_should_have_expected_Class()
12 | {
13 | var ex = new InvalidOperationException("Invalid operation");
14 | var model = ExceptionModelBuilder.CreateFromException(ex);
15 |
16 | Assert.AreEqual(typeof(InvalidOperationException).Name, model.Class);
17 | }
18 |
19 | [Test]
20 | public void when_creating_from_manually_created_exception_should_have_Message_copied()
21 | {
22 | var ex = new InvalidOperationException("Invalid operation");
23 | var model = ExceptionModelBuilder.CreateFromException(ex);
24 |
25 | Assert.AreEqual("Invalid operation", model.Message);
26 | }
27 |
28 | [Test]
29 | public void when_creating_from_thrown_exception_should_have_expected_Class()
30 | {
31 | try
32 | {
33 | CreateException();
34 | }
35 | catch (Exception ex)
36 | {
37 | var model = ExceptionModelBuilder.CreateFromException(ex);
38 |
39 | Assert.AreEqual(typeof(DivideByZeroException).Name, model.Class);
40 | }
41 | }
42 |
43 | [Test]
44 | public void when_creating_from_thrown_exception_should_have_Message()
45 | {
46 | try
47 | {
48 | CreateException();
49 | }
50 | catch (Exception ex)
51 | {
52 | var model = ExceptionModelBuilder.CreateFromException(ex);
53 |
54 | Assert.IsNotNullOrEmpty(model.Message);
55 | }
56 | }
57 |
58 | private int CreateException()
59 | {
60 | var x = 0;
61 | var y = 1 / x;
62 | return y;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/Serialization/NotifierModelTest.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using NUnit.Framework;
3 | using RollbarSharp.Builders;
4 | using RollbarSharp.Serialization;
5 |
6 | namespace RollbarSharp.Tests.Serialization
7 | {
8 | [TestFixture]
9 | public class NotifierModelTest
10 | {
11 | NotifierModel model;
12 |
13 | [SetUp]
14 | public void SetUp()
15 | {
16 | model = NotifierModelBuilder.CreateFromAssemblyInfo();
17 | }
18 |
19 | [Test]
20 | public void when_creating_notifier_from_assembly_info_should_have_RollbarSharp_for_Name()
21 | {
22 | Assert.AreEqual("RollbarSharp", model.Name);
23 | }
24 |
25 | [Test]
26 | public void when_creating_notifier_from_assembly_info_should_have_Version_populated()
27 | {
28 | Assert.IsNotNullOrEmpty(model.Version);
29 | }
30 |
31 | [Test]
32 | public void when_creating_notifier_from_assembly_info_Version_should_match_assembly_version()
33 | {
34 | var expectedVersion = Assembly.GetAssembly(typeof(NotifierModel)).GetName();
35 |
36 | Assert.AreEqual(expectedVersion.Version.ToString(), model.Version);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/Serialization/TraceModelTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using NUnit.Framework;
4 | using RollbarSharp.Builders;
5 | using System.Reflection;
6 |
7 | namespace RollbarSharp.Tests.Serialization
8 | {
9 | [TestFixture]
10 | public class TraceModelTest
11 | {
12 | [Test]
13 | public void when_creating_from_thrown_exception_should_have_frames()
14 | {
15 | try
16 | {
17 | GenerateException(null);
18 | }
19 | catch (Exception ex)
20 | {
21 | var model = TraceChainModelBuilder.CreateFromException(ex).FirstOrDefault();
22 | Assert.IsNotNull(model.Frames);
23 | }
24 | }
25 |
26 | [Test]
27 | public void when_creating_from_thrown_exception_should_have_more_than_0_frames()
28 | {
29 | try
30 | {
31 | GenerateException(null);
32 | }
33 | catch (Exception ex)
34 | {
35 | var model = TraceChainModelBuilder.CreateFromException(ex).FirstOrDefault();
36 | Assert.Greater(model.Frames.Length, 0);
37 | }
38 | }
39 |
40 | [Test]
41 | public void when_creating_from_thrown_exception_should_have_Exception_model()
42 | {
43 | try
44 | {
45 | GenerateException(null);
46 | }
47 | catch (Exception ex)
48 | {
49 | var model = TraceChainModelBuilder.CreateFromException(ex).FirstOrDefault();
50 | Assert.IsNotNull(model.Exception);
51 | }
52 | }
53 |
54 | [Test()]
55 | public void when_creating_from_thrown_within_reflection_call_exception_should_have_Exception_model()
56 | {
57 | var method = this.GetType().GetMethod("MethodWithException");
58 | try
59 | {
60 | method.Invoke(this, new object[]{ null });
61 | Assert.Fail("The previous call must throw an exception");
62 | }
63 | catch (Exception ex)
64 | {
65 | var model = TraceChainModelBuilder.CreateFromException(ex).FirstOrDefault();
66 | Assert.IsNotNull(model.Exception);
67 | }
68 | }
69 |
70 | private int GenerateException(string noparam)
71 | {
72 | var x = 0;
73 | var q = 1 / x;
74 | return q;
75 | }
76 |
77 | public void MethodWithException(string noparam)
78 | {
79 | throw new ArgumentException("Test exception");
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/RollbarSharp.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/RollbarSharp/Builders/BodyModelBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using RollbarSharp.Serialization;
4 |
5 | namespace RollbarSharp.Builders
6 | {
7 | ///
8 | /// Builder for the 'body' of the request.
9 | /// This will be either an exception with details
10 | /// or a plain text message with optional fields
11 | ///
12 | public static class BodyModelBuilder
13 | {
14 | public static ExceptionBodyModel CreateExceptionBody(Exception exception)
15 | {
16 | var traces = TraceChainModelBuilder.CreateFromException(exception);
17 | return new ExceptionBodyModel(traces);
18 | }
19 |
20 | public static MessageBodyModel CreateMessageBody(string message, IDictionary customData)
21 | {
22 | return new MessageBodyModel(message, customData);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/RollbarSharp/Builders/DataModelBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Collections.Generic;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 | using System.Web;
7 | using RollbarSharp.Serialization;
8 |
9 | namespace RollbarSharp.Builders
10 | {
11 | public class DataModelBuilder
12 | {
13 | public Configuration Configuration { get; protected set; }
14 |
15 | public DataModelBuilder()
16 | :this(Configuration.CreateFromAppConfig())
17 | {
18 | }
19 |
20 | public DataModelBuilder(Configuration configuration)
21 | {
22 | Configuration = configuration;
23 | }
24 |
25 | public DataModel CreateExceptionNotice(Exception ex, string message = null, string level = "error")
26 | {
27 | var body = BodyModelBuilder.CreateExceptionBody(ex);
28 | var model = Create(level, body);
29 |
30 | //merge exception data dictionaries to list of keyValues pairs
31 | var keyValuePairs = body.TraceChain.Where(tm => tm.Exception.Data != null).SelectMany(tm => tm.Exception.Data);
32 |
33 | foreach (var keyValue in keyValuePairs)
34 | {
35 | //the keys in keyValuePairs aren't necessarily unique, so don't add but overwrite
36 | model.Custom[keyValue.Key.ToString()] = keyValue.Value;
37 | }
38 |
39 | model.Title = message;
40 |
41 | return model;
42 | }
43 |
44 | public DataModel CreateMessageNotice(string message, string level = "info", IDictionary customData = null)
45 | {
46 | return Create(level, BodyModelBuilder.CreateMessageBody(message, customData));
47 | }
48 |
49 | ///
50 | /// Create the best stub of a request that we can using the message level and body
51 | ///
52 | ///
53 | ///
54 | ///
55 | protected DataModel Create(string level, BodyModel body)
56 | {
57 | var model = new DataModel(level, body);
58 |
59 | model.CodeVersion = Configuration.CodeVersion;
60 | model.Environment = Configuration.Environment;
61 | model.Platform = Configuration.Platform;
62 | model.Language = Configuration.Language;
63 | model.Framework = Configuration.Framework;
64 |
65 | model.Timestamp = (ulong)Now();
66 |
67 | model.Notifier = NotifierModelBuilder.CreateFromAssemblyInfo();
68 |
69 | var currentHttpRequest = GetCurrentHttpRequest();
70 |
71 | if (currentHttpRequest == null)
72 | {
73 | model.Request = new RequestModel();
74 | model.Server = new ServerModel();
75 |
76 | //Obtain person information on non-hosted environment only
77 | model.Person = System.Web.Hosting.HostingEnvironment.IsHosted
78 | ? new PersonModel()
79 | : PersonModelBuilder.CreateFromEnvironment();
80 | }
81 | else
82 | {
83 | model.Request = RequestModelBuilder.CreateFromHttpRequest(currentHttpRequest, HttpContext.Current.Session, Configuration.ScrubParams);
84 | model.Server = ServerModelBuilder.CreateFromHttpRequest(currentHttpRequest);
85 | model.Person = PersonModelBuilder.CreateFromHttpRequest(currentHttpRequest);
86 | }
87 |
88 | model.Server.GitSha = Configuration.GitSha;
89 |
90 | return model;
91 | }
92 |
93 | ///
94 | /// Returns the current HttpRequest. If not available, returns null
95 | ///
96 | ///
97 | private static HttpRequest GetCurrentHttpRequest()
98 | {
99 | var cx = HttpContext.Current;
100 | HttpRequest req = null;
101 |
102 | if (cx != null)
103 | {
104 |
105 | //In the Application_Start HttpContext.Request is not available.
106 | //Instead of HttpContext.Request returning null, it throws an exception. So we swallow the exception here.
107 | try
108 | {
109 | req = cx.Request;
110 | }
111 | catch (HttpException)
112 | {
113 |
114 | }
115 |
116 | }
117 |
118 | return req;
119 | }
120 |
121 | ///
122 | /// Current UTC date time as a UNIX timestamp
123 | ///
124 | ///
125 | private static double Now()
126 | {
127 | var epoch = new DateTime(1970, 1, 1);
128 | return (DateTime.UtcNow - epoch).TotalSeconds;
129 | }
130 |
131 | public static string FingerprintHash(params object[] fields)
132 | {
133 | return FingerprintHash(string.Join(",", fields));
134 | }
135 |
136 | ///
137 | /// To make sure fingerprints are the correct length and don't
138 | /// contain any problematic characters, SHA1 the fingerprint.
139 | ///
140 | ///
141 | ///
142 | public static string FingerprintHash(string data)
143 | {
144 | using (var sha = new SHA1Managed())
145 | {
146 | var bytes = Encoding.UTF8.GetBytes(data);
147 | var hash = sha.ComputeHash(bytes);
148 | return BitConverter.ToString(hash).Replace("-", string.Empty);
149 | }
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/RollbarSharp/Builders/ExceptionModelBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using RollbarSharp.Serialization;
4 |
5 | namespace RollbarSharp.Builders
6 | {
7 | public static class ExceptionModelBuilder
8 | {
9 | ///
10 | /// Converts an exception to an .
11 | ///
12 | public static ExceptionModel CreateFromException(Exception ex)
13 | {
14 | var m = new ExceptionModel(ex.GetType().Name, ex.Message);
15 |
16 | if (ex.Data.Count > 0)
17 | m.Data = ex.Data.Keys.Cast