public void UploadThumbnailImage_Succeeds() { // Arrange repository.Repository.Add(new DAL.Model.ItemCard { Id = idOfItemCard }); var memoryStream = new MemoryStream(); var testImage = new Bitmap(2, 2); testImage.Save(memoryStream, ImageFormat.Jpeg); unitOfWork.Setup(x => x.GetRepository <DAL.Model.ItemCard>(It.IsAny <bool>())).Returns(repository); environment.Setup(x => x.WebRootPath).Returns(Guid.NewGuid().ToString()); var serviceForTest = new ItemCardService(ajkaShopDbContext.Object, unitOfWork.Object, environment.Object, fileProcessingService.Object, itemCardImageService.Object, itemCardSizePriceService.Object, itemCardQueries.Object, categoryQueries.Object); // Act serviceForTest.UploadThumbnailImageAsync(idOfItemCard, memoryStream, Guid.NewGuid().ToString(), CancellationToken.None).Wait(); // Assert // Thumbnail image is created and network path to this file is stored in DB. Assert.NotNull(repository.Repository.Where(x => x.ThumbnailImagePath != null)); }
public void SynchronizeAdlerItemCards_Succeeds() { // Arrange repository.Repository.Add(new DAL.Model.ItemCard { Id = idOfItemCard, CommodityIdentifier = commodityIdentifier }); unitOfWork.Setup(x => x.GetRepository <DAL.Model.ItemCard>(It.IsAny <bool>())).Returns(repository); var categories = new Dictionary <string, int> { { "TRICKA", 1004 }, { "POLOKOSILE", 1005 }, { "KOSILE", 1006 } }; categoryQueries.Setup(x => x.GetCategoriesCommodityDictionaryAsync(It.IsAny <IAjkaShopDbContext>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult((IDictionary <string, int>)categories)); itemCardQueries.Setup(x => x.GetEntityAsync(It.IsAny <IAjkaShopDbContext>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns <IAjkaShopDbContext, string, CancellationToken>((context, categoryId, token) => { if (categoryId == commodityIdentifier) { return(Task.FromResult(new DAL.Model.ItemCard { Id = idOfItemCard, CommodityIdentifier = commodityIdentifier })); } return(Task.FromResult((DAL.Model.ItemCard)null)); }); var serviceForTest = new ItemCardService(ajkaShopDbContext.Object, unitOfWork.Object, environment.Object, fileProcessingService.Object, itemCardImageService.Object, itemCardSizePriceService.Object, itemCardQueries.Object, categoryQueries.Object); // Act serviceForTest.SynchronizeAdlerItemCardsAsync(ImportAdlerTestData(), CancellationToken.None).Wait(); // Assert // There is one new record and one existing (updated) record. Assert.Equal(2, repository.Repository.Count); // Check for update of existing record on two random chosen attributes. Assert.NotEmpty(repository.Repository.Where(x => x.CommodityIdentifier == commodityIdentifier && x.Description != null && x.Quantity > 0)); // Because all item cards have quantity higher than zero, both records is available for sale. Assert.Empty(repository.Repository.Where(x => x.State != Common.Enums.ItemCardEnums.ItemCardState.ForSale)); }