public async Task CreateSupplierAsync_Throws_ConflictException() { //Arrange _fixture.MockSupplierService.Setup(x => x.GetSupplierAsync(It.IsAny <Expression <Func <Supplier, bool> > >())) .Returns <Expression <Func <Supplier, bool> > >(expression => Task.FromResult(_fixture.Suppliers.AsQueryable().FirstOrDefault(expression))); var repository = new SupplierRepository(AutoMapperSingleton.Mapper, _fixture.MockSupplierService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateSupplierAsync(new CreateSupplierDto { Name = "VBT Pvt Ltd", Address1 = "#03-46, Blk 687", Address2 = "Hindu College Road", City = "Jaffna", Country = "Sri Lanka", Telephone1 = "0777113644", Telephone2 = "0777113644", Fax = "0777113644", Email = "*****@*****.**", ContactPerson = "James" })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Supplier VBT Pvt Ltd is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }
public async Task CreateSupplierAsync_Returns_New_GetSupplierDto() { //Arrange _fixture.MockSupplierService.Setup(x => x.AddSupplierAsync(It.IsAny <Supplier>())) .ReturnsAsync(_fixture.CreatedNewSupplier); var repository = new SupplierRepository(AutoMapperSingleton.Mapper, _fixture.MockSupplierService.Object); //Act var result = await repository.CreateSupplierAsync(_fixture.CreateSupplierDto); //Assert result.Should().BeOfType(typeof(GetSupplierDto)); result.Id.Should().Be(3); result.Name.Should().Be(_fixture.CreateSupplierDto.Name); result.ContactPerson.Should().Be(_fixture.CreateSupplierDto.ContactPerson); }