Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is not working? What are you storing in the <code>Session["SubCategory"]</code>?</p> <p>These tests pass when storing string representing the ID in the session object:</p> <pre><code>[Test] public void GivenWhenIntegerString_WhenTryParse_ThenValidInteger() { Dictionary&lt;string, Object&gt; fakeSession = new Dictionary&lt;string, object&gt;(); fakeSession["SubCategory"] = "5"; decimal tmp; decimal? IdSubCategory = null; if (decimal.TryParse((string)fakeSession["SubCategory"], out tmp)) IdSubCategory = tmp; Assert.That(IdSubCategory, Is.EqualTo(5d)); } [Test] public void GivenWhenNull_WhenTryParse_ThenNull() { Dictionary&lt;string, Object&gt; fakeSession = new Dictionary&lt;string, object&gt;(); fakeSession["SubCategory"] = null; decimal tmp; decimal? IdSubCategory = null; if (decimal.TryParse((string)fakeSession["SubCategory"], out tmp)) IdSubCategory = tmp; Assert.That(IdSubCategory, Is.EqualTo(null)); } </code></pre> <p>This test fails when you store the <code>int</code> or <code>decimal</code> in <code>Session["SubCategory"]</code></p> <pre><code>[Test] public void GivenWhenInteger_WhenTryParse_ThenValidInteger() { Dictionary&lt;string, Object&gt; fakeSession = new Dictionary&lt;string, object&gt;(); fakeSession["SubCategory"] = 5; decimal tmp; decimal? IdSubCategory = null; if (decimal.TryParse((string)fakeSession["SubCategory"], out tmp)) IdSubCategory = tmp; Assert.That(IdSubCategory, Is.EqualTo(5d)); } </code></pre> <p>In this case, this will fix it:</p> <pre><code>decimal tmp; decimal? IdSubCategory = null; if (Session["SubCategory"] != null &amp;&amp; decimal.TryParse(Session["SubCategory"].ToString(), out tmp)) IdSubCategory = tmp; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload