public async Task CreateServiceTypeAsync_Returns_New_GetServiceTypeDto() { //Arrange _fixture.MockServiceTypeService.Setup(x => x.AddServiceTypeAsync(It.IsAny <ServiceType>())) .ReturnsAsync(_fixture.CreatedNewServiceType); var repository = new ServiceTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockServiceTypeService.Object); //Act var result = await repository.CreateServiceTypeAsync(_fixture.CreateServiceTypeDto); //Assert result.Should().BeOfType(typeof(GetServiceTypeDto)); result.Id.Should().Be(3); result.Type.Should().Be(_fixture.CreateServiceTypeDto.Type); }
public async Task CreateServiceTypeAsync_Throws_ConflictException() { //Arrange _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))); var repository = new ServiceTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockServiceTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateServiceTypeAsync(new CreateServiceTypeDto { Type = "dine in" })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Service type \"dine in\" is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }