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 GetById_ShouldReturnNull_WhenWrongId() { // Arrange var context = GetContext(); var repo = new SqlConstructionElementRepo(context); // Act var constructionElement = repo.GetById(999); // Assert Assert.Null(constructionElement); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetById_ShouldReturnConstructionElement() { // Arrange var context = GetContext(); var repo = new SqlConstructionElementRepo(context); int id = _rnd.Next(1, _constructionElements.Count()); // Act var constructionElement = repo.GetById(id); // Assert Assert.Equal(_constructionElements.SingleOrDefault(v => v.Id == id), constructionElement); context.Database.EnsureDeleted(); context.Dispose(); }
public void Delete_ShouldDeleteConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionElementRepo(context); int id = _rnd.Next(1, _constructionElements.Count()); var constructionElement = _constructionElements.FirstOrDefault( v => v.Id == id); // Act repo.Delete(constructionElement); // Assert Assert.Null(repo.GetById(id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void Update_ShouldUpdateConstruction() { // Arrange var context = GetContext(true); var repo = new SqlConstructionElementRepo(context); int id = _rnd.Next(1, _updateConstructionElements.Count()); var construction = _updateConstructionElements.FirstOrDefault(v => v.Id == id); construction.Length = 9.0f; // Act repo.Update(construction); // Assert Assert.Equal(construction.Length, repo.GetById(id).Length); context.Database.EnsureDeleted(); context.Dispose(); }