public void ExtractInstanceMembers_ClassWithMethods() { IExtractor extractor = new Extractor(typeof(ClassWithMethods)); const string interfaceName = "Custom.Namespace.IMyClass"; const string implementationName = "Custom.Namespace.SMyClass"; var actualInterface = extractor.ExtractInterfaceForInstanceMembers(interfaceName); var actualImplementation = extractor.ExtractImplementationForInstanceMembers(interfaceName, implementationName); write_output(actualInterface, actualImplementation); var expected = @" namespace Custom.Namespace { public interface IMyClass { void MultipleParameters(System.String value1, System.Int32 value2); void OutParameter(out System.String value); void RefParameter(ref System.String value); System.Int32 Simple(); } }"; Assert.That(actualInterface.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on interface creation"); expected = @" namespace Custom.Namespace { public class SMyClass : Custom.Namespace.IMyClass { private readonly Core.Fixtures.Fakes.ClassWithMethods instance; public SMyClass() { instance = new Core.Fixtures.Fakes.ClassWithMethods(); } public void MultipleParameters(System.String value1, System.Int32 value2) { instance.MultipleParameters(value1, value2); } public void OutParameter(out System.String value) { instance.OutParameter(out value); } public void RefParameter(ref System.String value) { instance.RefParameter(ref value); } public System.Int32 Simple() { return instance.Simple(); } public override System.Boolean Equals(System.Object obj) { return instance.Equals(obj); } public override System.Int32 GetHashCode() { return instance.GetHashCode(); } public override System.String ToString() { return instance.ToString(); } } }"; Assert.That(actualImplementation.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on implementation creation"); }
public void ExtractMembers_TypeOfDateTime_JustWriteItToConsole() { IExtractor extractor = new Extractor(typeof (DateTime)); var interfaceName = "Custom.Namespace.IDateTime"; var implementationName = "Custom.Namespace.DateTimeImplementation"; var extracted = extractor.ExtractInterfaceForInstanceMembers(interfaceName); Console.WriteLine(extracted); extracted = extractor.ExtractImplementationForInstanceMembers(interfaceName, implementationName); Console.WriteLine(extracted); interfaceName = "Custom.Namespace.IDateTimeStatics"; implementationName = "Custom.Namespace.DateTimeStaticsImplementation"; extracted = extractor.ExtractInterfaceForStaticMembers(interfaceName); Console.WriteLine(extracted); extracted = extractor.ExtractImplementationForStaticMembers(interfaceName, implementationName); Console.WriteLine(extracted); Console.WriteLine(); }
public void ExtractInstanceMembers_SourceType_SubstituteCreatedType() { IExtractor extractor = new Extractor(typeof(ClassThatHasAReturnTypeOfSelf)); const string interfaceName = "Custom.Namespace.IClassThatHasAReturnTypeOfSelf"; const string implementationName = "Custom.Namespace.ClassWithMethodsImplementation"; var actualInterface = extractor.ExtractInterfaceForInstanceMembers(interfaceName); var actualImplementation = extractor.ExtractImplementationForInstanceMembers(interfaceName, implementationName); write_output(actualInterface, actualImplementation); var expected = @" namespace Custom.Namespace { public interface IClassThatHasAReturnTypeOfSelf { Custom.Namespace.IClassThatHasAReturnTypeOfSelf ReturnSameType(); } }"; Assert.That(actualInterface.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on interface creation"); expected = @" namespace Custom.Namespace { public class ClassWithMethodsImplementation : Custom.Namespace.IClassThatHasAReturnTypeOfSelf { private readonly Core.Fixtures.Fakes.ClassThatHasAReturnTypeOfSelf instance; public ClassWithMethodsImplementation() { instance = new Core.Fixtures.Fakes.ClassThatHasAReturnTypeOfSelf(); } public ClassWithMethodsImplementation(Core.Fixtures.Fakes.ClassThatHasAReturnTypeOfSelf instance) { this.instance = instance; } public Custom.Namespace.IClassThatHasAReturnTypeOfSelf ReturnSameType() { return new ClassWithMethodsImplementation(instance); } public override System.Boolean Equals(System.Object obj) { return instance.Equals(obj); } public override System.Int32 GetHashCode() { return instance.GetHashCode(); } public override System.String ToString() { return instance.ToString(); } } }"; Assert.That(actualImplementation.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on implementation creation"); }
public void ExtractMembers_StructWithConstructors_ExtractsConstructorIncludingParameterless() { IExtractor extractor = new Extractor(typeof(StructWithConstructors)); const string interfaceName = "Custom.Namespace.IMyStruct"; const string implementationName = "Custom.Namespace.Impl"; var actualInterface = extractor.ExtractInterfaceForInstanceMembers(interfaceName); var actualImplementation = extractor.ExtractImplementationForInstanceMembers(interfaceName, implementationName); write_output(actualInterface, actualImplementation); var expected = @" namespace Custom.Namespace { public interface IMyStruct { } }"; Assert.That(actualInterface.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on interface creation"); expected = @" namespace Custom.Namespace { public class Impl : Custom.Namespace.IMyStruct { private readonly Core.Fixtures.Fakes.StructWithConstructors instance; public Impl(System.Int32 value) { instance = new Core.Fixtures.Fakes.StructWithConstructors(value); } public Impl(System.Int32 value1, System.Int32 value2) { instance = new Core.Fixtures.Fakes.StructWithConstructors(value1, value2); } public override System.Boolean Equals(System.Object obj) { return instance.Equals(obj); } public override System.Int32 GetHashCode() { return instance.GetHashCode(); } public override System.String ToString() { return instance.ToString(); } public Impl() { instance = new Core.Fixtures.Fakes.StructWithConstructors(); } } }"; Assert.That(actualImplementation.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on implementation creation"); }
public void ExtractInstanceMembers_SimpleClassWithNoImplementation_OverrideMembersFromObject() { IExtractor extractor = new Extractor(typeof(SimpleClass)); const string interfaceName = "Custom.Namespace.IMyClass"; const string implementationName = "Custom.Namespace.SMyClass"; var actualInterface = extractor.ExtractInterfaceForInstanceMembers(interfaceName); var actualImplementation = extractor.ExtractImplementationForInstanceMembers(interfaceName, implementationName); write_output(actualInterface, actualImplementation); var expected = @" namespace Custom.Namespace { public interface IMyClass { } }"; Assert.That(actualInterface.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on interface creation"); expected = @" namespace Custom.Namespace { public class SMyClass : Custom.Namespace.IMyClass { private readonly Core.Fixtures.Fakes.SimpleClass instance; public SMyClass() { instance = new Core.Fixtures.Fakes.SimpleClass(); } public override System.Boolean Equals(System.Object obj) { return instance.Equals(obj); } public override System.Int32 GetHashCode() { return instance.GetHashCode(); } public override System.String ToString() { return instance.ToString(); } } }"; Assert.That(actualImplementation.RemoveWhitespace(), Is.EqualTo(expected.RemoveWhitespace()), "failed on implementation creation"); }