public void WhenRequestingNonExistentUserByAuthenticationId_ThenThrowsInvalidOperationException() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var userRepository = new UserRepository(new MileageStatsDbContext()); Assert.Throws<InvalidOperationException>(() => userRepository.GetByAuthenticatedId("NotExistingId")); }
private void InitializeFixture() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); this.defaultTestUser = new User() { AuthorizationId = "TestAuthorizationId", DisplayName = "DefaultTestUser" }; var repository = new UserRepository(new MileageStatsDbContext()); repository.Create(this.defaultTestUser); }
public void WhenAddingUser_ThenUserPersists() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var userRepository = new UserRepository(new MileageStatsDbContext()); var newUser = new User() { AuthorizationId = "AnAuthorizationId", DisplayName = "TheDisplayName", }; userRepository.Create(newUser); Assert.NotNull( new MileageStatsDbContext().Users.Where(u => u.AuthorizationId == newUser.AuthorizationId).Single()); }
public void WhenAddingUser_ThenUserReceivesNonZeroId() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var userRepository = new UserRepository(new MileageStatsDbContext()); var newUser = new User() { AuthorizationId = "AnAuthorizationId", DisplayName = "TheDisplayName", }; Assert.Equal(0, newUser.UserId); userRepository.Create(newUser); Assert.True(newUser.UserId > 0, "User did not receive non-zero UserId when persisted."); }
private void InitializeFixture() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); this.defaultTestUser = new User() { AuthorizationId = "TestAuthorizationId", DisplayName = "DefaultTestUser" }; var userRepository = new UserRepository(this.GetUnitOfWork()); userRepository.Create(this.defaultTestUser); int userId = this.defaultTestUser.UserId; var vehicleRepository = new VehicleRepository(this.GetUnitOfWork()); this.defaultVehicle = new Vehicle() { Name = "Test Vehicle" }; vehicleRepository.Create(this.defaultTestUser.UserId, this.defaultVehicle); }
public void WhenAddingUser_ThenUserReturnsPopulatedNewUser() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var userRepository = new UserRepository(new MileageStatsDbContext()); string authorizationId = "AnAuthorizationId"; string displayName = "TheDisplayName"; var newUser = new User() { AuthorizationId = authorizationId, DisplayName = displayName, }; userRepository.Create(newUser); Assert.NotNull(newUser); Assert.Equal(1, newUser.UserId); Assert.Equal(authorizationId, newUser.AuthorizationId); Assert.Equal(displayName, newUser.DisplayName); }
public void WhenRequestingAvailableUserByAuthenticatedId_ThenReturnsUserFromRepository() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); User userData = new User { AuthorizationId = "TestId", DisplayName = "TestDisplayName", }; using (var dbContext = new MileageStatsDbContext()) { var set = dbContext.Users.Add(userData); dbContext.SaveChanges(); } var userRepository = new UserRepository(new MileageStatsDbContext()); var retrievedUser = userRepository.GetByAuthenticatedId(userData.AuthorizationId); Assert.NotNull(retrievedUser); }
public void WhenConstructingRepositoryWithNullContext_ThenThrows() { Assert.Throws<ArgumentNullException>( () => { var userRepository = new UserRepository(null); }); }