コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }