public async Task CreatePromotionOrderAsync_WithInvalidAdId_ShouldThrowAnArgumentException() { //Arrange var expectedErrorMessage = "Ad with the given id doesn't exist!"; var moqAdsService = new Mock <IAdsService>(); var context = InitializeContext.CreateContextForInMemory(); promotionsService = new PromotionsService(context, moqAdsService.Object); //Act and assert var ex = await Assert.ThrowsAsync <ArgumentException>(() => promotionsService.CreatePromotionOrderAsync(1, 1)); Assert.Equal(expectedErrorMessage, ex.Message); }
public async Task CreatePromotionOrderAsync_WithInvalidPromotionId_ShouldThrowAnArgumentException() { //Arrange var expectedErrorMessage = "Promotion with the given id doesn't exist!"; var moqAdsService = new Mock <IAdsService>(); var context = InitializeContext.CreateContextForInMemory(); promotionsService = new PromotionsService(context, moqAdsService.Object); var testingAd = new Ad { Id = 1, Title = "Iphone 6s", Description = "PerfectCondition", ActiveFrom = DateTime.UtcNow, ActiveTo = DateTime.UtcNow.AddDays(30), AvailabilityCount = 1, Price = 120, Condition = new Condition { Name = "Brand New" }, Address = new Address { Id = 1, Country = "Bulgaria", City = "Sofia", Street = "Ivan Vazov", District = "Student city", ZipCode = 1000, PhoneNumber = "0895335532", EmailAddress = "*****@*****.**" } }; await context.Ads.AddAsync(testingAd); await context.SaveChangesAsync(); //Act and assert var ex = await Assert.ThrowsAsync <ArgumentException>(() => promotionsService.CreatePromotionOrderAsync(1, 1)); Assert.Equal(expectedErrorMessage, ex.Message); }
public async Task CreatePromotionOrderAsync_WithValidData_ShouldCreateAnPromotionOrder() { //Arrange var moqAdsService = new Mock <IAdsService>(); moqAdsService.Setup(x => x.GetAdByIdAsync(1)) .ReturnsAsync(new Ad { Id = 1, Title = "Iphone 6s", Description = "PerfectCondition", ActiveFrom = DateTime.UtcNow, ActiveTo = DateTime.UtcNow.AddDays(30), AvailabilityCount = 1, Price = 120, Condition = new Condition { Name = "Brand New" }, Address = new Address { Country = "Bulgaria", City = "Sofia", Street = "Ivan Vazov", District = "Student city", ZipCode = 1000, PhoneNumber = "0895335532", EmailAddress = "*****@*****.**" } }); var context = InitializeContext.CreateContextForInMemory(); promotionsService = new PromotionsService(context, moqAdsService.Object); var testingAd = new Ad { Id = 1, Title = "Iphone 6s", Description = "PerfectCondition", ActiveFrom = DateTime.UtcNow, ActiveTo = DateTime.UtcNow.AddDays(30), AvailabilityCount = 1, Price = 120, Condition = new Condition { Name = "Brand New" }, Address = new Address { Id = 1, Country = "Bulgaria", City = "Sofia", Street = "Ivan Vazov", District = "Student city", ZipCode = 1000, PhoneNumber = "0895335532", EmailAddress = "*****@*****.**" } }; var testingPromotion = new Promotion { Id = 1, ActiveDays = 10, Price = 3.50M, Type = "silver", Updates = 3 }; await context.Ads.AddAsync(testingAd); await context.Promotions.AddAsync(testingPromotion); await context.SaveChangesAsync(); //Act await promotionsService.CreatePromotionOrderAsync(1, 1); //Assert Assert.True(context.PromotionOrders.Count() == 1); }