public void Add_ShouldAddConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionElementRepo(context); int constructionId = _rnd.Next(1, _specifications.Count()); int profileId = _rnd.Next(1, _profiles.Count()); int steelId = _rnd.Next(1, _steel.Count()); var constructionElement = new ConstructionElement { Construction = _constructions.SingleOrDefault( v => v.Id == constructionId), Profile = _profiles.SingleOrDefault( v => v.Id == profileId), Steel = _steel.SingleOrDefault( v => v.Id == steelId), Length = 1.0f, }; // Act repo.Add(constructionElement); // Assert Assert.NotNull(repo.GetById(constructionElement.Id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void Create( ConstructionElement constructionElement, int constructionId, int profileId, int steelId) { if (constructionElement == null) { throw new ArgumentNullException(nameof(constructionElement)); } var foundConstruction = _constructionRepo.GetById(constructionId); if (foundConstruction == null) { throw new ArgumentNullException(nameof(foundConstruction)); } var foundProfile = _profileRepo.GetById(profileId); if (foundProfile == null) { throw new ArgumentNullException(nameof(foundProfile)); } var foundSteel = _steelRepo.GetById(steelId); if (foundSteel == null) { throw new ArgumentNullException(nameof(foundSteel)); } // var uniqueConstraintViolationCheck = _repository.GetByUniqueConstraint(markId, linkedDocId); // if (uniqueConstraintViolationCheck != null) // throw new ConflictException(nameof(uniqueConstraintViolationCheck)); constructionElement.Construction = foundConstruction; constructionElement.Profile = foundProfile; constructionElement.Steel = foundSteel; _repository.Add(constructionElement); var foundMark = _markRepo.GetById(foundConstruction.Specification.Mark.Id); foundMark.EditedDate = DateTime.Now; _markRepo.Update(foundMark); }
public void Create_ShouldFailWithNull_WhenWrongValues() { // Arrange int constructionId = _rnd.Next(1, _marks.Count()); int profileId = _rnd.Next(1, _profiles.Count()); int steelId = _rnd.Next(1, _steel.Count()); var newConstructionElement = new ConstructionElement { Length = 1.0f, }; // Act & Assert Assert.Throws <ArgumentNullException>(() => _service.Create( null, constructionId, profileId, steelId)); Assert.Throws <ArgumentNullException>(() => _service.Create( newConstructionElement, 999, profileId, steelId)); Assert.Throws <ArgumentNullException>(() => _service.Create( newConstructionElement, constructionId, 999, steelId)); Assert.Throws <ArgumentNullException>(() => _service.Create( newConstructionElement, constructionId, profileId, 999)); _repository.Verify(mock => mock.Add(It.IsAny <ConstructionElement>()), Times.Never); }
public void Create_ShouldCreateConstructionElement() { // Arrange int constructionId = _rnd.Next(1, _marks.Count()); int profileId = _rnd.Next(1, _profiles.Count()); int steelId = _rnd.Next(1, _steel.Count()); var newConstructionElement = new ConstructionElement { Length = 1.0f, }; // Act _service.Create( newConstructionElement, constructionId, profileId, steelId); // Assert _repository.Verify(mock => mock.Add( It.IsAny <ConstructionElement>()), Times.Once); Assert.NotNull(newConstructionElement.Construction); }
public void Delete(ConstructionElement constructionElement) { _context.ConstructionElements.Remove(constructionElement); _context.SaveChanges(); }
public void Update(ConstructionElement constructionElement) { _context.Entry(constructionElement).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(ConstructionElement constructionElement) { _context.ConstructionElements.Add(constructionElement); _context.SaveChanges(); }