public void ShouldFetchAllComplaintsFromDb(string title, string description) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var complaintService = new ComplaintService(context); var complaintEntityEntries = new List <EntityEntry <ComplaintEntity> >(); var complaintIds = new List <int>(); for (var i = 0; i < 5; i++) { complaintEntityEntries.Add( context.Complaints.Add(new ComplaintEntity { Title = title, Description = description })); } context.SaveChanges(); // Act var complaintsInDb = complaintService.GetAll().ToList(); // Assert Assert.Equal(complaintsInDb.Count, complaintEntityEntries.Count); foreach (var complaint in complaintEntityEntries) { Assert.NotNull(complaintsInDb.Find(x => x.Id == complaint.Entity.Id)); } }
public void ShouldThrowAnExceptionIfUsernameIsTaken(string firstName, string lastName, string username, string password) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var authenticationOptions = Options.Create(new Authentication { Secret = "mockSecret" }); var _userService = new UserService(context, authenticationOptions); var userEntity1 = new UserEntity { FirstName = firstName, LastName = lastName, Username = username }; var userEntity2 = new UserEntity { FirstName = "testname", LastName = "testsurname", Username = username }; var user1 = _userService.Create(userEntity1, password); // Act + Assert Assert.Throws <AuthenticationException>(() => _userService.Create(userEntity2, password)); }
public void ShouldCreateNewUserInInMemoryDatabase(string firstName, string lastName, string username, string password) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); { var authenticationOptions = Options.Create(new Authentication { Secret = "mockSecret" }); var _userService = new UserService(context, authenticationOptions); var userEntity = new UserEntity { FirstName = firstName, LastName = lastName, Username = username }; // Act var createdUser = _userService.Create(userEntity, password); // Assert var userInDb = _userService.GetUserById(createdUser.Id); Assert.Equal(createdUser, userInDb); } }
public void ShouldThrowAnExceptionGivenIdIfItemNotFoundInDatabase(int complaintId) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var complaintService = new ComplaintService(context); // Act + Assert Assert.Throws <ComplaintException>(() => complaintService.GetComplaintById(complaintId)); }
public void ShouldAddComplaintToDatabase(string title, string description) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var complaintService = new ComplaintService(context); var complaintEntity = new ComplaintEntity { Title = title, Description = description }; // Act var createdComplaint = complaintService.AddComplaint(complaintEntity); // Assert var complaintInDb = context.Complaints.Find(createdComplaint.Id); Assert.NotNull(complaintInDb); Assert.Equal(createdComplaint, complaintInDb); }
public void ShouldFetchCorrectComplaintFromDb(string title, string description) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var complaintService = new ComplaintService(context); var complaintEntity = new ComplaintEntity { Title = title, Description = description }; var createdComplaint = context.Complaints.Add(complaintEntity); context.SaveChanges(); // Act var complaintInDb = complaintService.GetComplaintById(createdComplaint.Entity.Id); // Assert Assert.Equal(complaintInDb, createdComplaint.Entity); }
public void ShouldThrowAnAuthenticationExceptionGivenUsernameIsIncorrect(string username, string password) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var authenticationOptions = Options.Create(new Authentication { Secret = "mockSecret" }); var _userService = new UserService(context, authenticationOptions); var userEntity = new UserEntity { FirstName = "name", LastName = "surname", Username = "******" }; var registeredUser = _userService.Create(userEntity, password); // Act + Assert Assert.Throws <AuthenticationException>(() => _userService.Authenticate(username, password)); }
public void ShouldAuthenticateUserGivenCredentialsAreCorrect(string firstName, string lastName, string username, string password) { // Arrange using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions()); var authenticationOptions = Options.Create(new Authentication { Secret = "mockSecret" }); var _userService = new UserService(context, authenticationOptions); var userEntity = new UserEntity { FirstName = firstName, LastName = lastName, Username = username }; var registeredUser = _userService.Create(userEntity, password); // Act var loggedInUser = _userService.Authenticate(registeredUser.Username, password); // Assert Assert.Equal(registeredUser, loggedInUser); }