Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i make a test expecting an exception to be thrown.
here is my code :


C#
[ExpectedException(typeof(Exception))]
       public void AnAddressHasOnly1UserTest()
       {
           Address address = new Address()
           {
               Street ="street1",
               City="city1",
               Number=1,
                State="state1"
           };
           User user = new User()
           {
               UserName="User1",
               Password="1234",
               Address = address,

           };
           context.Users.Add(user);
           User user2 = new User()
           {
               UserName = "User2",
               Password = "1234",
               Address = address
           };
           context.Users.Add(user2);
           context.SaveChanges();

       }


But when i run the test instead of passing the test i get the exception thrown.
Posted
Updated 11-Mar-12 2:48am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900