Exemplo 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();
        }
Exemplo 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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }