public void WhenRequestingNonExistentUserByAuthenticationId_ThenThrowsInvalidOperationException() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var userRepository = new UserRepository(new MileageStatsDbContext()); Assert.Throws <InvalidOperationException>(() => userRepository.GetByAuthenticatedId("NotExistingId")); }
public void WhenDeleteCalledForNonexistentPhoto_ThenThrows() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var repository = new VehiclePhotoRepository(new MileageStatsDbContext()); Assert.Throws <InvalidOperationException>(() => repository.Delete(12345)); }
public void WhenGetCalledForNonExistantPhoto_ThenThrowsInvalidOperationException() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); VehiclePhotoRepository target = new VehiclePhotoRepository(new MileageStatsDbContext()); Assert.Throws <InvalidOperationException>(() => target.Get(1200)); }
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 WhenCreateCalled_ThenPhotoPersists() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var repository = new VehiclePhotoRepository(new MileageStatsDbContext()); var photo = new Model.VehiclePhoto() { ImageMimeType = "image/jpeg", Image = new byte[1] }; repository.Create(1, photo); var repository2 = new VehiclePhotoRepository(new MileageStatsDbContext()); Assert.NotNull(repository2.Get(1)); }
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."); }
public void WhenDeleteCalled_ThenPhotoNuked() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); var repository = new VehiclePhotoRepository(new MileageStatsDbContext()); var photo = new Model.VehiclePhoto() { ImageMimeType = "image/jpeg", Image = new byte[1] }; repository.Create(1, photo); var photoToEdit = repository.Get(1); repository.Delete(photoToEdit.VehiclePhotoId); var repository2 = new VehiclePhotoRepository(new MileageStatsDbContext()); Assert.Throws <InvalidOperationException>(() => repository2.Get(1)); }
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 WhenGetCalled_ThenReturnsPhoto() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); using (var dbContext = new MileageStatsDbContext()) { var photo = new Model.VehiclePhoto() { ImageMimeType = "image/jpeg", Image = new byte[1] }; dbContext.VehiclePhotos.Add(photo); dbContext.SaveChanges(); } VehiclePhotoRepository target = new VehiclePhotoRepository(new MileageStatsDbContext()); var actual = target.Get(1); Assert.NotNull(actual); }
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); }
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 CountryRepositoryFixture() { DatabaseTestUtility.DropCreateAndSeedMileageStatsDatabase(); }
private void SetupResolverAndDatabase() { DatabaseTestUtility.DropCreateMileageStatsDatabase(); this.dbContext = new MileageStatsDbContext(); this.dbContext.Seed(); }