public void Add_ShouldAddConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); int specificationId = _rnd.Next(1, _specifications.Count()); int typeId = _rnd.Next(1, _constructionTypes.Count()); int subtypeId = _rnd.Next(1, _constructionSubtypes.Count()); int weldingControlId = _rnd.Next(1, _weldingControl.Count()); var construction = new Construction { Specification = _specifications.SingleOrDefault(v => v.Id == specificationId), Name = "NewCreate", Type = _constructionTypes.SingleOrDefault(v => v.Id == typeId), Subtype = _constructionSubtypes.SingleOrDefault(v => v.Id == subtypeId), Valuation = "1700", NumOfStandardConstructions = 0, HasEdgeBlunting = false, HasDynamicLoad = false, HasFlangedConnections = false, WeldingControl = _weldingControl.SingleOrDefault(v => v.Id == weldingControlId), PaintworkCoeff = 1, }; // Act repo.Add(construction); // Assert Assert.NotNull(repo.GetById(construction.Id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetById_ShouldReturnNull_WhenWrongId() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); // Act var construction = repo.GetById(999); // Assert Assert.Null(construction); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetAllBySpecificationId_ShouldReturnEmptyArray_WhenWrongSpecificationId() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); // Act var constructions = repo.GetAllBySpecificationId(999); // Assert Assert.Empty(constructions); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetById_ShouldReturnConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); int id = _rnd.Next(1, _constructions.Count()); // Act var construction = repo.GetById(id); // Assert Assert.Equal(_constructions.SingleOrDefault(v => v.Id == id), construction); context.Database.EnsureDeleted(); context.Dispose(); }
public void Delete_ShouldDeleteConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); int id = _rnd.Next(1, _constructions.Count()); var construction = _constructions.FirstOrDefault(v => v.Id == id); // Act repo.Delete(construction); // Assert Assert.Null(repo.GetById(id)); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetAllBySpecificationId_ShouldReturnConstructions() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); var specificationId = _rnd.Next(1, _maxSpecificationId); // Act var constructions = repo.GetAllBySpecificationId(specificationId); // Assert Assert.Equal(_constructions.Where( v => v.Specification.Id == specificationId), constructions); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetAllByMarkId_ShouldReturnConstructions() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); var markId = _rnd.Next(1, 3); // Act var constructions = repo.GetAllByMarkId(markId); // Assert Assert.Equal(_constructions.Where( v => v.Specification.Mark.Id == markId).OrderBy( v => v.Type.Id), constructions); context.Database.EnsureDeleted(); context.Dispose(); }
public void Update_ShouldUpdateConstruction() { // Arrange var context = GetContext(true); var repo = new SqlConstructionRepo(context); int id = _rnd.Next(1, _updateConstructions.Count()); var construction = _updateConstructions.FirstOrDefault(v => v.Id == id); construction.Name = "NewUpdate"; // Act repo.Update(construction); // Assert Assert.Equal(construction.Name, repo.GetById(id).Name); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetByUniqueKey_ShouldReturnConstruction() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); var specificationId = _constructions[0].Specification.Id; var name = _constructions[0].Name; var paintworkCoeff = _constructions[0].PaintworkCoeff; // Act var construction = repo.GetByUniqueKey( specificationId, name, paintworkCoeff); // Assert Assert.Equal(_constructions.SingleOrDefault( v => v.Specification.Id == specificationId && v.Name == name && v.PaintworkCoeff == paintworkCoeff), construction); context.Database.EnsureDeleted(); context.Dispose(); }
public void GetByUniqueKey_ShouldReturnNull_WhenWrongKey() { // Arrange var context = GetContext(); var repo = new SqlConstructionRepo(context); var specificationId = _constructions[0].Specification.Id; var name = _constructions[0].Name; var paintworkCoeff = _constructions[0].PaintworkCoeff; // Act var additionalWork1 = repo.GetByUniqueKey(999, name, paintworkCoeff); var additionalWork2 = repo.GetByUniqueKey(specificationId, "NotFound", paintworkCoeff); var additionalWork3 = repo.GetByUniqueKey(specificationId, name, -1); // Assert Assert.Null(additionalWork1); Assert.Null(additionalWork2); Assert.Null(additionalWork3); context.Database.EnsureDeleted(); context.Dispose(); }