public async Task DeleteServiceTypeAsync_Returns_NoResult() { //Arrange var id = 2; _fixture.MockServiceTypeService.Setup(x => x.GetServiceTypeAsync(It.IsAny <Expression <Func <ServiceType, bool> > >())) .Returns <Expression <Func <ServiceType, bool> > >(expression => Task.FromResult(_fixture.ServiceTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockServiceTypeService.Setup(x => x.DeleteServiceTypeAsync(It.IsAny <ServiceType>())); var repository = new ServiceTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockServiceTypeService.Object); //Act await repository.DeleteServiceTypeAsync(id); // Assert _fixture.MockServiceTypeService.Verify(x => x.DeleteServiceTypeAsync(It.IsAny <ServiceType>()), Times.Once); }
public async Task DeleteServiceTypeAsync_Throws_NotFoundException() { //Arrange var id = 201; _fixture.MockServiceTypeService.Setup(x => x.GetServiceTypeAsync(It.IsAny <Expression <Func <ServiceType, bool> > >())) .Returns <Expression <Func <ServiceType, bool> > >(expression => Task.FromResult(_fixture.ServiceTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockServiceTypeService.Setup(x => x.DeleteServiceTypeAsync(It.IsAny <ServiceType>())); var repository = new ServiceTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockServiceTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.DeleteServiceTypeAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Service type not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }