public async Task CreateAndAddNewOfferWithIDsInDB_WhenValidParametersArePassed() { var databaseName = System.Reflection.MethodBase.GetCurrentMethod().Name; using (var context = new StoreSystemDbContext(DbSeed.GetOptions(databaseName))) { //Arrange var dateTimeNowProvider = new Mock <IDateTimeNowProvider>(); var validDate = new DateTime(2019, 1, 1); dateTimeNowProvider.Setup(x => x.Now).Returns(validDate); var sut = new OfferService(context, dateTimeNowProvider.Object); var client = 1; var address = 1; var city = 1; var country = 1; var deadline = new DateTime(2019, 5, 10); var discount = 0.10m; //Act await sut.CreateOfferAsync(client, discount, deadline, address, city, country); //Assert Assert.AreEqual(1, context.Offers.Count()); Assert.AreEqual(client, context.Offers.Single(x => x.ClientID == client).ClientID); } }
public async Task RemoveFromFavoritesAsync_WithInValidDataWithNotFoundOffer_ShouldNotAddOfferToFavorites() { var expectedOffersCount = 1; var guid = Guid.NewGuid().ToString(); var moqUsersService = new Mock <IUserService>(); moqUsersService.Setup(x => x.GetCurrentUserId()) .Returns("CurrentUserId"); var moqCategoriesService = new Mock <ICategoryService>(); var moqCloudinaryService = new Mock <ICloudinaryService>(); var moqIFormFile = new Mock <IFormFile>(); moqCloudinaryService.Setup(x => x.UploadPhotoAsync(moqIFormFile.Object, "FileName", "Folder")) .ReturnsAsync("http://test.com"); var createOfferInputModel = new CreateOfferModel { Name = "Wow Account", CategotyName = "Wow", CreatorId = guid, Description = "Some Test Description", Price = 10.00, PicUrl = "link", }; var user = new ApplicationUser() { Id = guid, UserName = "******", }; var context = InitializeContext.CreateContextForInMemory(); var offerService = new OfferService(context, moqCategoriesService.Object, moqCloudinaryService.Object); this.favoriteService = new FavoriteService(context, offerService); var approvedOffer = await offerService.CreateOfferAsync(createOfferInputModel); await offerService.ApproveOfferAsync(approvedOffer.Id); context.Users.Add(user); await context.SaveChangesAsync(); // Assert await this.favoriteService.AddToFavoritesAsync(approvedOffer.Id, guid); var result = await this.favoriteService.AddToFavoritesAsync("InvalidID", guid); var userFav = await context.UserFavorites.FirstOrDefaultAsync(x => x.OfferId == approvedOffer.Id && x.UserId == guid); Assert.NotNull(userFav); Assert.False(result); }