Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void GivenNullAsOneOfTheArguments_WhenCreateAuctionIsCalled_ExceptionIsThrown()
        {
            // Arrange
            var auctionService = new AuctionService(new AuctionRepositoryFake(), new UserRepositoryFake(), new AuditRepositoryFake());

            // Act & Assert
            Assert.Throws <ArgumentException>(() => auctionService.CreateAuction(null, new AuctionItemViewModel {
                Description = "description", MinAmount = "0", Name = "Item"
            }));
            Assert.Throws <ArgumentNullException>(() => auctionService.CreateAuction("Pera", null));
        }
Exemplo n.º 4
0
        public void Test_Auction_Can_Accept_Bid()
        {
            var user = new User()
            {
                UserName = testUserName
            };
            var userRepo = new UsersRepository();

            userRepo.Add(user);
            userRepo.SetLogin(user, true);

            var repo = new AuctionRepository();
            var sut  = new AuctionService(repo, userRepo);

            var auctionId = sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(1));

            var auction = repo.FindAuctionById(auctionId);
            var myBid   = new Bid {
                amount = 1.75, bidder = "Joe", User = user
            };

            sut.CreateBid(auctionId, 10.0, )
            Assert.True(myBid.amount > auction.HighestBid.amount);
            // public double amount { get; set; }
            // public string bidder { get; set; }
            // public User User { get; set; }
        }
Exemplo n.º 5
0
        public void Test_Auction_Cannot_Be_Created_Invalid_StartDate()
        {
            var repo = new AuctionRepository();
            var sut  = new AuctionService(repo, null);

            Assert.Throws <ArgumentException>(() => sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(-2)));
        }
Exemplo n.º 6
0
        public void Test_Auction_Cannot_Be_Created_User_Not_Authenticated()
        {
            var repo     = new AuctionRepository();
            var userRepo = new UsersRepository();
            var sut      = new AuctionService(repo, userRepo);

            Assert.Throws <Exception>(() => sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(2)));
        }
        public void DeleteAuction()
        {
            //Arrange
            userModel        = new UserModel("Peter", "Torp", "TheDankMan", "Dudududuvej", "*****@*****.**", "99887766", "9876", "2008");
            TestAuctionModel = new AuctionModel(50, 500, 1500, 50, "Lækker lækker MacDut", DateTime.Now, DateTime.Today, "Hjemløs", "TheDankMan");
            //Act
            userService.CreateUser(userModel);
            auctionService.CreateAuction(TestAuctionModel, userModel);
            auctionRepos.deleteAuctionById(TestAuctionModel.Id);

            //Assert
            Assert.IsNull(auctionRepos.getAuctionsByUserName("TheDankMan"));
        }
Exemplo n.º 8
0
        public void Test_Auction_Created_Successfully()
        {
            var repo     = new AuctionRepository();
            var userRepo = new UsersRepository();
            var user     = new User()
            {
                UserName = testUserName
            };

            userRepo.Add(user);
            userRepo.SetLogin(user, true);
            var sut       = new AuctionService(repo, userRepo);
            var auctionId = sut.CreateAuction(testUserName, DateTime.UtcNow.AddDays(2));
            var auction   = repo.FindAuctionById(auctionId);

            Assert.NotNull(auction);
            Assert.Equal(testUserName, auction.Seller.UserName);
            Assert.Equal(auctionId, auction.Id);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 protected void WhenAnAuctionIsCreatedWithSettings(BiddingMethod BiddingMethod, DateTime EndDate)
 {
     var service = new AuctionService();
     this.ReturnedAuctionIdentity = service.CreateAuction(BiddingMethod, EndDate);
 }
        private void Save()
        {
            Auction      = AuctionPrimaryDataVM.Auction;
            Auction.Date = DatesRegulationVM.Order.Auction.Date;

            if (Auction.Id == 0)
            {
                if (string.IsNullOrEmpty(Auction.Number))
                {
                    MessagesService.Show("Сохранение аукциона", "Аукцион не может быть сохранен, так как не имеет номера");
                    return;
                }

                Auction.OwnerId      = 1;
                Auction.signStatusId = 1;

                try {
                    Auction.RegulationId = DatesRegulationVM.CreateRegulation();
                } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка при сохранении дат"); return; }

                try {
                    Auction.FilesListId = DocumentService.CreateFilesList("Файлы аукциона №" + Auction.Number);
                } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка во время занесения данных аукциона"); return; }

                try {
                    Auction.Id = AuctionService.CreateAuction(Auction);
                } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка при сохранении аукциона"); return; }

                if (OrderDetailsVM.Order.id != 0)
                {
                    // Update order
                }
                else
                {
                    // Create order
                    order.customerid = Auction.CustomerId;
                    order.auctionId  = Auction.Id;
                    order.statusId   = 4;
                    order.Number     = Auction.Number;
                    order.siteId     = Auction.SiteId;
                    order.Date       = DatesRegulationVM.Order.Date;

                    try {
                        order.filesListId = DocumentService.CreateFilesList("Файлы заявки №" + order.Number);
                    } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка во время занесения данных заявки"); return; }

                    try {
                        order.id = AuctionService.CreateOrder(order);
                    } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка при создании заявки"); return; }
                }

                Init();
            }
            else
            {
                try {
                    DatesRegulationVM.UpdateRegulation(Auction.RegulationId);
                } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка при сохранении дат"); return; }

                try {
                    AuctionService.UpdateAuction(Auction);
                } catch { MessagesService.Show("Сохранение аукциона", "Произошла ошибка при сохранении аукциона"); return; }
            }

            MessagesService.Show("Сохранение аукциона", "Аукциона успешно сохранен");
        }