Beispiel #1
0
        public void AuctionArgsBuilder_when_invalid_params_throws()
        {
            var builder = new AuctionArgs.Builder();

            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetCategory(new Category("test", 0));
            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetOwner(new UserIdentity());
            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetProduct(new Product("test name", "desccription 1111", Condition.New));
            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetStartDate(DateTime.UtcNow.AddMinutes(20));
            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetEndDate(DateTime.UtcNow.AddDays(5));
            Assert.Throws <DomainException>(() => builder.Build());

            builder.SetTags(new [] { "tag1", "tag2" });
            Assert.Throws <DomainException>(() => builder.Build());
            builder.SetName("Example name");
            Assert.DoesNotThrow(() => builder.Build());
            builder.SetBuyNow(20.0m);
            Assert.DoesNotThrow(() => builder.Build());
            builder.SetBuyNowOnly(false);
            Assert.DoesNotThrow(() => builder.Build());


            builder.SetBuyNow(20.0m);
            Assert.DoesNotThrow(() => builder.Build());
        }
Beispiel #2
0
        public void Auction_FromEvents_builds_valid_auction()
        {
            var start       = DateTime.UtcNow.AddMinutes(20);
            var end         = start.AddDays(2);
            var id          = Guid.NewGuid();
            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(20)
                              .SetStartDate(start)
                              .SetEndDate(end)
                              .SetOwner(new UserIdentity())
                              .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetTags(new[] { "tag1" })
                              .SetName("Test name")
                              .Build();
            var events = new Event[]
            {
                new AuctionCreated(id, auctionArgs)
            };

            var auction = Auction.FromEvents(events);

            auction.PendingEvents.Count.Should()
            .Be(0);
            auction.AggregateId.Should()
            .NotBeEmpty()
            .And.Be(id);
            auction.BuyNowPrice.Value.Should()
            .Be(20m);
            auction.Product.Should()
            .NotBeNull();
            auction.Buyer.Should()
            .Be(UserIdentity.Empty);
            auction.Completed.Should()
            .BeFalse();
            auction.ActualPrice.Should()
            .Be(0);
            auction.Owner.Should()
            .NotBeNull();
            auction.StartDate.Value.Should()
            .Be(start);
            auction.EndDate.Value.Should()
            .Be(end);
            auction.Tags.Length.Should()
            .Be(1);
            auction.Tags[0]
            .Value.Should()
            .Be("tag1");
        }
Beispiel #3
0
        public void AuctionConstructor_when_tags_array_contains_repeating_tags_throws()
        {
            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(90.00m)
                              .SetStartDate(DateTime.UtcNow)
                              .SetEndDate(DateTime.UtcNow.AddDays(1))
                              .SetOwner(new UserIdentity())
                              .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetTags(new[] { "t1", "t1" })
                              .SetName("test name")
                              .Build();

            Assert.Throws <DomainException>(() => new Auction(auctionArgs));
        }
        public Auction CreateAuction(AuctionArgs auctionArgs)
        {
            CheckIsSessionValid();
            if (Creator == null)
            {
                throw new DomainException("User must be registered to create auction");
            }
            var args = new AuctionArgs.Builder()
                       .From(auctionArgs)
                       .SetImages(SessionAuctionImages)
                       .SetOwner(Creator)
                       .Build();
            var auction = new Auction(args);

            return(auction);
        }
        public void SetUp()
        {
            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(90.00m)
                              .SetStartDate(DateTime.UtcNow.AddMinutes(20))
                              .SetEndDate(DateTime.UtcNow.AddDays(5))
                              .SetOwner(new UserIdentity())
                              .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetBuyNowOnly(false)
                              .SetTags(new[] { "tag1" })
                              .SetName("Test name")
                              .Build();

            auction = new Auction(auctionArgs);
        }
Beispiel #6
0
        public static Auction CreateBuyNowOnlyAuction()
        {
            var args = new AuctionArgs.Builder()
                       .SetBuyNowOnly(true)
                       .SetOwner(new UserIdentity())
                       .SetCategory(new Category("", 1))
                       .SetBuyNow(123)
                       .SetStartDate(DateTime.UtcNow.AddDays(1))
                       .SetEndDate(DateTime.UtcNow.AddDays(2))
                       .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                       .SetTags(new[] { "tag1" })
                       .SetName("Test name")
                       .Build();

            return(new Auction(args));
        }
Beispiel #7
0
        private Auction CreateFakeAuction()
        {
            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(20.0m)
                              .SetStartDate(DateTime.UtcNow.AddMinutes(10))
                              .SetEndDate(DateTime.UtcNow.AddDays(1))
                              .SetOwner(new UserIdentity()
            {
                UserName = "******", UserId = Guid.NewGuid()
            })
                              .SetProduct(new Product("product name", "description 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetTags(new [] { "tag1", "tag2" })
                              .SetName("Test name")
                              .Build();
            var auction = new Auction(auctionArgs);

            return(auction);
        }
        private AuctionArgs GetAuctionArgs(CreateAuctionCommand request, UserIdentity owner)
        {
            var category = _deps.categoryBuilder.FromCategoryNamesList(request.Category);
            var builder = new AuctionArgs.Builder()
                .SetStartDate(request.StartDate)
                .SetEndDate(request.EndDate)
                .SetCategory(category)
                .SetProduct(request.Product)
                .SetTags(request.Tags)
                .SetName(request.Name)
                .SetBuyNowOnly(request.BuyNowOnly.Value)
                .SetOwner(owner);
            if (request.BuyNowPrice != null)
            {
                builder.SetBuyNow(request.BuyNowPrice.Value);
            }

            return builder.Build();
        }
Beispiel #9
0
        public void AuctionConstructor_when_invalid_tags_throws()
        {
            var builder = new AuctionArgs.Builder()
                          .SetBuyNow(90.00m)
                          .SetStartDate(DateTime.UtcNow.AddMinutes(20))
                          .SetEndDate(DateTime.UtcNow.AddDays(5))
                          .SetOwner(new UserIdentity())
                          .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                          .SetCategory(new Category("test", 0))
                          .SetBuyNowOnly(false)
                          .SetName("Test name");
            var args = builder
                       .SetTags(Enumerable.Range(0, Auction.MIN_TAGS - 1)
                                .Select(i => $"tag1{i}")
                                .ToArray())
                       .Build();

            Assert.Throws <DomainException>(() => new Auction(args));
        }
Beispiel #10
0
        public void AuctionConstructor_when_invalid_end_date_args_throws(int minutesStart, int minutesEnd, bool throws)
        {
            var date = DateTime.UtcNow;

            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(90.00m)
                              .SetStartDate(date.AddMinutes(minutesStart))
                              .SetEndDate(date.AddMinutes(minutesEnd))
                              .SetOwner(new UserIdentity())
                              .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetTags(new[] { "t1" })
                              .SetName("test name")
                              .Build();

            if (throws)
            {
                Assert.Throws <DomainException>(() => new Auction(auctionArgs));
            }
            else
            {
                Assert.DoesNotThrow(() => new Auction(auctionArgs));
            }
        }
        public void Test1()
        {
            var services = TestDepedencies.Instance.Value;
            var user     = new User();

            user.Register("testUserName");
            user.AddCredits(10000);
            var userIdentity = user.UserIdentity;

            services.UserRepository.AddUser(user);


            var product     = new Product("test name", "test product description", Condition.New);
            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(20.0m)
                              .SetName("test auction name")
                              .SetStartDate(DateTime.UtcNow.AddMinutes(10))
                              .SetEndDate(DateTime.UtcNow.AddDays(1))
                              .SetCategory(new Category("test", 0))
                              .SetOwner(new UserIdentity()
            {
                UserId = Guid.NewGuid(), UserName = "******"
            })
                              .SetProduct(product)
                              .SetTags(new string[] { "tag1", "tag2" })
                              .Build();
            var auction = new Auction(auctionArgs);
            var sem     = new SemaphoreSlim(0, 1);


            var eventHandler = new Mock <AuctionRaisedHandler>(services.AppEventBuilder,
                                                               services.DbContext, Mock.Of <IRequestStatusService>(), Mock.Of <ILogger <AuctionRaisedHandler> >());

            eventHandler.CallBase = true;
            eventHandler.Setup(f => f.Consume(It.IsAny <IAppEvent <AuctionRaised> >()))
            .Callback(() => sem.Release());


            var requestStatusService = new Mock <IRequestStatusService>();

            requestStatusService.Setup(service =>
                                       service.TrySendNotificationToAll("AuctionPriceChanged", It.IsAny <Dictionary <string, object> >()));

            services.SetupEventBus(eventHandler.Object);

            var stubHandler = new BidCommandHandler(services.AuctionRepository,
                                                    services.EventBus, Mock.Of <ILogger <BidCommandHandler> >(), requestStatusService.Object, services.UserRepository);

            services.AuctionRepository.AddAuction(auction);
            var cmd = new BidCommand(auction.AggregateId, 21.0m);

            cmd.SignedInUser = userIdentity;
            stubHandler.Handle(cmd, CancellationToken.None);


            if (!sem.Wait(TimeSpan.FromSeconds(60)))
            {
                Assert.Fail();
            }
            ;

            eventHandler.Verify(f => f.Consume(It.IsAny <IAppEvent <AuctionRaised> >()), Times.Once);
            requestStatusService.Verify(f => f.TrySendNotificationToAll("AuctionPriceChanged", It.IsAny <Dictionary <string, object> >()), Times.Once());
        }
Beispiel #12
0
        public void AuctionConstructor_when_valid_args_generates_valid_pending_events()
        {
            var image1 = new AuctionImage("1", "2", "3");
            var image2 = new AuctionImage("1", "2", "3");
            var imgs   = new AuctionImage[] { image1, image2 };
            var start  = DateTime.UtcNow.AddMinutes(20);
            var end    = DateTime.UtcNow.AddDays(1);
            var owner  = new UserIdentity()
            {
                UserId = Guid.NewGuid(), UserName = "******"
            };

            var auctionArgs = new AuctionArgs.Builder()
                              .SetBuyNow(90.00m)
                              .SetStartDate(start)
                              .SetEndDate(end)
                              .SetOwner(owner)
                              .SetProduct(new Product("test name", "desccription 1111", Condition.New))
                              .SetCategory(new Category("test", 0))
                              .SetImages(imgs)
                              .SetTags(new[] { "tag1" })
                              .SetName("Test auction")
                              .Build();
            var auction = new Auction(auctionArgs);

            auction.Category.Should()
            .Be(auctionArgs.Category);
            auction.ActualPrice.Should()
            .Be(0);
            auction.AuctionImages[0]
            .Should()
            .Be(imgs[0]);
            auction.AuctionImages[1]
            .Should()
            .Be(imgs[1]);
            auction.Bids.Count.Should()
            .Be(0);
            auction.BuyNowPrice.Value.Should()
            .Be(90.00m);
            auction.StartDate.Value.Should()
            .Be(start);
            auction.EndDate.Value.Should()
            .Be(end);
            auction.Owner.Should()
            .Be(owner);
            auction.Tags[0]
            .Value
            .Should()
            .Be("tag1");
            auction.Tags.Length.Should()
            .Be(1);
            auction.Name.Value.Should()
            .Be("Test auction");

            auction.PendingEvents.Count.Should()
            .Be(1);
            auction.AggregateId.Should()
            .NotBeEmpty();
            var createdEvent = auction.PendingEvents.First() as AuctionCreated;

            createdEvent.Should()
            .NotBeNull();
            createdEvent.AuctionArgs.Should()
            .BeEquivalentTo(auctionArgs);
        }