public void Add_ShouldAddConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionBoltRepo(context); int constructionId = _rnd.Next(1, _marks.Count()); int diameterId = _rnd.Next(1, _boltDiameters.Count()); var constructionBolt = new ConstructionBolt { Construction = _constructions.SingleOrDefault( v => v.Id == constructionId), Diameter = _boltDiameters.SingleOrDefault( v => v.Id == diameterId), Packet = 5, Num = 5, NutNum = 5, WasherNum = 5, }; // Act repo.Add(constructionBolt); // Assert Assert.NotNull(repo.GetById(constructionBolt.Id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void Create_ShouldFailWithConflict() { // Arrange int conflictConstructionId = _constructionBolts[0].Construction.Id; int conflictDiameterId = _constructionBolts[0].Diameter.Id; var newConstructionBolt = new ConstructionBolt { Packet = 5, Num = 5, NutNum = 5, WasherNum = 5, }; // Act & Assert Assert.Throws <ConflictException>(() => _service.Create( newConstructionBolt, conflictConstructionId, conflictDiameterId)); _repository.Verify(mock => mock.Add(It.IsAny <ConstructionBolt>()), Times.Never); }
public void Create( ConstructionBolt constructionBolt, int constructionId, int boltDiameterId) { if (constructionBolt == null) { throw new ArgumentNullException(nameof(constructionBolt)); } var foundConstruction = _constructionRepo.GetById(constructionId); if (foundConstruction == null) { throw new ArgumentNullException(nameof(foundConstruction)); } var foundBoltDiameter = _boltDiameterRepo.GetById(boltDiameterId); if (foundBoltDiameter == null) { throw new ArgumentNullException(nameof(foundBoltDiameter)); } var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(constructionId, boltDiameterId); if (uniqueConstraintViolationCheck != null) { throw new ConflictException(nameof(uniqueConstraintViolationCheck)); } constructionBolt.Construction = foundConstruction; constructionBolt.Diameter = foundBoltDiameter; _repository.Add(constructionBolt); var foundMark = _markRepo.GetById(foundConstruction.Specification.Mark.Id); foundMark.EditedDate = DateTime.Now; _markRepo.Update(foundMark); }
public void Create_ShouldCreateConstructionBolt() { // Arrange int constructionId = 1; int diameterId = 3; var newConstructionBolt = new ConstructionBolt { Packet = 5, Num = 5, NutNum = 5, WasherNum = 5, }; // Act _service.Create(newConstructionBolt, constructionId, diameterId); // Assert _repository.Verify(mock => mock.Add( It.IsAny <ConstructionBolt>()), Times.Once); Assert.NotNull(newConstructionBolt.Construction); }
public void Create_ShouldFailWithNull_WhenWrongValues() { // Arrange int constructionId = _rnd.Next(1, _marks.Count()); int diameterId = _rnd.Next(1, _boltDiameters.Count()); var newConstructionBolt = new ConstructionBolt { Packet = 5, Num = 5, NutNum = 5, WasherNum = 5, }; // Act & Assert Assert.Throws <ArgumentNullException>(() => _service.Create( null, constructionId, diameterId)); Assert.Throws <ArgumentNullException>(() => _service.Create( newConstructionBolt, 999, diameterId)); Assert.Throws <ArgumentNullException>(() => _service.Create( newConstructionBolt, constructionId, 999)); _repository.Verify(mock => mock.Add(It.IsAny <ConstructionBolt>()), Times.Never); }
public void Delete(ConstructionBolt constructionBolt) { _context.ConstructionBolts.Remove(constructionBolt); _context.SaveChanges(); }
public void Update(ConstructionBolt constructionBolt) { _context.Entry(constructionBolt).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(ConstructionBolt constructionBolt) { _context.ConstructionBolts.Add(constructionBolt); _context.SaveChanges(); }
private void InsertThreeRows( List <TableCell> trCells, OpenXmlElement clonedFirstTr, Table t, int num, ConstructionBolt bolt, BoltLength boltLength) { // Болт OpenXmlElement newTr = null; if (num != 1) { newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); } trCells[0].GetFirstChild <Paragraph>().Append( Word.GetTextElement(num.ToString(), 24)); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Высокопрочные болты по {bolt.Diameter.BoltTechSpec}", 24)); trCells[2].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.Diameter.ToString(), 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.StrengthClass.ToStringWithComma(), 24)); trCells[4].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Packet.ToString(), 24)); trCells[5].GetFirstChild <Paragraph>().Append( Word.GetTextElement(boltLength.Length.ToString(), 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Num.ToString(), 24)); trCells[7].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.Num * boltLength.Weight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells, true, false); if (num != 1) { t.Append(newTr); } // Гайка newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Гайки по {bolt.Diameter.NutTechSpec}", 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement("?", 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.NutNum.ToString(), 24)); trCells[8].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.NutNum * bolt.Diameter.NutWeight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells); t.Append(newTr); // Шайба newTr = clonedFirstTr.CloneNode(true); trCells = newTr.Descendants <TableCell>().ToList(); trCells[1].GetFirstChild <Paragraph>().Append( Word.GetTextElement($"Шайбы по {bolt.Diameter.WasherTechSpec}", 24)); trCells[3].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.Diameter.WasherSteel, 24)); trCells[6].GetFirstChild <Paragraph>().Append( Word.GetTextElement(bolt.WasherNum.ToString(), 24)); trCells[9].GetFirstChild <Paragraph>().Append( Word.GetTextElement( (Math.Ceiling(bolt.WasherNum * bolt.Diameter.WasherWeight * 10) / 10).ToStringWithComma(), 24)); Word.MakeBordersThin(trCells, false); t.Append(newTr); }