|
3 | 3 | using NSubstitute.Extensions;
|
4 | 4 | using NUnit.Framework;
|
5 | 5 | using System;
|
6 |
| -using System.Collections.Generic; |
7 |
| -using System.Text; |
8 | 6 |
|
9 | 7 | namespace AutofacContrib.NSubstitute.Tests
|
10 | 8 | {
|
@@ -92,9 +90,61 @@ public void FailsIfSubstituteTypeIsChanged2()
|
92 | 90 | Assert.Throws<InvalidOperationException>(() => builder.SubstituteFor<Test1>());
|
93 | 91 | }
|
94 | 92 |
|
| 93 | + [Test] |
| 94 | + public void PropertiesNotSetByDefault() |
| 95 | + { |
| 96 | + using var mock = AutoSubstitute.Configure() |
| 97 | + .Provide<IProperty, CustomProperty>(out _) |
| 98 | + .SubstituteFor<TestWithProperty>().Configured() |
| 99 | + .Build(); |
| 100 | + |
| 101 | + Assert.IsNull(mock.Resolve<TestWithProperty>().PropertySetter); |
| 102 | + Assert.That(mock.Resolve<TestWithProperty>().VirtualProperty, Is.NSubstituteMock); |
| 103 | + } |
| 104 | + |
| 105 | + [Test] |
| 106 | + public void PropertiesSetIfRequested() |
| 107 | + { |
| 108 | + using var mock = AutoSubstitute.Configure() |
| 109 | + .Provide<IProperty, CustomProperty>(out var property) |
| 110 | + .SubstituteFor<TestWithProperty>() |
| 111 | + .InjectProperties() |
| 112 | + .Configured() |
| 113 | + .Build(); |
| 114 | + |
| 115 | + Assert.AreEqual(property.Value, mock.Resolve<TestWithProperty>().PropertySetter); |
| 116 | + Assert.AreEqual(property.Value, mock.Resolve<TestWithProperty>().VirtualProperty); |
| 117 | + } |
| 118 | + |
| 119 | + [Test] |
| 120 | + public void PropertiesSetIfGloballyRequested() |
| 121 | + { |
| 122 | + using var mock = AutoSubstitute.Configure() |
| 123 | + .InjectProperties() |
| 124 | + .Provide<IProperty, CustomProperty>(out var property) |
| 125 | + .SubstituteFor<TestWithProperty>().Configured() |
| 126 | + .Build(); |
| 127 | + |
| 128 | + Assert.AreEqual(property.Value, mock.Resolve<TestWithProperty>().PropertySetter); |
| 129 | + Assert.AreEqual(property.Value, mock.Resolve<TestWithProperty>().VirtualProperty); |
| 130 | + } |
| 131 | + |
95 | 132 | public abstract class Test1
|
96 | 133 | {
|
97 | 134 | public virtual object Throws() => throw new InvalidOperationException();
|
98 | 135 | }
|
| 136 | + |
| 137 | + public abstract class TestWithProperty |
| 138 | + { |
| 139 | + public IProperty PropertySetter { get; set; } |
| 140 | + |
| 141 | + public virtual IProperty VirtualProperty { get; } |
| 142 | + } |
| 143 | + |
| 144 | + public interface IProperty |
| 145 | + { |
| 146 | + } |
| 147 | + |
| 148 | + public class CustomProperty : IProperty { } |
99 | 149 | }
|
100 | 150 | }
|
0 commit comments