コード例 #1
0
        public void Add_ShouldAddDoc()
        {
            // Arrange
            var context = GetContext(TestData.docs);
            var repo    = new SqlDocRepo(context);

            int markId      = _rnd.Next(1, TestData.marks.Count());
            int docTypeId   = _rnd.Next(1, TestData.docTypes.Count());
            int creatorId   = _rnd.Next(1, TestData.employees.Count());
            int inspectorId = _rnd.Next(1, TestData.employees.Count());
            int normContrId = _rnd.Next(1, TestData.employees.Count());
            var doc         = new Doc
            {
                Mark       = TestData.marks.SingleOrDefault(v => v.Id == markId),
                Type       = TestData.docTypes.SingleOrDefault(v => v.Id == docTypeId),
                Name       = "NewCreate",
                Form       = 1.0f,
                Creator    = TestData.employees.SingleOrDefault(v => v.Id == creatorId),
                Inspector  = TestData.employees.SingleOrDefault(v => v.Id == inspectorId),
                NormContr  = TestData.employees.SingleOrDefault(v => v.Id == normContrId),
                ReleaseNum = 1,
                NumOfPages = 1,
            };

            // Act
            repo.Add(doc);

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

            context.Database.EnsureDeleted();
            context.Dispose();
        }
コード例 #2
0
        public void GetById_ShouldReturnNull_WhenWrongId()
        {
            // Arrange
            var context = GetContext(TestData.docs);
            var repo    = new SqlDocRepo(context);

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

            // Assert
            Assert.Null(doc);

            context.Database.EnsureDeleted();
            context.Dispose();
        }
コード例 #3
0
        public void GetById_ShouldReturnDoc()
        {
            // Arrange
            var context = GetContext(TestData.docs);
            var repo    = new SqlDocRepo(context);

            var id = _rnd.Next(1, TestData.docs.Count());

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

            // Assert
            Assert.Equal(TestData.docs.SingleOrDefault(v => v.Id == id), doc);

            context.Database.EnsureDeleted();
            context.Dispose();
        }
コード例 #4
0
        public void Delete_ShouldDeleteDoc()
        {
            // Arrange
            var context = GetContext(TestData.docs);
            var repo    = new SqlDocRepo(context);

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

            // Act
            repo.Delete(doc);

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

            context.Database.EnsureDeleted();
            context.Dispose();
        }
コード例 #5
0
        public void Update_ShouldUpdateDoc()
        {
            // Arrange
            var docs = new List <Doc> {
            };

            foreach (var d in TestData.docs)
            {
                docs.Add(new Doc
                {
                    Id         = d.Id,
                    Mark       = d.Mark,
                    Type       = d.Type,
                    Name       = d.Name,
                    Form       = d.Form,
                    Creator    = d.Creator,
                    Inspector  = d.Inspector,
                    NormContr  = d.NormContr,
                    ReleaseNum = d.ReleaseNum,
                    NumOfPages = d.NumOfPages,
                    Note       = d.Note,
                });
            }
            var context = GetContext(docs);
            var repo    = new SqlDocRepo(context);

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

            doc.Name = "NewUpdate";

            // Act
            repo.Update(doc);

            // Assert
            Assert.Equal(doc.Name, repo.GetById(id).Name);

            context.Database.EnsureDeleted();
            context.Dispose();
        }