Ejemplo n.º 1
0
        public async Task UpdateUnitOfMeasureAsync_Throws_NotFoundException()
        {
            //Arrange
            var id = 201;

            _fixture.MockUnitOfMeasureService.Setup(x => x.GetUnitOfMeasureAsync(It.IsAny <Expression <Func <UnitOfMeasure, bool> > >()))
            .Returns <Expression <Func <UnitOfMeasure, bool> > >(expression => Task.FromResult(_fixture.UnitOfMeasures.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockUnitOfMeasureService.Setup(x => x.UpdateUnitOfMeasureAsync(It.IsAny <UnitOfMeasure>()));

            var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object);

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdateUnitOfMeasureAsync(id, _fixture.EditUnitOfMeasureDto));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Unit of measure not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }
Ejemplo n.º 2
0
        public async Task UpdateUnitOfMeasureAsync_Returns_Updated_GetUnitOfMeasureDto()
        {
            //Arrange
            var id = 3;

            _fixture.MockUnitOfMeasureService.Setup(x => x.GetUnitOfMeasureAsync(It.IsAny <Expression <Func <UnitOfMeasure, bool> > >()))
            .Returns <Expression <Func <UnitOfMeasure, bool> > >(expression => Task.FromResult(_fixture.UnitOfMeasures.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockUnitOfMeasureService.Setup(x => x.UpdateUnitOfMeasureAsync(It.IsAny <UnitOfMeasure>()));

            var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object);

            //Act
            var result = await repository.UpdateUnitOfMeasureAsync(id, _fixture.EditUnitOfMeasureDto);

            //Assert
            result.Should().BeOfType(typeof(GetUnitOfMeasureDto));
            result.Id.Should().Be(id);
            result.Code.Should().Be(_fixture.EditUnitOfMeasureDto.Code);
            result.Description.Should().Be(_fixture.EditUnitOfMeasureDto.Description);
        }