public void Add_NewUserAddedAndReturned_UpdatesRepositoryFindsUser() { //TODO: Refactor test to do ONE thing not two //ARRANGE DatabaseTestUtility.DropCreateArbeDatabase(); var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var userRepository = new UserRepository(ambientDbContextLocator); User returnUser = null; var newUser = new User { UserId = 1, Name = "Kermit", Email = "*****@*****.**" }; //ACT using (var dbContextScope = dbContextScopeFactory.Create()) { userRepository.Add(newUser); dbContextScope.SaveChanges(); } //Now using a new dbContextScope - lets grab the data using (dbContextScopeFactory.CreateReadOnly()) { returnUser = userRepository.Find(1); } //ASSERT Assert.Equal(newUser.Name, returnUser.Name); }
public void InstantiatingClass_WithDefaultConstructor_Succeeds() { // Arrange & Act var model = new User(); // Assert Assert.NotNull(model); }
public static void Add(ArbeContext context) { var kermit = new User { UserId = 1, Name = "Kermit" }; context.Users.Add(kermit); context.SaveChanges(); try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult validationErrors in dbEx.EntityValidationErrors) { foreach (DbValidationError validationError in validationErrors.ValidationErrors) { Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
public void Add(User user) { ambientDbContextLocator.Get<UserManagementDbContext>().Users.Add(user); }
public void CreateUser(UserCreationSpec userToCreate) { if (userToCreate == null) throw new ArgumentNullException("userToCreate"); userToCreate.Validate(); /* * Typical usage of DbContextScope for a read-write business transaction. * It's as simple as it looks. */ using (var dbContextScope = dbContextScopeFactory.Create()) { //-- Build domain model var user = new User() { UserId = 99, //userToCreate.UserId, Name = userToCreate.Name }; //-- Persist userRepository.Add(user); dbContextScope.SaveChanges(); } }