Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using NSubstitute.Exceptions;
  3. using NUnit.Framework;
  4.  
  5. namespace NSubstitute.Acceptance.Specs
  6. {
  7. public class PropertyBehaviour
  8. {
  9. public interface IFoo
  10. {
  11. string Name { get; set; }
  12. DateTime Now { get; }
  13. string WriteOnly { set; }
  14. string this[int i] { get; set; }
  15. string this[string a, string b] { get; set; }
  16. }
  17.  
  18. protected object _ignored;
  19.  
  20. /* -- addded the following tests to the original file -- */
  21.  
  22. [Test]
  23. public void Properties_Return_Expected_Values()
  24. {
  25. var foo = Substitute.For<IFoo>();
  26. foo.Name = "This name";
  27. Assert.That(foo.Name, Is.EqualTo("This name"));
  28.  
  29. var bar = Substitute.For<IFoo>();
  30. bar.Name.Returns("This name");
  31. Assert.That(bar.Name, Is.EqualTo("This name"));
  32. }
  33.  
  34. [Test]
  35. public void Set_Property_To_Value_Of_Another_By_Assignment()
  36. {
  37. var foo = Substitute.For<IFoo>();
  38. foo.Name = "This name";
  39.  
  40. var bar = Substitute.For<IFoo>();
  41. bar.Name = foo.Name;
  42.  
  43. Assert.That(foo.Name, Is.EqualTo("This name"));
  44. Assert.That(bar.Name, Is.EqualTo("This name"));
  45. }
  46.  
  47. [Test]
  48. public void Set_Property_To_Value_Of_Another_By_Return_Value()
  49. {
  50. var foo = Substitute.For<IFoo>();
  51. foo.Name.Returns("This name");
  52.  
  53. var bar = Substitute.For<IFoo>();
  54. bar.Name.Returns(foo.Name);
  55.  
  56. Assert.That(foo.Name, Is.EqualTo("This name"));
  57. Assert.That(bar.Name, Is.EqualTo("This name"));
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement