Esempio n. 1
0
        public void Update_ShouldUpdateSpecification()
        {
            // Arrange
            var specifications = new List <Specification> {
            };

            foreach (var s in TestData.specifications)
            {
                specifications.Add(new Specification
                {
                    Id        = s.Id,
                    Mark      = s.Mark,
                    Num       = s.Num,
                    IsCurrent = s.IsCurrent,
                });
            }
            var context = GetContext(specifications);
            var repo    = new SqlSpecificationRepo(context);

            int id            = _rnd.Next(1, specifications.Count());
            var specification = specifications.FirstOrDefault(v => v.Id == id);

            specification.Note = "NewUpdate";

            // Act
            repo.Update(specification);

            // Assert
            Assert.Equal(specification.Note, repo.GetById(id).Note);

            context.Database.EnsureDeleted();
        }
Esempio n. 2
0
        public void GetById_ShouldReturnNull_WhenWrongId()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            // Act
            var specification = repo.GetById(999);

            // Assert
            Assert.Null(specification);

            context.Database.EnsureDeleted();
        }
Esempio n. 3
0
        public void GetAllByMarkId_ShouldReturnEmptyArray_WhenWrongMarkId()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            // Act
            var specifications = repo.GetAllByMarkId(999);

            // Assert
            Assert.Empty(specifications);

            context.Database.EnsureDeleted();
        }
Esempio n. 4
0
        public void GetAllByMarkId_ShouldReturnSpecifications()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            var markId = _rnd.Next(1, _maxMarkId);

            // Act
            var specifications = repo.GetAllByMarkId(markId);

            // Assert
            Assert.Equal(TestData.specifications.Where(v => v.Mark.Id == markId), specifications);

            context.Database.EnsureDeleted();
        }
Esempio n. 5
0
        public void GetById_ShouldReturnSpecification()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            int id = _rnd.Next(1, TestData.specifications.Count());

            // Act
            var specification = repo.GetById(id);

            // Assert
            Assert.Equal(TestData.specifications.SingleOrDefault(v => v.Id == id),
                         specification);

            context.Database.EnsureDeleted();
        }
Esempio n. 6
0
        public void Delete_ShouldDeleteSpecification()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            int id            = _rnd.Next(1, TestData.specifications.Count());
            var specification = TestData.specifications.FirstOrDefault(v => v.Id == id);

            // Act
            repo.Delete(specification);

            // Assert
            Assert.Null(repo.GetById(id));

            context.Database.EnsureDeleted();
        }
        public void GetCurrentByMarkId_ShouldReturnSpecification()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            int markId = _rnd.Next(1, _maxMarkId);

            // Act
            var specification = repo.GetCurrentByMarkId(markId);

            // Assert
            Assert.Equal(TestData.specifications.SingleOrDefault(
                             v => v.Mark.Id == markId && v.IsCurrent), specification);

            context.Database.EnsureDeleted();
        }
Esempio n. 8
0
        public void Add_ShouldAddSpecification()
        {
            // Arrange
            var context = GetContext(TestData.specifications);
            var repo    = new SqlSpecificationRepo(context);

            int markId        = _rnd.Next(1, TestData.marks.Count());
            var specification = new Specification
            {
                Mark      = TestData.marks.SingleOrDefault(v => v.Id == markId),
                Num       = 42,
                IsCurrent = false,
            };

            // Act
            repo.Add(specification);

            // Assert
            Assert.NotNull(repo.GetById(specification.Id));

            context.Database.EnsureDeleted();
        }