This is a migrated thread and some comments may be shown as answers.

In the words of Julie Andrews ...

5 Answers 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 05 Sep 2010, 06:10 PM
... let's start at the very beginning.

First, I want to apologise for a posting that it only loosely based on JustMock.

I have never written a unit test in my life and thought, given that I have access to JustMock, that I should give it a go and that's why I need help.

I'll explain.

I'm running VS2K8SP1 under Win7 Ultimate to develop Web Sites and Wep Applications.

I've done a bit of reading and have created a Test Project with a Test Method. My reading has led me to understand that I need to decorate my Test Method like this...
[TestMethod]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:50612/TestBed/Default3.aspx")]

Trying to run this test resulting in a fail with the message ...

The test or test run is configured to run in ASP.NET in IIS, but the current user (Tosh-Laptop\Stuart) is not in the Administrators group. Running tests in ASP.NET in IIS requires the user to be in the Administrators group.

The thing is, I am in the Administrators group. The output from the command net localgroup Administrators confirms this ...
C:\Users\Stuart>net localgroup Administrators
Alias name     Administrators
Comment        Administrators have complete and unrestricted access to the compu
ter/domain
 
Members
 
-------------------------------------------------------------------------------
Administrator
Stuart
The command completed successfully.

So, I guess I'm missing something. Is anyone here running tests under a similar environment? Is anyone here better versed in what's needed to get me running.

Any help, either here, or - if you feel the response too off-topic for posting here - direct to me at sejhemming@gmail.com would be much appreciated.

-- 
Stuart

5 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 05 Sep 2010, 08:54 PM
<fx>Time passes</fx>

Well nothing I've done has allowed me to create a working test on my Web Site. That said, I've discovered from this MSDN page that unit tests are of limited utility on a Web Site as only code in the App_code folder can be tested meaning that none of my page or control code can! :-)

Unbowed, I decided to have a try with a Web Application. I have created the app and I let VS create a test class for me and, lo, it worked, although my Test Methods are decorated differently...
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users\\Stuart\\Documents\\Visual Studio 2008\\Projects\\WebApplication\\WebApplication", "/")]
[UrlToTest("http://localhost:49573/")]

I created a class had VS create a test on it for me. The class looked like this ...
public class Class1
{
    public string Name;
    public Class1()
    {
        Initialize();
    }
    void Initialize()
    {
        Name = "Unnamed";
    }
}
 
And my test looks like this ...
public void Class1ConstructorTest()
{
    Class1 target = new Class1();
    Assert.AreEqual(target.Name, "Unnamed");
}

So far, so good.

Now if I've understood anything I've read, the idea behind Mocking is to allow me to 'mock' Object X and whilst I test Object  Y's functionality, so I understand that my next test isn't really in keeping with that, but,,, Anyhow, I modified the test above to just create a Mock of Class1...
public void Class1ConstructorTest()
{
    var target = Mock.Create<Class1>();
}

Running the test resulted in the following error...

Test method TestProject1.Class1Test.Class1ConstructorTest threw exception:  System.ArgumentException: Unable to obtain public key for StrongNameKeyPair.

And there was an Error Stack Trace too.

So:
  1. Have I done it wrong, or
  2. Is it broken?

-- 
Stuart

0
Ricky
Telerik team
answered on 06 Sep 2010, 08:57 AM
Hi Stuart,

Thanks for the question. In order to mock ASP.NET page class you can additionally provide us with the specific scenario that you are trying to mock so that we can provide further help with your test methods. Also, if you are trying to mock the Page class then you can do that directly with justmock rather setting up development server and hitting the actual URL during your test which is actually making your tests dependant on external factor.

To find more on mocking Page class, please take a look at the following link:
http://weblogs.asp.net/mehfuzh/archive/2010/04/29/playing-with-aspx-page-cycle-using-justmock.aspx

Finally, regarding the error:
Test method TestProject1.Class1Test.Class1ConstructorTest threw exception: System.ArgumentException: Unable to obtain public key for StrongNameKeyPair.

I would recommend to take a look at the following link as well:
http://stackoverflow.com/questions/2359506/unable-to-obtain-public-key-for-strongnamekeypair


Kind Regards,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stuart Hemming
Top achievements
Rank 2
answered on 06 Sep 2010, 10:07 AM
Thanks for the links. I'll have a read.

-- 
Stuart
0
Stuart Hemming
Top achievements
Rank 2
answered on 06 Sep 2010, 09:16 PM
> I would recommend to take a look at the following link as well: 
http://stackoverflow.com/questions/2359506/unable-to-obtain-public-key-for-strongnamekeypair 
If you believe that this link provides anything approaching an answer to this issue then you're a better man than I!

-- 
Stuart
0
Ricky
Telerik team
answered on 07 Sep 2010, 11:49 AM
Hi Stuart,

Thanks for pointing the issue. However, the error "Unable to obtain public key for StrongNameKeyPair" can occur, only if your project don't have sufficient privilege to access the file or you can no longer sign assemblies on the fly like JustMock does.

I have found few more resources that further address the issue:

http://support.targetprocess.com/Default.aspx?g=posts&t=305
http://ayende.com/Blog/archive/2006/06/09/UnableToObtainPublicKeyForStrongNameKeyPair.aspx

Additionally, I have attached a project that is constructed using the steps mentioned in your post. Please check it out as well. To run the test, you just need to modify the AspNetDevelopmentServerHost attribute to point to your development server. I have used JustMock SP1 for mocking the generated class.

Finally, please make sure that you have turned on strong naming for the website and it is configured properly.





Sincerely yours,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Ricky
Telerik team
Share this question
or