Example #1
0
        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();
        }
Example #2
0
        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();
        }
Example #3
0
        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();
        }
Example #4
0
        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();
        }
Example #5
0
        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();
        }