public void ConstructObject_GivenParameterValues_ShouldConstructObjectWithParameterValues() { //---------------Set up test pack------------------- var testDateTime = DateTime.Now; var fakeComplex = new FakeComplex(); var parameterValues = new List <(string paramName, object paramValue)> { ("testDateTime", testDateTime), ("complexObject", fakeComplex) }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var testClass = ConstructorTestHelper.ConstructObject <FakeTestClass>(constructorParams: parameterValues.ToArray()); //---------------Test Result ----------------------- testClass.TestDateTime.Should().BeSameDateAs(testDateTime); testClass.ComplexObject2.Should().Be(fakeComplex); }
public void ValidateExceptionIsThrownIfParameterIsNull_GivenParameterValuesAndExceptionNotThrown_ShouldFailTest() { //---------------Set up test pack------------------- var parameterName = "notSetParameter"; var testDateTime = DateTime.Now; var fakeComplex = new FakeComplex(); var parameterValues = new List <(string paramName, object paramValue)> { ("testDateTime", testDateTime), ("complexObject", fakeComplex) }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var exception = Assert.Throws <AssertionException>(() => ConstructorTestHelper.ValidateExceptionIsThrownIfParameterIsNull <FakeTestClass, ArgumentNullException>(parameterName, constructorParams: parameterValues.ToArray())); //---------------Test Result ----------------------- exception.Message.Should().Contain($"ArgumentNullException Exception not throw for Constructor Parameter [{parameterName}] on {typeof(FakeTestClass).FullName}"); }
public FakeTestClass(Guid fakeId, string testName, int testIntValue, bool isActive, // ReSharper disable once UnusedParameter.Local string notSetParameter, DateTime testDateTime, FakeComplex complexObjectNotTested, FakeComplex complexObject, IFakeComplex complexInterface, FakeTestEnum testEnum, IEnumerable <IFakeComplex> allFakes = null, Dictionary <string, string> testDictionary = null, IDictionary <string, object> testDictionary2 = null) : this(testDictionary, testDictionary2) { Id = fakeId; Name = testName ?? throw new ArgumentNullException(nameof(testName)); IntValue = testIntValue; IsActive = isActive; TestDateTime = testDateTime; ComplexObject1 = complexObjectNotTested; ComplexObject2 = complexObject ?? throw new ArgumentNullException(nameof(complexObject)); ComplexObject3 = complexInterface ?? throw new ArgumentNullException(nameof(complexInterface)); TestEnum = testEnum; FakeList = allFakes; }