public void GivenAuctionsByASingleUser_GetAuctionsByUsername_WithDifferentUsername_ReturnsEmptyList() { // Arrange const string pera = "Pera"; const string mika = "Mika"; var userFake = new UserRepositoryFake(); userFake.CreateUser(pera, "123456"); userFake.CreateUser(mika, "654321"); var auctionService = new AuctionService(new AuctionRepositoryFake(), userFake, new AuditRepositoryFake()); auctionService.CreateAuction(pera, new AuctionItemViewModel { Description = "description", MinAmount = "0", Name = "Item 1" }); auctionService.CreateAuction(pera, new AuctionItemViewModel { Description = "description 2", MinAmount = "0", Name = "Item 2" }); // Act var allAuctionsByUsername = auctionService.GetAuctionsByUsername(mika); // Assert Assert.IsEmpty(allAuctionsByUsername); }
public void GivenTwoCreatedAuctionsByASingleUser_GetAuctionsByUsername_ReturnsListContainingBothAuctions() { // Arrange const string username = "******"; var userFake = new UserRepositoryFake(); userFake.CreateUser(username, "123456"); var auctionService = new AuctionService(new AuctionRepositoryFake(), userFake, new AuditRepositoryFake()); auctionService.CreateAuction(username, new AuctionItemViewModel { Description = "description", MinAmount = "0", Name = "Item 1" }); auctionService.CreateAuction(username, new AuctionItemViewModel { Description = "description 2", MinAmount = "0", Name = "Item 2" }); // Act var allAuctionsByUsername = auctionService.GetAuctionsByUsername(username); // Assert var auctionViewModels = allAuctionsByUsername.ToList(); var firstAuction = auctionViewModels.FirstOrDefault(); var lastAuction = auctionViewModels.LastOrDefault(); Assert.AreEqual(2, auctionViewModels.Count); Assert.AreEqual(username, firstAuction.Seller); Assert.AreEqual(username, lastAuction.Seller); }
public void ChangePasswordWithWrongOldPasswords() { // Arrange var fakeRepository = new UserRepositoryFake(); var userService = new UserService(fakeRepository); fakeRepository.CreateUser("stefan", "test123"); // Act and assert Assert.Throws <System.ArgumentException>(() => userService.ChangePassword("stefan", "test", "test456")); }
public void GetByExistingUserNameTest() { // Arrange var fakeRepository = new UserRepositoryFake(); var userService = new UserService(fakeRepository); fakeRepository.CreateUser("stefan", "test123"); // Act var result = userService.GetByUsername("stefan"); // Assert Assert.AreEqual("stefan", result.Username); }
public void GivenUser_WhenPasswordChanged_ThenPasswordHasNewValue() { // Arrange var fakeRepository = new UserRepositoryFake(); var userService = new UserService(fakeRepository); fakeRepository.CreateUser("stefan", "test123"); // Act var result = userService.ChangePassword("stefan", "test123", "test456"); // Assert Assert.AreEqual("test456", result.Password); }
public void GivenRepositoriesWithOneAuctionAndOneUser_WhenGetAllAuctionsIsCalled_ListContainingThatAuctionIsReturned() { // Arrange const string username = "******"; var userFake = new UserRepositoryFake(); userFake.CreateUser(username, "123456"); var auctionService = new AuctionService(new AuctionRepositoryFake(), userFake, new AuditRepositoryFake()); // Act auctionService.CreateAuction(username, new AuctionItemViewModel { Description = "description", MinAmount = "0", Name = "Item" }); // Assert var allAuctions = auctionService.GetAllAuctions(); var auctionViewModels = allAuctions.ToList(); var firstAuction = auctionViewModels.FirstOrDefault(); Assert.IsNotEmpty(auctionViewModels); Assert.AreEqual(username, firstAuction.Seller); }