public async Task AddAsyncAddsTheEntityToTheRepository( string boulderName, string boulderDescription, string gradeId, string gymId, string imageSource, string authorId) { AutoMapperConfig.RegisterMappings(typeof(Test).Assembly, typeof(ErrorViewModel).Assembly); var repositoryMock = new Mock <IDeletableEntityRepository <Boulder> >(); var testData = new List <Boulder>(); var boulderInput = new BoulderInputModel() { Name = boulderName, Description = boulderDescription, GradeId = gradeId, GymId = gymId, }; var imageInput = new ImageInputModel() { Source = imageSource, }; var saved = false; repositoryMock.Setup(x => x.AddAsync(It.IsAny <Boulder>())) .Callback((Boulder boulder) => { testData.Add(boulder); }); repositoryMock.Setup(x => x.SaveChangesAsync()) .Callback(() => { saved = true; }); var bouldersService = new BouldersService(repositoryMock.Object, AutoMapperConfig.MapperInstance); // Act await bouldersService.AddAsync(boulderInput, authorId, imageInput); // Assert var boulder = testData[0]; Assert.True(saved); Assert.Equal(authorId, boulder.AuthorId); Assert.Equal(boulderName, boulder.Name); Assert.Equal(boulderDescription, boulder.Description); Assert.Equal(gradeId, boulder.GradeId); Assert.Equal(gymId, boulder.GymId); Assert.Equal(imageInput.Source, boulder.Image.Source); }
public async Task AddAsyncThrowsWhenTheImageInputModelIsNull() { // Arrange var mapperMock = new Mock <IMapper>(); var repositoryMock = new Mock <IDeletableEntityRepository <Boulder> >(); var bouldersService = new BouldersService(repositoryMock.Object, mapperMock.Object); // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { // Act await bouldersService.AddAsync(new BoulderInputModel(), "validId", null); }); }