public void InsertsEntity()
        {
            //Arrange
            var initialCount = _context.Set <Foo>().Count();
            var foo          = new Foo {
                Id = Guid.NewGuid()
            };

            //Act
            _repositoryWriter.Insert(foo);
            _context.SaveChanges();

            //Assert
            Assert.Equal(initialCount + 1, _context.Set <Foo>().Count());
            Assert.Contains(foo, _context.Set <Foo>().AsEnumerable());
        }
Example #2
0
        public void SavesChanges()
        {
            //Arrange
            var initialCount = _repositoryReader.GetAll().Count();
            var foo1         = new Foo {
                Id = Guid.NewGuid()
            };
            var foo2 = new Foo {
                Id = Guid.NewGuid()
            };

            //Act
            _repositoryWriter.Insert(foo1);
            _repositoryWriter.Insert(foo2);
            _unitOfWork.SaveChanges();

            //Assert
            var all = _repositoryReader.GetAll();

            Assert.Equal(initialCount + 2, all.Count());
            Assert.Contains(foo1, all);
            Assert.Contains(foo2, all);
        }
Example #3
0
        public void GetsByIdReturnsItemCorrectlyWhenFound()
        {
            //Arrange
            var foo = new Foo {
                Id = Guid.NewGuid(), Name = "A"
            };

            _repositoryWriter.Insert(foo);

            //Act
            var fooDb = _repositoryReader.GetById(foo.Id);

            //Assert
            Assert.NotNull(fooDb);
            Assert.Equal(foo.Id, fooDb.Id);
            Assert.Equal("A", fooDb.Name);
        }