{"id":21004908,"url":"https://github.com/aivascu/autofixture.community.automapper","last_synced_at":"2026-03-08T18:31:23.475Z","repository":{"id":45045427,"uuid":"380920646","full_name":"aivascu/AutoFixture.Community.AutoMapper","owner":"aivascu","description":"The AutoFixture integration library for AutoMapper","archived":false,"fork":false,"pushed_at":"2023-01-05T17:26:05.000Z","size":68,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-03T23:07:27.709Z","etag":null,"topics":["autofixture","automapper","mstest","nunit","test","testing","unit-test","unit-testing","xunit"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aivascu.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-28T05:53:53.000Z","updated_at":"2023-01-09T12:33:22.000Z","dependencies_parsed_at":"2023-02-04T08:30:41.101Z","dependency_job_id":null,"html_url":"https://github.com/aivascu/AutoFixture.Community.AutoMapper","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aivascu%2FAutoFixture.Community.AutoMapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aivascu%2FAutoFixture.Community.AutoMapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aivascu%2FAutoFixture.Community.AutoMapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aivascu%2FAutoFixture.Community.AutoMapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aivascu","download_url":"https://codeload.github.com/aivascu/AutoFixture.Community.AutoMapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225321304,"owners_count":17456157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autofixture","automapper","mstest","nunit","test","testing","unit-test","unit-testing","xunit"],"created_at":"2024-11-19T08:38:24.590Z","updated_at":"2026-03-08T18:31:23.445Z","avatar_url":"https://github.com/aivascu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoFixture.Community.AutoMapper\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/aivascu/AutoFixture.Community.AutoMapper/release.yml?logo=github\u0026style=flat-square)](https://github.com/aivascu/AutoFixture.Community.AutoMapper/actions/workflows/release.yml)\n[![GitHub](https://img.shields.io/github/license/aivascu/AutoFixture.Community.AutoMapper?style=flat-square)](https://licenses.nuget.org/MIT)\n[![Nuget](https://img.shields.io/nuget/v/AutoFixture.Community.AutoMapper?logo=nuget\u0026style=flat-square)](https://www.nuget.org/packages/AutoFixture.Community.AutoMapper/)\n\n`AutoFixture.Community.AutoMapper` is a glue library that helps with integration of AutoFixture and AutoMapper.\n\n## Features\n\nThe `AutoFixture.Community.AutoMapper` package offers a customization that helps\n\n- Customizes AutoFixture to provide a fully configured `Mapper` instance\n- Relays requests for an `IMapper` instance to the `Mapper` implementation\n- Configures AutoMapper to use AutoFixture as a service factory\n- Provides an easy way to include only the required AutoMapper configuration\n\n## Examples\n\nThe example below demonstrates how to use the `AutoMapperCustomization` to integrate existing AutoMapper profiles.\n\n```cs\npublic class ModelsProfile: Profile\n{\n    public ModelsProfile()\n    {\n        CreateMap\u003cCustomer, CustomerDto\u003e();\n    }\n}\n\n[Theory, AutoData]\npublic void MapsModels(Customer customer, Fixture fixture)\n{\n    // Arrange\n    var expected = fixture.Build\u003cCustomerDto\u003e()\n        .With(x =\u003e x.Id, customer.Id)\n        .With(x =\u003e x.Name, customer.Name)\n        .Create();\n\n    fixture.Customize(new AutoMapperCustomization(x =\u003e x\n        /* x is IMapperConfigurationExpression,\n            so any AutoMapper configuration is valid here */\n        .AddMaps(typeof(ModelsProfile))));\n\n    var sut = fixture.Create\u003cIMapper\u003e();\n\n    // Act\n    var actual = sut.Map\u003cCustomerDto\u003e(customer);\n\n    // Assert\n    actual.AsSource().OfLikeness\u003cCustomerDto\u003e()\n        .ShouldEqual(expected);\n}\n```\n\n### Resolve services from AutoFixture\n\nThe following example shows that the library can act as the service factory for AutoMapper.\nThis means you can easily manipulate services injected into type and value converters.\n\n```cs\npublic class OrderTypeConverter : ITypeConverter\u003cOrderDto, Order\u003e\n{\n    private readonly ITime time;\n\n    public OrderTypeConverter(ITime time)\n    {\n        this.time = time;\n    }\n\n    public Order Convert(OrderDto source, Order destination, ResolutionContext context)\n    {\n        return new Order(source.ProductId, source.Amount, this.time.Now);\n    }\n}\n\npublic class CommerceModelProfile : Profile\n{\n    public CommereceModelProfile()\n    {\n        this.CreateMap\u003cOrderDto, Order\u003e()\n            .ConvertUsing\u003cOrderTypeConverter\u003e();\n    }\n}\n\npublic class CommerceDataAttribute : AutoDataAttribute\n{\n    public CommerceDataAttribute()\n        : base(() =\u003e new Fixture()\n            .Customize(\n                new CompositeCustomization(\n                    // This configures ITime to be resolved as a mock with a value in ITime.Now\n                    new AutoMoqCustomization { ConfigureMembers = true },\n                    new AutoMapperCustomization(x =\u003e x\n                        .AddProfile\u003cCommerceModelProfile\u003e())))\n                )))\n    {}\n}\n\n[Theory, CommerceData]\npublic void ProvidesServices(\n    /* The value to be injected into ITime.Now */\n    [Frozen] DateTime now,\n    IMapper mapper, OrderDto model)\n{\n    // Arrange\n    var expected = new Order(model.ProductId, model.Amount, now);\n\n    // Act\n    var actual = mapper.Map\u003cOrder\u003e(model);\n\n    // Assert\n    actual.AsSource().OfLikeness\u003cOrder\u003e().ShouldEqual(expected);\n}\n```\n\n## License\n\nCopyright \u0026copy; 2021 [Andrei Ivascu](https://github.com/aivascu).\u003cbr/\u003e\nThis project is [MIT](https://github.com/aivascu/AutoFixture.Community.AutoMapper/blob/master/LICENSE) licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faivascu%2Fautofixture.community.automapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faivascu%2Fautofixture.community.automapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faivascu%2Fautofixture.community.automapper/lists"}