private void AddBindings() { /* Services */ _kernel.Bind <IArticleService>().To <ArticleService>().InRequestScope(); _kernel.Bind <IViewArticleService>().To <ViewArticleService>().InRequestScope(); _kernel.Bind <IFileService>().To <FileService>().InRequestScope(); _kernel.Bind <ICommentService>().To <CommentService>().InRequestScope(); _kernel.Bind <IAccountService>().To <AccountService>().InRequestScope(); _kernel.Bind <IAuthenticationService>().To <AuthenticationService>().InRequestScope(); _kernel.Bind <ILoggerService>().To <LoggerService>().InRequestScope(); /* Repositories */ _kernel.Bind <IArticleRepository>().To <ArticleRepository>().InRequestScope(); _kernel.Bind <ITagRepository>().To <TagRepository>().InRequestScope(); _kernel.Bind <ILoggerRepository>().To <LoggerRepository>().InRequestScope(); /* Unit of Works*/ _kernel.Bind <IIdentityUnitOfWork>().To <IdentityUnitOfWork>().InRequestScope(); _kernel.Bind <ILoggerUnitOfWork>().To <LoggerUnitOfWork>().InRequestScope(); _kernel.Bind <IArticleUnitOfWork>().To <ArticleUnitOfWork>().InRequestScope(); /* Managers */ _kernel.Bind <IAccountManager>().To <AccountManager>().InRequestScope(); /* Shared */ _kernel.Bind <Context>().ToSelf().InSingletonScope(); _kernel.Bind <IMapper>().ToConstant(MapperBuilder.BuildMapper()).InSingletonScope(); }
protected IMapper BuildAutoMapper() { var mapper = new MapperBuilder().CreateMapper(); mapper.ConfigurationProvider.AssertConfigurationIsValid(); return(mapper); }
public void WithOutOverrideHashCode() { var mapper = new MapperBuilder() .AddMapper <SimpleC, SimpleD>() .Reverse() .Build(); var a = new SimpleC { Id = _fixture.Create <int>(), Text = _fixture.Create <string>(), IsEnable = _fixture.Create <bool>() }; var b = new SimpleD { Id = _fixture.Create <int>(), Text = _fixture.Create <string>(), IsEnable = _fixture.Create <bool>() }; a.Simple = b; b.Simple = a; var newB = mapper.Map <SimpleD>(a); newB.Id.Should().Be(a.Id); newB.Text.Should().Be(a.Text); newB.IsEnable.Should().Be(a.IsEnable); newB.Simple.Id.Should().Be(b.Id); newB.Simple.Text.Should().Be(b.Text); newB.Simple.IsEnable.Should().Be(b.IsEnable); }
public static void AddAutoMapper(this IServiceCollection services) { var mapperBuilder = new MapperBuilder(); AutoMapper.IMapper mapper = mapperBuilder.CreateMapper(); services.AddSingleton(mapper); }
public void ShouldUseDefaultPath() { var numbers = new[] { 1, 2, 3 }; var mapper = new MapperBuilder { Maps = new List <AbstractMap>() { new ValueMap <int>() } } .Build(); var actualCsv = mapper.Serialize(numbers); var expectedCsv = @"Value 1 2 3"; actualCsv.ShouldBe(expectedCsv); var expectedOrders = JsonSerializer.Serialize(numbers); var actualOrders = JsonSerializer.Serialize(mapper.Deserialize <int>(actualCsv).ToArray()); actualOrders.ShouldBe(expectedOrders); }
public void ShouldUseDefaultValue() { var values = new[] { "Test", null, "", "Test" }; var mapper = new MapperBuilder { Maps = new List <AbstractMap>() { new ValueMap <string> { DefaultValue = "-" } } } .Build(); var actualCsv = mapper.Serialize(values); var expectedCsv = @"Value Test - - Test"; actualCsv.ShouldBe(expectedCsv); var expectedOrders = JsonSerializer.Serialize(values.Select(x => String.IsNullOrEmpty(x) ? null : x).ToArray()); var actualOrders = JsonSerializer.Serialize(mapper.Deserialize <string>(actualCsv).ToArray()); actualOrders.ShouldBe(expectedOrders); }
public void ShouldEscapeString() { var values = new[] { "\"the quick brown fox ran fast\"", "here, or there?" }; var mapper = new MapperBuilder { Maps = new List <AbstractMap>() { new ValueMap <string> { DefaultPathSegment = "value" } } } .Build(); var actualCsv = mapper.Serialize(values); var expectedCsv = @"value """"""the quick brown fox ran fast"""""" ""here, or there?"""; actualCsv.ShouldBe(expectedCsv); var expectedOrders = JsonSerializer.Serialize(values); var actualOrders = JsonSerializer.Serialize(mapper.Deserialize <string>(actualCsv).ToArray()); actualOrders.ShouldBe(expectedOrders); }
public void SetUp() { _mock = new Mock <IArticleRepository>(); _articleUnitOfWork = new ArticleUnitOfWork(null, _mock.Object, null); _mapper = MapperBuilder.BuildMapper(); _fileService = new FileService(_articleUnitOfWork, _mapper); }
public async Task Build_WithFullExample_MapsCorrectly() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.First, "Mikey") .For(to => to.Last, from => from.Surname) .For(to => to.PhoneNumber, from => Formatter.ToInternational(from.PhoneNumber, from.Address.CountryId)) .For(to => to.HomeAddress, from => _addressService.Transform(from.Address)) .For(to => to.OtherAddresses, from => Task.WhenAll(_addressService.Transform(from.BusinessAddress), _addressService.Transform(from.ShippingAddress))) .Build(); var customerMapper = new MapperBuilder <Customer, CustomerDto>() .For(to => to.DateJoined, from => from.DateJoined.ToString(CultureInfo.InvariantCulture)) .For(to => to.CustomerNumber, from => from.CustomerId) .For(to => to.Contact, customerContactMapper) .Build(); var mapped = await customerMapper(_customer); Assert.AreEqual("Mikey", mapped.Contact.First); Assert.AreEqual("12345", mapped.CustomerNumber); Assert.AreEqual(_customer.DateJoined.ToString(CultureInfo.InvariantCulture), mapped.DateJoined); Assert.AreEqual("Thailand", mapped.Contact.OtherAddresses.First().CountryName); Assert.AreEqual(_customer.ShippingAddress.Street, mapped.Contact.OtherAddresses.ElementAt(1).Street); Assert.AreEqual("+66971143378", mapped.Contact.PhoneNumber); }
public void WithOutOverrideHashCodeWithMoreThan8Parameter() { var mapper = new MapperBuilder() .AddMapper <SimpleF, SimpleE>() .Reverse() .Build(); var a = new SimpleE { Short = _fixture.Create <short>(), UShort = _fixture.Create <ushort>(), Int = _fixture.Create <int>(), UInt = _fixture.Create <uint>(), Long = _fixture.Create <long>(), ULong = _fixture.Create <ulong>(), Float = _fixture.Create <float>(), Double = _fixture.Create <double>(), Decimal = _fixture.Create <decimal>(), }; var b = new SimpleF { Short = _fixture.Create <short>(), UShort = _fixture.Create <ushort>(), Int = _fixture.Create <int>(), UInt = _fixture.Create <uint>(), Long = _fixture.Create <long>(), ULong = _fixture.Create <ulong>(), Float = _fixture.Create <float>(), Double = _fixture.Create <double>(), Decimal = _fixture.Create <decimal>(), }; a.Simple = b; b.Simple = a; var newB = mapper.Map <SimpleF>(a); newB.Short.Should().Be(a.Short); newB.UShort.Should().Be(a.UShort); newB.Int.Should().Be(a.Int); newB.UInt.Should().Be(a.UInt); newB.Long.Should().Be(a.Long); newB.ULong.Should().Be(a.ULong); newB.Float.Should().Be(a.Float); newB.Double.Should().Be(a.Double); newB.Decimal.Should().Be(a.Decimal); newB.Simple.Short.Should().Be(b.Short); newB.Simple.UShort.Should().Be(b.UShort); newB.Simple.Int.Should().Be(b.Int); newB.Simple.UInt.Should().Be(b.UInt); newB.Simple.Long.Should().Be(b.Long); newB.Simple.ULong.Should().Be(b.ULong); newB.Simple.Float.Should().Be(b.Float); newB.Simple.Double.Should().Be(b.Double); newB.Simple.Decimal.Should().Be(b.Decimal); }
public DbObjectBuilderTests() { _context = InMemoryContextBuilder.GetContext(); _mapper = MapperBuilder.GetSailScoresMapper(); _service = new DbObjectBuilder( _context, _mapper); }
public MappingDescriptorTests() { output = new StringBuilder(); var builder = new MapperBuilder(); builder.Settings.MappingDescriptorWriter = new StringWriter(output); mapper = builder.BuildMapper(); }
private MapperCacheItem CreateMapperCacheItem(TypePair parentTypePair, MappingMember mappingMember) { MapperBuilder mapperBuilder = _config.GetMapperBuilder(parentTypePair, mappingMember); Mapper mapper = mapperBuilder.Build(parentTypePair, mappingMember); MapperCacheItem mapperCacheItem = _mapperCache.Add(mappingMember.TypePair, mapper); return(mapperCacheItem); }
public ScoringServiceTests() { _context = InMemoryContextBuilder.GetContext(); _mapper = MapperBuilder.GetSailScoresMapper(); _service = new ScoringService( _context, _mapper); }
private MapperCacheItem CreateMapperCacheItem(TypePair typePair) { MapperBuilder mapperBuilder = GetMapperBuilder(typePair); Mapper mapper = mapperBuilder.Build(typePair); MapperCacheItem mapperCacheItem = _mapperCache.Add(typePair, mapper); return(mapperCacheItem); }
private void Execute() { var mapperBuilder = new MapperBuilder(); mapperBuilder.Settings.TypeMapper = new NDCTypeMapper(); mapper = mapperBuilder.BuildMapper(); AuditedActionDto[] audit = GetAudit(); }
public void ActionExpressionTest() { var mapper = new MapperBuilder <TestMap, TestMap>() .SetProcessCrossReferences(false) .GetMapperExpressionEx() .Compile(); mapper(new TestMap(), new TestMap(), null); }
public FleetServiceTests() { _context = InMemoryContextBuilder.GetContext(); _clubId = _context.Clubs.First().Id; _mapper = MapperBuilder.GetSailScoresMapper(); _service = new FleetService( _context, _mapper); }
public void ShouldUseDefaultPath() { var todos = new[] { new[] { new ToDo { Id = 1, Description = "Desc 1" }, new ToDo { Id = 2, Description = "Desc 2" }, new ToDo { Id = 3, Description = "Desc 3" } }, new[] { new ToDo { Id = 4, Description = "Desc 4" }, new ToDo { Id = 5, Description = "Desc 5" }, new ToDo { Id = 6, Description = "Desc 6" } } }; var mapper = new MapperBuilder { Maps = new List <AbstractMap>() { new ValueMap <int>(), new ValueMap <string>(), new RecordMap <ToDo>(), new EnumerableMap <ToDo>() } } .Build(); var actualCsv = mapper.Serialize(todos); var expectedCsv = @"Items[0].Id,Items[0].Description,Items[1].Id,Items[1].Description,Items[2].Id,Items[2].Description 1,Desc 1,2,Desc 2,3,Desc 3 4,Desc 4,5,Desc 5,6,Desc 6"; actualCsv.ShouldBe(expectedCsv); var expectedOrders = JsonSerializer.Serialize(todos); var actualOrders = JsonSerializer.Serialize(mapper.Deserialize <ToDo[]>(actualCsv).ToArray()); actualOrders.ShouldBe(expectedOrders); }
public void BuildSync_MapsCorrectly() { var mapper = new MapperBuilder <Customer, CustomerDto>() .For(to => to.DateJoined, from => from.DateJoined.ToString(CultureInfo.InvariantCulture)) .BuildSync(); var mapped = mapper(_customer); Assert.AreEqual(_customer.DateJoined.ToString(CultureInfo.InvariantCulture), mapped.DateJoined); }
public async Task For_WithAsyncLiteralValue_MapsCorrectly() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.First, Task.FromResult("Mike")) .Build(); var mapped = await customerContactMapper(_customer); Assert.AreEqual("Mike", mapped.First); }
public void MapBuilder_build_IMapper_instance() { // ACT var result = new MapperBuilder().Map <Source, Destination>().Build(); // ASSERT Assert.IsType <MapperBuilder.Mapper <Source, Destination> >(result); }
public async Task For_WithMemberAccess_MapsCorrectly() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.First, from => "Mike") .Build(); var mapped = await customerContactMapper(_customer); Assert.AreEqual("Mike", mapped.First); }
public async Task For_WithNullSource_MapsToNull() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.PhoneNumber, _ => (string)null) .Build(); var mapped = await customerContactMapper(_customer); Assert.IsNull(mapped.PhoneNumber); }
public async Task For_WithNestedMemberAccess_MapsCorrectly() { var customerMapper = new MapperBuilder <Customer, CustomerDto>() .For(to => to.Contact.First, from => from.FirstName) .Build(); var mapped = await customerMapper(_customer); Assert.AreEqual("Mike", mapped.Contact.First); }
public async Task For_WithSynchronousMapper_MapsCorrectly() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.PhoneNumber, from => Formatter.ToInternational(from.PhoneNumber, from.Address.CountryId)) .Build(); var mapped = await customerContactMapper(_customer); Assert.AreEqual("+66971143378", mapped.PhoneNumber); }
public void FuncExpressionTest() { var mapper = new MapperBuilder <TestMap, TestMap>() .GetMapperExpression() .Compile(); var value = mapper(new TestMap()); Assert.That(value, Is.Not.Null); }
public async Task For_WithAsyncMapper_MapsCorrectly() { var customerContactMapper = new MapperBuilder <Customer, ContactDto>() .For(to => to.HomeAddress, from => _addressService.Transform(from.Address)) .Build(); var mapped = await customerContactMapper(_customer); Assert.AreEqual("3 Some Lane", mapped.HomeAddress.Street); Assert.AreEqual("Thailand", mapped.HomeAddress.CountryName); }
public ClubServiceTests() { _context = Utilities.InMemoryContextBuilder.GetContext(); _clubId = _context.Clubs.First().Id; _clubInitials = _context.Clubs.First().Initials; _mapper = MapperBuilder.GetSailScoresMapper(); _service = new SailScores.Core.Services.ClubService( _context, _mapper ); }
public void SourceNotNullableAndDestinyNullable() { var mapper = new MapperBuilder() .AddMapper <SimpleB, SimpleC>() .Build(); var a = _fixture.Create <SimpleB>(); var b = mapper.Map <SimpleC>(a); b.Should().NotBeNull(); b.Should().BeEquivalentTo(a); }