public void Add_New_User() { User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, }; IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); User addedUser = repository.AddUser(newUser); // Check if a non-null user is returned from the call Assert.IsNotNull(addedUser); // Check id the DbContext cached the user object in its local User collection Assert.IsTrue(testDBContext.Users.Local.Count == 1); // Check if the locally cached user object has the same data as the new User that was added above Assert.AreEqual(testDBContext.Users.Local[0].NameIdentifier, newUser.NameIdentifier); // Check if the state of the added user is set to Added Assert.AreEqual(testDBContext.GetEntityState(addedUser), EntityState.Added); testDBContext.Commit(); User retrieved = testDBContext.Users.Find(1); }
private void AddUser(User user) { IUserRepository repository = new UserRepository(testDBContext); User addedUser = repository.AddUser(user); testDBContext.Commit(); }