public async Task Handle_Given_ValidModel_Should_Not_ThrowException() { var itemId = Guid.NewGuid(); await this.Context.Items.AddAsync(new Item { Id = itemId, Title = DataConstants.SampleItemTitle, Description = DataConstants.SampleItemDescription, StartingPrice = DataConstants.SampleItemStartingPrice, MinIncrease = DataConstants.SampleItemMinIncrease, StartTime = this.dateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10)), EndTime = DataConstants.SampleItemEndTime, SubCategoryId = DataConstants.SampleSubCategoryId, UserId = DataConstants.SampleUserId }); await this.Context.SaveChangesAsync(CancellationToken.None); var command = new CreateBidCommand { Amount = 1000, ItemId = itemId, UserId = DataConstants.SampleUserId }; await this.handler.Handle(command, CancellationToken.None); }
public async Task Handle_Given_Model_With_WrongUserId_Should_Throw_NotFoundException(string userId) { var command = new CreateBidCommand { Amount = 1000, ItemId = DataConstants.SampleItemId, UserId = userId }; await Assert.ThrowsAsync <NotFoundException>(() => this.handler.Handle(command, CancellationToken.None)); }
public void ShouldMap_CreateBidCommand_To_Bid() { var entity = new CreateBidCommand(); var result = this.mapper.Map <Bid>(entity); result.Should().NotBeNull(); result.Should().BeOfType <Bid>(); }
Handle_Should_ThrowBadRequestException_InCase_BiddingAmount_IsLower_Than_TheCurrentHighestBid() { var command = new CreateBidCommand { Amount = DataConstants.SampleItemStartingPrice - 1, ItemId = DataConstants.SampleItemId, UserId = DataConstants.SampleUserId }; await Assert.ThrowsAsync <BadRequestException>(() => this.handler.Handle(command, CancellationToken.None)); }
public async Task Handle_Should_ThrowBadRequestException_InCase_Bidding_DidNotStartYet() { var item = await this.Context .Items .Where(i => i.Id == DataConstants.SampleItemId) .SingleOrDefaultAsync(); // Set starTime to be > than current time item.StartTime = this.dateTime.UtcNow.AddYears(10); this.Context.Update(item); await this.Context.SaveChangesAsync(); var command = new CreateBidCommand { Amount = 1000, ItemId = DataConstants.SampleItemId, UserId = DataConstants.SampleUserId }; await Assert.ThrowsAsync <BadRequestException>(() => this.handler.Handle(command, CancellationToken.None)); }
public async Task Handle_Should_ThrowBadRequestException_InCase_Bidding_HasAlreadyEnded() { var item = await this.Context .Items .Where(i => i.Id == DataConstants.SampleItemId) .SingleOrDefaultAsync(); // Set endTime to be < than current time item.EndTime = this.dateTime.UtcNow.Subtract(TimeSpan.FromDays(10)); this.Context.Update(item); await this.Context.SaveChangesAsync(); var command = new CreateBidCommand { Amount = 1000, ItemId = DataConstants.SampleItemId, UserId = DataConstants.SampleUserId }; await Assert.ThrowsAsync <BadRequestException>(() => this.handler.Handle(command, CancellationToken.None)); }
public async Task <IActionResult> Post([FromBody] CreateBidCommand model) { await this.Mediator.Send(model); return(this.NoContent()); }
public static BidPlaced CreateFrom(CreateBidCommand cmd) { return(new BidPlaced(cmd.UserId, cmd.CoinId, cmd.Price, cmd.Quantity)); }
public async Task <IActionResult> MakeBid() { var command = new CreateBidCommand(new Guid("a583c96a-c7e3-4748-81e7-beb0cbd284f7"), 8000); return(Ok(await _mediator.Send(command))); }