public void Must_perform_acceptably() { var sourceFoo = new Foo { A = "SourceA", B = "SourceB", C = 1, RefType = new SimpleRefType { Id = Guid.NewGuid() } }; const int numberOfMappings = 10000000; var systemUnderTest = new DefaultAdapterFactory <Foo, IBar>(); var milliseconds = (long)StopwatchContext.Timed(() => { for (int i = 0; i < numberOfMappings; i++) { IBar bar = systemUnderTest.Create(sourceFoo); // ReSharper disable UnusedVariable string a = bar.A; string b = bar.B; int c = bar.C; SimpleRefType refType = bar.RefType; // ReSharper restore UnusedVariable } }).TotalMilliseconds; Console.WriteLine("{0:0.000000000000000}", milliseconds / numberOfMappings); }
public void Must_attempt_to_adapt_nested_types() { var person = new Person { Name = "Joe", Employer = new Employer { Name = "Microsoft", Address = new Address { Street = "1 Microsoft Way", City = "Redmond" } } }; var systemUnderTest = new DefaultAdapterFactory <Person, IPerson>(); systemUnderTest.Validate(); IPerson personInterface = systemUnderTest.Create(person); Assert.That(personInterface.Employer.Name, Is.EqualTo(person.Employer.Name)); Assert.That(personInterface.Employer.Address.Street, Is.EqualTo(person.Employer.Address.Street)); Assert.That(personInterface.Employer.Address.City, Is.EqualTo(person.Employer.Address.City)); }
public void Must_adapt_properties_in_target_type() { var systemUnderTest = new DefaultAdapterFactory <Foo, IBar>(); var sourceFoo = new Foo { A = "SourceA", B = "SourceB", C = 1, RefType = new SimpleRefType { Id = Guid.NewGuid() }, Letter = FooLetter.B }; IBar bar = systemUnderTest.Create(sourceFoo); Assert.That(bar.A, Is.EqualTo(sourceFoo.A)); Assert.That(bar.B, Is.EqualTo(sourceFoo.B)); Assert.That(bar.C, Is.EqualTo(sourceFoo.C)); Assert.That(bar.RefType, Is.Not.Null); Assert.That(bar.RefType.Id, Is.Not.Null); Assert.That(bar.RefType.Id, Is.EqualTo(sourceFoo.RefType.Id)); Assert.That(bar.Letter.ToString(), Is.EqualTo(sourceFoo.Letter.ToString())); }