Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SliceFixture with AutoMapper #54

Open
TDK1964 opened this issue Feb 28, 2021 · 1 comment
Open

SliceFixture with AutoMapper #54

TDK1964 opened this issue Feb 28, 2021 · 1 comment

Comments

@TDK1964
Copy link

TDK1964 commented Feb 28, 2021

My Create handler uses AutoMapper to map from command to entity.

public async Task<int> Handle(Command command, CancellationToken cancellationToken)
            {
                var entity = _mapper.Map<ExampleEntity>(command);
                await _db.ExampleEntity.AddAsync(entity, cancellationToken);
                await _db.SaveChangesAsync(cancellationToken);
                return entity.Id;
            }

My test looks like this

var command = new Create.Command
{
    Name = "Example 1",
     ...
};
var id = await _fixture.SendAsync(command, mapper);
id.ShouldNotBeNull();

When I run the test I get "Object reference not set to an instance of an object." because _maper is null;
I know I probably need to modify the SliceFixture but can't figure out what to do.

@TDK1964
Copy link
Author

TDK1964 commented Mar 2, 2021

Could anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant