public static List <UnitOfMeasure> GetActiveUnitOfMeasures() { List <UnitOfMeasure> uom; using (CustomClearviewEntities ctx = new CustomClearviewEntities()) { UnitOfMeasureRepository repo = new UnitOfMeasureRepository(ctx); uom = repo.GetActiveItems(); } return(uom); }
public static void ReloadData() { var session = CurrencyAndMeasurementSession.GetSession(); var uow = new NHUnitOfWork(session); var transaction = new NHTransactionHandler(); var configurator = new AggregateRootConfigurator(new TIBA.Core.EventPublisher()); //create an uomType before create uom var nhExMap = new NHRepositoryExceptionMapper(new List<System.Tuple<DBActionType, string, Exception>>()); var target = new UnitOfMeasureRepository(transaction, uow, nhExMap, configurator); UnitOfMeasureParserHelper.RegisterParsersFromRepository(target); }
public ProductCrudHandler(ProductRepository productRepository, CategoryRepository categoryRepository, WerehouseRepository werehouseRepository, TaxRepository taxRepository, UnitOfMeasureRepository unitOfMeasureRepository) : base(productRepository) { _productRepository = productRepository; _categoryRepository = categoryRepository; _werehouseRepository = werehouseRepository; _taxRepository = taxRepository; _unitOfMeasureRepository = unitOfMeasureRepository; _fromDto = FromDto; _fromEntity = FromEntity; _updateEntity = UpdateEntity; }
public async Task GetUnitOfMeasuresAsync_Returns_GetUnitOfMeasureDtos() { //Arrange _fixture.MockUnitOfMeasureService.Setup(x => x.GetUnitOfMeasuresAsync()) .ReturnsAsync(_fixture.UnitOfMeasures); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act var result = await repository.GetUnitOfMeasuresAsync(); //Assert var uoms = result.Should().BeAssignableTo <IEnumerable <GetUnitOfMeasureDto> >().Subject; uoms.Should().HaveCount(3); }
public async Task CreateUnitOfMeasureAsync_Returns_New_GetUnitOfMeasureDto() { //Arrange _fixture.MockUnitOfMeasureService.Setup(x => x.AddUnitOfMeasureAsync(It.IsAny <UnitOfMeasure>())) .ReturnsAsync(_fixture.CreatedNewUnitOfMeasure); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act var result = await repository.CreateUnitOfMeasureAsync(_fixture.CreateUnitOfMeasureDto); //Assert result.Should().BeOfType(typeof(GetUnitOfMeasureDto)); result.Id.Should().Be(4); result.Code.Should().Be(_fixture.CreateUnitOfMeasureDto.Code); result.Description.Should().Be(_fixture.CreateUnitOfMeasureDto.Description); }
public async Task GetUnitOfMeasureAsync_Returns_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))); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.GetUnitOfMeasureAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Unit of measure not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }
public async Task DeleteUnitOfMeasureAsync_Returns_NoResult() { //Arrange var id = 2; _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.DeleteUnitOfMeasureAsync(It.IsAny <UnitOfMeasure>())); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act await repository.DeleteUnitOfMeasureAsync(id); // Assert _fixture.MockUnitOfMeasureService.Verify(x => x.DeleteUnitOfMeasureAsync(It.IsAny <UnitOfMeasure>()), Times.Once); }
public async Task CreateUnitOfMeasureAsync_Throws_ConflictException() { //Arrange _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))); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateUnitOfMeasureAsync(new CreateUnitOfMeasureDto { Code = "g", Description = "" })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Unit of measure \"g\" is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }
public async Task GetUnitOfMeasureAsync_Returns_GetUnitOfMeasureDto() { //Arrange var id = 1; _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))); var repository = new UnitOfMeasureRepository(AutoMapperSingleton.Mapper, _fixture.MockUnitOfMeasureService.Object); //Act var result = await repository.GetUnitOfMeasureAsync(id); //Assert result.Should().BeOfType(typeof(GetUnitOfMeasureDto)); result.Id.Should().Be(id); result.Code.Should().Be("kg"); result.Description.Should().Be("kg units"); }