public void ShouldConstructAnImmutable_WhenGivenAValidObject(Type type) { // Arrange object value; switch (type) { case Type strType when strType == typeof(string): value = "Blah"; break; case Type arrType when arrType.IsArray: value = Activator.CreateInstance(type, new object[] { 3 }); break; default: value = Activator.CreateInstance(type); break; } var expectedType = typeof(Immutable <>).MakeGenericType(new[] { type }); // Act var result = Immutable <object> .CreateImmutable(type, value); // Assert result.Should().BeOfType(expectedType); }
public void ShouldThrowException_WhenGivenAnInvalidObject(Type type) { // Arrange var value = Activator.CreateInstance(type); var expectedType = typeof(Immutable <>).MakeGenericType(new[] { type }); // Act Action result = () => Immutable <object> .CreateImmutable(type, value); // Assert result.Should().Throw <TargetInvocationException>(); }