public void CreateAuction_when_not_null_image_adds_it_to_auction_images() { AuctionCreateSession.SESSION_MAX_TIME = AuctionCreateSession.DEFAULT_SESSION_MAX_TIME; user.Register(username); var session = user.UserIdentity.GetAuctionCreateSession(); var image1 = new AuctionImage("id1", "id2", "id3"); session.AddOrReplaceImage(image1, 0); var image2 = new AuctionImage("id1", "id2", "id3"); session.AddOrReplaceImage(image2, 1); var auction = session.CreateAuction(auctionArgs); auction.AuctionImages.Count.Should() .Be(Auction.MAX_IMAGES); auction.AuctionImages[0] .Should() .Be(image1); auction.AuctionImages[1] .Should() .Be(image2); for (int i = 2; i < auction.AuctionImages.Count; i++) { auction.AuctionImages[i] .Should() .BeNull(); } }
public void AddOrReplaceImage_adds_to_auction_images() { AuctionCreateSession.SESSION_MAX_TIME = AuctionCreateSession.DEFAULT_SESSION_MAX_TIME; int imgNum = 1; user.Register(username); var session = user.UserIdentity.GetAuctionCreateSession(); var image1 = new AuctionImage("id1", "id2", "id3"); session.AddOrReplaceImage(image1, imgNum); session.AuctionImages.Count.Should() .Be(Auction.MAX_IMAGES); for (int i = 0; i < session.AuctionImages.Count; i++) { if (i == imgNum) { continue; } session.AuctionImages[i] .Should() .BeNull(); } session.AuctionImages[imgNum] .Should() .Be(image1); session.AuctionImages.Count.Should() .Be(Auction.MAX_IMAGES); }
public AuctionImageReplaced(Guid auctionId, int imgNum, AuctionImage newImage, UserIdentity auctionOwner) : base(EventNames.AuctionImageReplaced) { AuctionId = auctionId; ImgNum = imgNum; NewImage = newImage; AuctionOwner = auctionOwner; }
public AuctionImageAdded(AuctionImage addedImage, int num, Guid auctionId, UserIdentity auctionOwner) : base(EventNames.AuctionImageAddedEventName) { AddedImage = addedImage; Num = num; AuctionId = auctionId; AuctionOwner = auctionOwner; }
public void AddOrReplaceImage_when_session_max_time_reached_throws() { user.Register(username); var session = user.UserIdentity.GetAuctionCreateSession(); var img = new AuctionImage("1", "2", "3"); AuctionCreateSession.SESSION_MAX_TIME = -1; Assert.Throws <DomainException>(() => session.AddOrReplaceImage(img, 0)); }
public void AddOrReplaceImage(AuctionImage img, int imgNum) { CheckIsSessionValid(); if (imgNum > SessionAuctionImages.Length) { throw new DomainException($"Cannot add more than {SessionAuctionImages.Length} images"); } SessionAuctionImages[imgNum] = img; }
public void AddImage_when_full_image_list_throws() { var image = new AuctionImage("id1", "id2", "id3"); auction.MarkPendingEventsAsHandled(); for (int i = 1; i <= Auction.MAX_IMAGES; i++) { auction.AddImage(image); } Assert.Throws <DomainException>(() => auction.AddImage(image)); }
public void ResetSession_when_session_max_time_not_reached_resets() { AuctionCreateSession.SESSION_MAX_TIME = AuctionCreateSession.DEFAULT_SESSION_MAX_TIME; user.Register(username); var session = user.UserIdentity.GetAuctionCreateSession(); var img = new AuctionImage("1", "2", "3"); session.AddOrReplaceImage(img, 0); session.ResetSession(); session.AuctionImages[0] .Should() .BeNull(); }
public async Task <IActionResult> UploadImageAuction([FromForm] List <IFormFile> files, int id) { long size = files.Sum(f => f.Length); foreach (var file in files) { if (file.Length > 0) { var path = Path.GetTempFileName(); AuctionImage lastImage = null; if (_context.AuctionImage.Count() > 0) { lastImage = await _context.AuctionImage .OrderBy(x => x.ID) .LastAsync(); } int lastImageID = 1; if (lastImage != null) { lastImageID = (lastImage.ID + 1); } using (var stream = System.IO.File.Create(path)) { await file.CopyToAsync(stream); } var newpath = VeilingConfiguration.AuctionImageLocation + $"/{id}/{lastImageID}{FileContentType.GetExtension(file.ContentType)}"; Directory.CreateDirectory(Path.GetDirectoryName(newpath)); System.IO.File.Delete(newpath); _context.AuctionImage.Add(new AuctionImage() { AuctionID = id, ImageLocation = newpath, ID = lastImageID, AspectRatio = AuctionImage.CalculateAspectRatio(file.OpenReadStream()) }); await _context.SaveChangesAsync(); System.IO.File.Move(path, newpath); System.IO.File.Delete(path); } } return(Ok(new { count = files.Count, size })); }
public AuctionImage AddAuctionImage(AuctionImageRepresentation representation) { if (!_imageConverterService.ValidateImage(representation, AuctionImage.AllowedExtensions)) { throw new DomainException("Invalid image"); } var img = new AuctionImage( AuctionImage.GenerateImageId(AuctionImageSize.SIZE1), AuctionImage.GenerateImageId(AuctionImageSize.SIZE2), AuctionImage.GenerateImageId(AuctionImageSize.SIZE3) ); AddConvertedImage(img.Size1Id, AuctionImageSize.SIZE1, representation); AddConvertedImage(img.Size2Id, AuctionImageSize.SIZE2, representation); AddConvertedImage(img.Size3Id, AuctionImageSize.SIZE3, representation); return(img); }
public void AddImage_when_empty_image_list_adds_image() { var image = new AuctionImage("id1", "id2", "id3"); auction.MarkPendingEventsAsHandled(); auction.AddImage(image); var ev = auction.PendingEvents.First() as AuctionImageAdded; auction.PendingEvents.Count.Should() .Be(1); auction.PendingEvents.First() .GetType() .Should() .Be(typeof(AuctionImageAdded)); ev.AddedImage.Should() .Be(image); ev.AuctionId.Should() .Be(auction.AggregateId); ev.Num.Should() .Be(0); }
internal AuctionCreateSession(UserIdentity creator) { Creator = creator; DateCreated = DateTime.UtcNow; SessionAuctionImages = new AuctionImage[Auction.MAX_IMAGES]; }
public void RemoveAuctionImage(AuctionImage img) { _imageRepository.Remove(img.Size1Id); _imageRepository.Remove(img.Size2Id); _imageRepository.Remove(img.Size3Id); }
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); }