public void ShouldThrowWithInvalidVariableType() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <Action>("_value"); //Act Action action = () => subject.AssertFieldsAreExpectedType(new VariabledClass()); //Assert action.Should().Throw <AsserterException>().WithMessage("Expected [name=_value] to be of [type=Action] but found [type=String]"); }
public void ShouldNotThrowGivenMatchingPrimitive() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <string>("_value", "stringValue"); VariabledClass target = new VariabledClass(); //Act subject.AssertFieldsAreExpectedType(target); //Assert }
public void ShouldNotThrowWithValidVariable() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <string>("_value"); //Act Action action = () => subject.AssertFieldsAreExpectedType(new VariabledClass()); //Assert action.Should().NotThrow(); }
public void ShouldThrowWithInvalidVariableName() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <string>("_value2"); //Act Action action = () => subject.AssertFieldsAreExpectedType(new VariabledClass()); //Assert action.Should().Throw <Exception>().WithMessage("Expected field [name=_value2] to be of [type=string] but a field [name=_value2] was not found."); }
public void ShouldNotThrowGivenEquatableObject() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <EquatableObject>("_eo", new EquatableObject("SomeValue")); //Act Action action = () => subject.AssertFieldsAreExpectedType(new EquatableObjectContainer(new EquatableObject("SomeValue"))); //Assert action.Should().NotThrow(); }
public void ShouldThrowGivenEquatableNonEqualObject() { //Arrange ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <EquatableObject>("_eo", new EquatableObject("SomeValue")); //Act Action action = () => subject.AssertFieldsAreExpectedType(new EquatableObjectContainer(new EquatableObject("OtherValue"))); //Assert action.Should().Throw <AsserterException>().WithMessage( "Field [name=_eo] is not the same reference as expected and does not '#Equals()' actual. [expected=InterfaceMocksTests.Validators.ClassVariableTypeValidationTests+EquatableObject] [actual =InterfaceMocksTests.Validators.ClassVariableTypeValidationTests+EquatableObject]"); }
public void ShouldThrowGivenDifferentObjects() { //Arrange ExampleObject exampleObject = new ExampleObject(new VariabledClass()); ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <VariabledClass>("_variable", new VariabledClass()); //Act Action action = () => subject.AssertFieldsAreExpectedType(exampleObject); //Assert action.Should().Throw <AsserterException>().WithMessage( "Field [name=_variable] is not the same reference as expected and does not '#Equals()' actual. [expected=InterfaceMocksTests.Validators.ClassVariableTypeValidationTests+VariabledClass] [actual =InterfaceMocksTests.Validators.ClassVariableTypeValidationTests+VariabledClass]"); }
public void ShouldNotThrowGivenSameObject() { //Arrange VariabledClass expectedValue = new VariabledClass(); ExampleObject exampleObject = new ExampleObject(expectedValue); ClassVariableTypeValidation subject = new ClassVariableTypeValidation() .FieldShouldBeType <VariabledClass>("_variable", expectedValue); //Act Action action = () => subject.AssertFieldsAreExpectedType(exampleObject); //Assert action.Should().NotThrow(); }
public void ShouldValidateTheVariables() { //Arrange ClassVariableTypeValidation classVariableTypeValidation = new ClassVariableTypeValidation() .FieldShouldBeType <MockMethodWithParam <string> >("_paramMethod") .FieldShouldBeType <MockMethodWithResponse <bool> >("_responseMethod"); //Act MockMethodWithParamAndResponse <string, bool> subject = new MockMethodWithParamAndResponse <string, bool>("hah"); //Assert classVariableTypeValidation.AssertFieldsAreExpectedType(subject); }