public async Task CreateGoodsReceivedNoteFreeItemAsync_Returns_New_GetGoodsReceivedNoteFreeItemDto() { //Arrange _fixture.MockGoodsReceivedNoteFreeItemService.Setup(x => x.AddGoodsReceivedNoteFreeItemAsync(It.IsAny <GoodsReceivedNoteFreeItem>())) .ReturnsAsync(_fixture.CreatedNewGoodsReceivedNoteFreeItem); var repository = new GoodsReceivedNoteFreeItemRepository(AutoMapperSingleton.Mapper, _fixture.MockGoodsReceivedNoteFreeItemService.Object); //Act var result = await repository.CreateGoodsReceivedNoteFreeItemAsync(_fixture.CreateGoodsReceivedNoteFreeItemDto); //Assert result.Should().BeOfType(typeof(GetGoodsReceivedNoteFreeItemDto)); result.Id.Should().Be(3); result.ItemTypeName.Should().Be("Grocery"); result.ItemName.Should().Be("Rice"); result.ItemUnitPrice.Should().Be(350); result.Quantity.Should().Be(5); }
public async Task CreateGoodsReceivedNoteFreeItemAsync_Throws_ConflictException() { //Arrange _fixture.MockGoodsReceivedNoteFreeItemService.Setup(x => x.GetGoodsReceivedNoteFreeItemAsync(It.IsAny <Expression <Func <GoodsReceivedNoteFreeItem, bool> > >())) .Returns <Expression <Func <GoodsReceivedNoteFreeItem, bool> > >(expression => Task.FromResult(_fixture.GoodsReceivedNoteFreeItems.AsQueryable().FirstOrDefault(expression))); var repository = new GoodsReceivedNoteFreeItemRepository(AutoMapperSingleton.Mapper, _fixture.MockGoodsReceivedNoteFreeItemService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateGoodsReceivedNoteFreeItemAsync(new CreateGoodsReceivedNoteFreeItemDto { GoodsReceivedNoteId = 202, ItemId = 20050, ItemUnitPrice = 350, Quantity = 5 })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Item already available for this goods received note."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }