public void ThrowArgumentNullExceptionWhenPassedEntityIsNull() { //Arrange var pages = new List <Page> { new Page() { Id = Guid.NewGuid(), Title = "page", Content = "cntnt" }, new Page() { Id = Guid.NewGuid(), Title = "page", Content = "cntnt" } }; var mockedDbContext = new Mock <ISotnWikiDbContext>(); var mockedPageSet = QueryableDbSetMock.GetQueryableMockDbSet <Page>(pages); mockedDbContext.Setup(c => c.Set <Page>()).Returns(mockedPageSet); mockedDbContext.Setup(c => c.Pages).Returns(mockedPageSet); string expectedExceptionMessage = "entity"; var repositoryUnderTest = new EfGenericRepository <Page>(mockedDbContext.Object); //Act & Assert var exc = Assert.Throws <ArgumentNullException>(() => repositoryUnderTest.Add(null)); //Assert StringAssert.Contains(expectedExceptionMessage, exc.Message); }
public void RepositoryUpdate() { //arrange var connection = DbConnectionFactory.CreateTransient(); var stubDB = new GroceryStoreContext(connection); var userRepo = new EfGenericRepository <User>(stubDB); var user = new User { FirstName = "Pesho", LastName = "Pesho", Username = "******", Password = "******", PhoneNumber = "Pesho" }; userRepo.Add(user); stubDB.SaveChanges(); //act user.Password = "******"; userRepo.Update(user); string actual = userRepo.GetById(1).Password; //assert Assert.AreEqual("newPassword", actual); }
public void RepositoryGetById() { //arrange var connection = DbConnectionFactory.CreateTransient(); var stubDB = new GroceryStoreContext(connection); var userRepo = new EfGenericRepository <User>(stubDB); var userToAdd = new User { FirstName = "Pesho", LastName = "Pesho", Username = "******", Password = "******", PhoneNumber = "Pesho" }; userRepo.Add(userToAdd); stubDB.SaveChanges(); //act var actual = userRepo.GetById(1); //assert Assert.AreEqual(userToAdd.Username, actual.Username); }
public void ThrowArgumentNullExceptionWhitCorrectMessage_WhenEntityParameterIsNull() { // Arrange var dbContext = new Mock <ICarAdvertsSystemDbContext>(); var efGenericRepository = new EfGenericRepository <MockDbModel>(dbContext.Object); MockDbModel entity = null; // Act and Assert Assert.That( () => efGenericRepository.Add(entity), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains(nameof(entity))); }
public void RepositoryAddEntity() { //arrange var connection = DbConnectionFactory.CreateTransient(); var stubDB = new GroceryStoreContext(connection); var userRepo = new EfGenericRepository <User>(stubDB); var userToAdd = new User { FirstName = "Pesho", LastName = "Pesho", Username = "******", Password = "******", PhoneNumber = "Pesho" }; //act userRepo.Add(userToAdd); stubDB.SaveChanges(); //assert Assert.AreEqual(1, stubDB.Users.Count()); }
public void RepositoryAddCollection() { //arrange var connection = DbConnectionFactory.CreateTransient(); var stubDB = new GroceryStoreContext(connection); var userRepo = new EfGenericRepository <User>(stubDB); var user1 = new User { FirstName = "Pesho", LastName = "Peshev", Username = "******", Password = "******", PhoneNumber = "12345678" }; var user2 = new User { FirstName = "Gosho", LastName = "Goshev", Username = "******", Password = "******", PhoneNumber = "09876543" }; var collection = new List <User>() { user1, user2 }; //act userRepo.Add(collection); stubDB.SaveChanges(); //assert Assert.AreEqual(2, stubDB.Users.Count()); }
public void RepositoryAdd() { // Arrange var connection = DbConnectionFactory.CreateTransient(); var mockDB = new GroceryStoreContext(connection); var userRepo = new EfGenericRepository <User>(mockDB); var addressRepo = new EfGenericRepository <Address>(mockDB); var user = new User { Username = "******", Password = "******", PhoneNumber = "1234567890" }; var addressToAdd = new Address { AddressText = "Pesho", UserId = 1 }; // Act userRepo.Add(user); //addressRepo.Add(addressToAdd); // Assert Assert.AreEqual(1, mockDB.Users.Count()); //Assert.AreEqual(1, mockDB.Addresses.Count()); }
public T Add(T entity) { return(efGenericRepository.Add(entity)); }