コード例 #1
0
        public void Add_ShouldAddstandardConstruction()
        {
            // Arrange
            var context = GetContext();
            var repo    = new SqlStandardConstructionRepo(context);

            int specificationId      = _rnd.Next(1, _specifications.Count());
            var standardConstruction = new StandardConstruction
            {
                Specification = _specifications.SingleOrDefault(v => v.Id == specificationId),
                Name          = "NewCreate",
                Num           = 1,
                Sheet         = "NewCreate",
                Weight        = 1.0f,
            };

            // Act
            repo.Add(standardConstruction);

            // Assert
            Assert.NotNull(repo.GetById(standardConstruction.Id));

            context.Database.EnsureDeleted();
            context.Dispose();
        }
コード例 #2
0
        public void Create(
            StandardConstruction standardConstruction,
            int specificationId)
        {
            if (standardConstruction == null)
            {
                throw new ArgumentNullException(nameof(standardConstruction));
            }
            var foundSpecification = _specificationRepo.GetById(specificationId);

            if (foundSpecification == null)
            {
                throw new ArgumentNullException(nameof(foundSpecification));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                specificationId, standardConstruction.Name);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(nameof(uniqueConstraintViolationCheck));
            }

            standardConstruction.Specification = foundSpecification;

            _repository.Add(standardConstruction);

            var foundMark = _markRepo.GetById(foundSpecification.Mark.Id);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
コード例 #3
0
        public void Create_ShouldCreatestandardConstruction()
        {
            // Arrange
            int specificationId = _rnd.Next(1, _specifications.Count());

            var newStandardConstruction = new StandardConstruction
            {
                Name   = "NewCreate",
                Num    = 9,
                Sheet  = "NewCreate",
                Weight = 9.0f,
            };

            // Act
            _service.Create(
                newStandardConstruction,
                specificationId);

            // Assert
            _repository.Verify(mock => mock.Add(It.IsAny <StandardConstruction>()), Times.Once);
            Assert.NotNull(newStandardConstruction.Specification);
        }
コード例 #4
0
        public void Create_ShouldFailWithConflict_WhenConflictValue()
        {
            // Arrange
            var specificationId = _standardConstructions[0].Specification.Id;
            var name            = _standardConstructions[0].Name;

            var newStandardConstruction = new StandardConstruction
            {
                Name   = name,
                Num    = 9,
                Sheet  = "NewCreate",
                Weight = 9.0f,
            };

            // Act & Assert
            Assert.Throws <ConflictException>(
                () => _service.Create(
                    newStandardConstruction,
                    specificationId));

            _repository.Verify(mock => mock.Add(It.IsAny <StandardConstruction>()), Times.Never);
        }
コード例 #5
0
        public void Create_ShouldFailWithNull_WhenWrongValues()
        {
            // Arrange
            int specificationId = _rnd.Next(1, _specifications.Count());

            var newStandardConstruction = new StandardConstruction
            {
                Name   = "NewCreate",
                Num    = 9,
                Sheet  = "NewCreate",
                Weight = 9.0f,
            };

            // Act & Assert
            Assert.Throws <ArgumentNullException>(
                () => _service.Create(
                    null, specificationId));
            Assert.Throws <ArgumentNullException>(
                () => _service.Create(
                    newStandardConstruction, 999));

            _repository.Verify(mock => mock.Add(It.IsAny <StandardConstruction>()), Times.Never);
        }
コード例 #6
0
 public void Delete(StandardConstruction standardconstruction)
 {
     _context.StandardConstructions.Remove(standardconstruction);
     _context.SaveChanges();
 }
コード例 #7
0
 public void Update(StandardConstruction standardconstruction)
 {
     _context.Entry(standardconstruction).State = EntityState.Modified;
     _context.SaveChanges();
 }
コード例 #8
0
 public void Add(StandardConstruction standardconstruction)
 {
     _context.StandardConstructions.Add(standardconstruction);
     _context.SaveChanges();
 }