public async Task GetStockTypesAsync_Returns_GetStockTypeDtos() { //Arrange _fixture.MockStockTypeService.Setup(x => x.GetStockTypesAsync()) .ReturnsAsync(_fixture.StockTypes); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act var result = await repository.GetStockTypesAsync(); //Assert var stockTypes = result.Should().BeAssignableTo <IEnumerable <GetStockTypeDto> >().Subject; stockTypes.Should().HaveCount(2); }
public async Task CreateStockTypeAsync_Returns_New_GetStockTypeDto() { //Arrange _fixture.MockStockTypeService.Setup(x => x.AddStockTypeAsync(It.IsAny <StockType>())) .ReturnsAsync(_fixture.CreatedNewStockType); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act var result = await repository.CreateStockTypeAsync(_fixture.CreateStockTypeDto); //Assert result.Should().BeOfType(typeof(GetStockTypeDto)); result.Id.Should().Be(3); result.Type.Should().Be(_fixture.CreateStockTypeDto.Type); result.Description.Should().Be(_fixture.CreateStockTypeDto.Description); }
public async Task GetStockTypeAsync_Throws_NotFoundException() { //Arrange var id = 201; _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >())) .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression))); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.GetStockTypeAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Stock type not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }
public async Task DeleteStockTypeAsync_Returns_NoResult() { //Arrange var id = 2; _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >())) .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression))); _fixture.MockStockTypeService.Setup(x => x.DeleteStockTypeAsync(It.IsAny <StockType>())); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act await repository.DeleteStockTypeAsync(id); // Assert _fixture.MockStockTypeService.Verify(x => x.DeleteStockTypeAsync(It.IsAny <StockType>()), Times.Once); }
public async Task CreateStockTypeAsync_Throws_ConflictException() { //Arrange _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >())) .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression))); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateStockTypeAsync(new CreateStockTypeDto { Type = "Beverage", Description = "" })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Stock type \"Beverage\" is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }
public async Task GetStockTypeAsync_Returns_GetStockTypeDto() { //Arrange var id = 1; _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >())) .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression))); var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object); //Act var result = await repository.GetStockTypeAsync(id); //Assert result.Should().BeOfType(typeof(GetStockTypeDto)); result.Id.Should().Be(id); result.Type.Should().Be("Grocery"); result.Description.Should().Be(""); }