public async Task DeletePreviousUserAllergensByUserId_WithExistentUserId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "UserAllergenService DeletePreviousUserAllergensByUserId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userAllergenRepository = new EfRepository <UserAllergen>(context); var userAllergenService = new UserAllergenService(userAllergenRepository); await this.SeedDataAsync(context); var userId = context.Users.First(x => x.Biography == "User with milk and eggs allergies").Id; // Act var userAllergensCount = userAllergenRepository.All().Count(); userAllergenService.DeletePreviousUserAllergensByUserId(userId); await userAllergenRepository.SaveChangesAsync(); var actualResult = userAllergenRepository.All().Count(); var expectedResult = userAllergensCount - 2; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly."); }
public async Task RemoveFollowerAsync_WithValidData_ShouldRemoveFollowerFromDatabase() { // Arrange this.InitilaizeMapper(); var context = InMemoryDbContext.Initiliaze(); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(context); var userFollowerRepository = new EfRepository <UserFollower>(context); var profileService = new ProfilesService(userRepository, userFollowerRepository); await this.SeedUsers(context); await userFollowerRepository.AddAsync(new UserFollower { UserId = "userOneId", FollowerId = "userTwoId" }); await userFollowerRepository.SaveChangesAsync(); var model = new AddFollowerModel { UserId = "userOneId", FollowerId = "userTwoId", }; // Act int expectedCount = userFollowerRepository.All().Count() - 1; await profileService.RemoveFollowerAsync(model); int actualCount = userFollowerRepository.All().Count(); // Assert Assert.Equal(expectedCount, actualCount); }
public async Task DeletePreviousRecipeLifestylesByRecipeId_WithNonExistentRecipeId_ShouldWorkProperly() { var errorMessagePrefix = "RecipeLifestyleService DeletePreviousRecipeLifestylesByRecipeId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipeLifestyleRepository = new EfRepository <RecipeLifestyle>(context); var recipeLifestyleService = new RecipeLifestyleService(recipeLifestyleRepository); await this.SeedDataAsync(context); var recipeId = Guid.NewGuid().ToString(); // Act var recipeAllergensCount = recipeLifestyleRepository.All().Count(); recipeLifestyleService.DeletePreviousRecipeLifestylesByRecipeId(recipeId); await recipeLifestyleRepository.SaveChangesAsync(); var actualResult = recipeLifestyleRepository.All().Count(); var expectedResult = recipeAllergensCount; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count does not match."); }
public async Task TestDeleteIngredientToItem() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var recipeStepRepository = new EfRepository <RecipeStep>(new ApplicationDbContext(options.Options)); var itemRepository = new EfRepository <Item>(new ApplicationDbContext(options.Options)); recipeStepRepository.AddAsync(new RecipeStep { Description = "Testing description", Minutes = 10 }).GetAwaiter().GetResult(); recipeStepRepository.SaveChangesAsync().GetAwaiter().GetResult(); itemRepository.AddAsync(new Item { Name = "Meatball" }).GetAwaiter().GetResult(); itemRepository.SaveChangesAsync().GetAwaiter().GetResult(); var item = itemRepository.All().Where(x => x.Name == "Meatball").FirstOrDefault(); var recipeStep = recipeStepRepository.All().Where(x => x.Description == "Testing description").FirstOrDefault(); var recipeStepService = new RecipeStepService(itemRepository, recipeStepRepository); await recipeStepService.AddRecipeStepToItem(recipeStep.Description, recipeStep.Minutes, item.Name); await recipeStepService.DeleteRecipeToItem(1); Assert.False(recipeStepRepository.All().FirstOrDefault().Description == null); }
public async Task DeletePreviousRecipeLifestylesByRecipeId_WithExistentRecipeId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "RecipeLifestyleService DeletePreviousRecipeLifestylesByRecipeId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipeLifestyleRepository = new EfRepository <RecipeLifestyle>(context); var recipeLifestyleService = new RecipeLifestyleService(recipeLifestyleRepository); await this.SeedDataAsync(context); var recipeId = context.Recipes.First(x => x.Title == "Recipe for vegetarians and vegans").Id; // Act var recipeLifestylesCount = recipeLifestyleRepository.All().Count(); recipeLifestyleService.DeletePreviousRecipeLifestylesByRecipeId(recipeId); await recipeLifestyleRepository.SaveChangesAsync(); var actualResult = recipeLifestyleRepository.All().Count(); var expectedResult = recipeLifestylesCount - 2; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly."); }
public async Task GetByIdAsync_WithExistentId_ShouldReturnCorrectResult() { var errorMessagePrefix = "LifestyleService GetByIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var existentId = lifestyleRepository.All().First().Id; // Act var actualResult = await lifestyleService.GetByIdAsync(existentId); var expectedResult = (await lifestyleRepository .All() .SingleOrDefaultAsync(x => x.Id == existentId)) .To <LifestyleServiceModel>(); // Assert Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResult.Type == expectedResult.Type, errorMessagePrefix + " " + "Type is not returned properly."); }
public async Task AddFundsAsync_WithCorrectData_ShouldSuccessfullyUpdate() { var errorMessage = "UsersService AddFundsAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var usersRepository = new EfRepository <ApplicationUser>(context); var cloudinaryService = new Mock <ICloudinaryService>(); var usersService = new UsersService(usersRepository, cloudinaryService.Object); var userStore = new ApplicationUserStore(context); var userManager = new UserManager <ApplicationUser>(userStore, null, null, null, null, null, null, null, null); var user = new ApplicationUser() { Id = Guid.NewGuid().ToString(), UserName = "******", }; // Act await userManager.CreateAsync(user); var funds = usersRepository.All().First().Funds; await usersService.AddFundsAsync(user, 5); var actualResult = usersRepository.All().First().Funds; var expectedResult = funds + 5; // Assert Assert.True(expectedResult == actualResult, errorMessage); }
public async Task DeleteByUserIdAndShoppingListIdAsync_WithExistentUserIdAndShoppingListId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "UserShoppingListService DeleteByUserIdAndShoppingListIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userShoppingListRepository = new EfRepository <UserShoppingList>(context); var userShoppingListService = new UserShoppingListService(userShoppingListRepository); await this.SeedDataAsync(context); var userId = context.Users.First(x => x.FullName == "User 1").Id; var shoppingListId = context.ShoppingLists.First(x => x.Ingredients == "Ingredients 1").Id; // Act var userShoppingListsCount = userShoppingListRepository.All().Count(); await userShoppingListService .DeleteByUserIdAndShoppingListIdAsync(userId, shoppingListId); var actualResult = userShoppingListRepository.All().Count(); var expectedResult = userShoppingListsCount - 1; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly."); }
public async Task TestDeleteIngredientToItem() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var ingredientrRepository = new EfRepository <Ingredient>(new ApplicationDbContext(options.Options)); var itemRepository = new EfRepository <Item>(new ApplicationDbContext(options.Options)); ingredientrRepository.AddAsync(new Ingredient { Name = "Meat", Quantity = 5 }).GetAwaiter().GetResult(); ingredientrRepository.SaveChangesAsync().GetAwaiter().GetResult(); itemRepository.AddAsync(new Item { Name = "Kebapche" }).GetAwaiter().GetResult(); itemRepository.SaveChangesAsync().GetAwaiter().GetResult(); var item = itemRepository.All().Where(x => x.Name == "Kebapche").FirstOrDefault(); var firstIngredient = ingredientrRepository.All().Where(x => x.Name == "Meat").FirstOrDefault(); var ingredientService = new IngredientService(itemRepository, ingredientrRepository); //AutoMapperConfig.RegisterMappings(typeof(MyTestIngredient).Assembly); await ingredientService.AddIngredientToItem(firstIngredient.Name, firstIngredient.Quantity, item.Name); await ingredientService.DeleteIngredientToItem(firstIngredient.Name, firstIngredient.Quantity, item.Name, 1); ingredientrRepository.SaveChangesAsync().GetAwaiter().GetResult(); Assert.True(ingredientrRepository.All().Select(x => x.Name == "Meat").FirstOrDefault()); }
public async Task AddAsyncShouldIncreaseContactFormEntries() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var contactFormRepository = new EfRepository <ContactFormEntry>(context); var contactFormService = new ContactFormService(contactFormRepository); var input = new ContactFormViewModel(); var countPreAdd = contactFormRepository.All().Count(); var result = await contactFormService.AddAsync(input); var countAfterAdd = contactFormRepository.All().Count(); Assert.AreEqual(countPreAdd + 1, countAfterAdd); }
public async Task CreateMovieWithValidInputData() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "MoviesDbTest").Options; var dbContext = new ApplicationDbContext(options); var repository = new EfRepository <Movie>(dbContext); var service = new MovieService(repository); var inputModel = new MovieInputModel { Title = "Titanic", Actors = "Test actor, test actor, test actor", Country = MegaCinema.Data.Models.Enums.Country.USA, Description = "test description test description", Director = "John West", Duration = new System.TimeSpan(1, 35, 33), Genre = GenreType.Adventure, Language = MegaCinema.Data.Models.Enums.Language.English, Poster = "http://testposter.com", Rating = MPAARating.G, ReleaseDate = new System.DateTime(2020, 2, 15), Score = 4.5, Trailer = "sometext", }; var id = await service.CreateMovie(inputModel); var movie = repository.All().FirstOrDefault(x => x.Id == id); Assert.True(movie.Title == "Titanic"); Assert.True(movie.Director == "John West"); Assert.True(movie.Score == 4.5); }
public async Task AcceptOrderAsync_WithCorrectData_ShouldSuccessfullyUpdate() { var errorMessage = "BoostingService AcceptOrderAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var boostOrdersRepository = new EfRepository <BoostOrder>(context); var boostingService = new BoostingService(boostOrdersRepository); var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), }; var boostOrderModel = new PurchaseInputModel { CurrentRank = "Diamond 1", Ranks = 1, Username = "******", Password = "******", }; // Act await boostingService.AddAsync(boostOrderModel); await boostingService.AcceptOrderAsync(user, boostOrderModel.Username); var actualResult = boostOrdersRepository.All().First(); var expectedResult = user.Id; // Assert Assert.True(expectedResult == actualResult.BoosterId, errorMessage); }
public async Task GetIdsByNamesAsync_WithCorrectData_ShouldReturnCorrectResult() { var errorMessagePrefix = "AllergenService GetIdsByNamesAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var existentNames = new string[] { "Milk", "Eggs" }; // Act var actualResult = (await allergenService.GetIdsByNamesAsync(existentNames)).ToList(); var expectedResult = await allergenRepository .All() .Where(x => existentNames.Contains(x.Name)) .Select(x => x.Id) .ToListAsync(); // Assert for (int i = 0; i < actualResult.Count; i++) { Assert.True(actualResult[i] == expectedResult[i], errorMessagePrefix + " " + "Id is not returned properly."); } }
public void All_ShouldReturn_InstanceOfIQueryable() { //Arrange var posts = new List <Post> { new Post() { Id = 1, Title = "post", Content = "content" }, new Post() { Id = 2, Title = "post", Content = "content" } }; var mockedDbContext = new Mock <MsSqlDbContext>(); var mockedPostSet = QueryableDbSetMock.GetQueryableMockDbSet <Post>(posts); mockedDbContext.Setup(c => c.Set <Post>()).Returns(mockedPostSet); mockedDbContext.Setup(c => c.Posts).Returns(mockedPostSet); var repositoryUnderTest = new EfRepository <Post>(mockedDbContext.Object); //Act var result = repositoryUnderTest.All(); //Assert Assert.IsInstanceOf(typeof(IQueryable <Post>), result); }
public void TestAddSkillinUser() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options)); var studentEfRepository = new EfRepository <StudentJob>(new ApplicationDbContext(options.Options)); var userSkillRepository = new EfRepository <UsersSkill>(new ApplicationDbContext(options.Options)); var jobRepository = new EfDeletableEntityRepository <Job>(new ApplicationDbContext(options.Options)); var jobService = new JobsService(jobRepository, studentEfRepository); var skillRepository = new EfDeletableEntityRepository <Skill>(new ApplicationDbContext(options.Options)); var skillService = new SkillsService(skillRepository, userSkillRepository); var usersService = new ApplicationUsersService(repository, jobService, studentEfRepository, jobRepository, skillService, userSkillRepository, skillRepository); var user = new ApplicationUser { Description = "test", Type = UserType.Student, }; var skill = new Skill { Name = "test", }; skillRepository.AddAsync(skill).GetAwaiter().GetResult(); skillRepository.SaveChangesAsync().GetAwaiter().GetResult(); repository.AddAsync(user).GetAwaiter().GetResult(); repository.SaveChangesAsync().GetAwaiter().GetResult(); AutoMapperConfig.RegisterMappings(typeof(CompaniesServiceTests.MyTest).Assembly); Assert.NotNull(userSkillRepository.All()); }
public async Task CreateAllAsync_WithDummyData_ShouldSuccessfullyCreate() { var errorMessagePrefix = "AllergenService CreateAllAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var allergenNames = new string[] { "Milk", "Eggs" }; // Act await allergenService.CreateAllAsync(allergenNames); var actualResult = await allergenRepository .All() .Select(x => x.Name) .ToListAsync(); var expectedResult = allergenNames; // Assert for (int i = 0; i < actualResult.Count; i++) { Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "Expected name and actual name do not match."); } }
public async Task AddAsync_WithCorrectData_ShouldSuccessfullyCreate() { var errorMessage = "BoostingService AddAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var boostOrdersRepository = new EfRepository <BoostOrder>(context); var boostingService = new BoostingService(boostOrdersRepository); var boostOrderModel = new PurchaseInputModel { CurrentRank = "Diamond 1", Ranks = 1, Username = "******", Password = "******", }; // Act await boostingService.AddAsync(boostOrderModel); var actualResult = boostOrdersRepository.All().First(); var expectedResult = boostOrderModel; // Assert Assert.True(expectedResult.CurrentRank == actualResult.CurrentRank, errorMessage); Assert.True(expectedResult.Ranks == actualResult.Ranks, errorMessage); Assert.True(expectedResult.Username == actualResult.Username, errorMessage); Assert.True(expectedResult.Password == actualResult.Password, errorMessage); }
public async Task CreateCoverPictureAsyncShouldCreateCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext); var applicationUser = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var pictureRepository = new EfRepository <UserProfilePicture>(dbContext); var repositoryComment = new EfDeletableEntityRepository <NewsFeedComment>(dbContext); var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext); var friendRepository = new EfDeletableEntityRepository <Friend>(dbContext); var userPicture = new UserCoverPicture { PictureURL = "mountain.jpg", ApplicationUserId = "1", }; var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository); var createResult = service.CreateCoverPictureAsync(userPicture.ApplicationUserId, userPicture.PictureURL); Assert.Equal(1, coverPictureRepository.All().Count()); }
public async Task CheckRemovingProductToProcedureAsync() { ApplicationDbContext db = GetDb(); var repository = new EfDeletableEntityRepository <Procedure>(db); var procedureProductsRepository = new EfRepository <ProcedureProduct>(db); var service = new ProceduresService( repository, this.procedureReviewsRepository.Object, procedureProductsRepository, this.procedureStylistsRepository.Object, this.skinProblemProceduresRepository.Object, this.appointmentsRepository.Object, this.categoriesService.Object); var procedure = new Procedure() { Id = "1", }; var product = new Product() { Id = "1" }; await service.AddProductToProcedureAsync(procedure.Id, product.Id); await service.RemoveProductAsync(product.Id, procedure.Id); Assert.Empty(procedureProductsRepository.All()); }
public async Task SetAllergenToUserAsync_WithCorrectData_ShouldSuccessfullySet() { var errorMessagePrefix = "AllergenService SetAllergenToUserAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var user = new ApplicationUser(); // Act await allergenService.SetAllergenToUserAsync("Milk", user); var actualResult = user.Allergies.First().Allergen; var expectedResult = await allergenRepository .All() .SingleOrDefaultAsync(x => x.Name == "Milk"); // Assert Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResult.Name == expectedResult.Name, errorMessagePrefix + " " + "Name is not returned properly."); }
public async Task CreateAllAsync_WithCorrectData_ShouldSuccessfullyCreate() { var errorMessagePrefix = "LifestyleService CreateAllAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var lifestyleTypes = new string[] { "Vegetarian", "Dairy Free" }; // Act await lifestyleService.CreateAllAsync(lifestyleTypes); var actualResult = await lifestyleRepository .All() .Select(x => x.Type) .ToListAsync(); var expectedResult = lifestyleTypes; // Assert for (int i = 0; i < actualResult.Count; i++) { Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "Expected type and actual type do not match."); } }
public async Task SetLifestyleToUserAsync_WithCorrectData_ShouldSuccessfullySet() { var errorMessagePrefix = "LifestyleService SetLifestyleToUserAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var user = new ApplicationUser(); // Act await lifestyleService.SetLifestyleToUserAsync("Vegetarian", user); var actualResult = user.Lifestyle; var expectedResult = await lifestyleRepository .All() .SingleOrDefaultAsync(x => x.Type == "Vegetarian"); // Assert Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResult.Type == expectedResult.Type, errorMessagePrefix + " " + "Type is not returned properly."); }
public async Task GetShoppingListsByUserIdAsync_WithExistentUserId_ShouldReturnCorrectResult() { var errorMessagePrefix = "UserShoppingListService GetShoppingListsByUserIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userShoppingListRepository = new EfRepository <UserShoppingList>(context); var userShoppingListService = new UserShoppingListService(userShoppingListRepository); await this.SeedDataAsync(context); var userId = context.Users.First(x => x.FullName == "User 1").Id; // Act var actualResult = (await userShoppingListService .GetShoppingListsByUserIdAsync(userId)) .ToList(); var expectedResult = userShoppingListRepository .All() .Where(x => x.UserId == userId) .OrderBy(x => x.AddedOn) .Select(x => x.ShoppingList) .To <ShoppingListServiceModel>() .ToList(); // Assert Assert.True(expectedResult.Count() == actualResult.Count(), errorMessagePrefix + " " + "Collections count mismatch."); for (int i = 0; i < actualResult.Count(); i++) { Assert.True(expectedResult[i].Id == actualResult[i].Id, errorMessagePrefix + " " + "ShoppingList is not returned properly."); } }
public async Task TestAddItemToOrderOrderedQuantityIsBiggerThenItemQuantity() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var orderRepository = new EfDeletableEntityRepository <Order>(new ApplicationDbContext(options.Options)); var itemsRepository = new EfRepository <Item>(new ApplicationDbContext(options.Options)); var orderItemRepository = new EfRepository <OrderItem>(new ApplicationDbContext(options.Options)); orderRepository.AddAsync(new Order { UserId = "1" }).GetAwaiter().GetResult(); orderRepository.SaveChangesAsync().GetAwaiter().GetResult(); itemsRepository.AddAsync(new Item { Name = "Pizza", Quantity = 5 }).GetAwaiter().GetResult(); itemsRepository.SaveChangesAsync().GetAwaiter().GetResult(); var orderService = new OrderService(itemsRepository, orderRepository, orderItemRepository); await orderService.AddItemToOrder(1, "1", 10); var orderItems = orderItemRepository.All().Where(x => x.ItemId == 1).FirstOrDefault(); Assert.Equal(5, orderItems.Quantity); }
public async Task PurchaseAccountAsync_WithCorrectData_ShouldSuccessfullyDelete() { var errorMessage = "ApprovedAccountsService PurchaseAccountAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var accountsRepository = new EfRepository <Account>(context); var approvedAccountsRepository = new EfRepository <ApprovedAccount>(context); var accountsService = new AccountsService(accountsRepository, approvedAccountsRepository); var approvedAccountsService = new ApprovedAccountsService(approvedAccountsRepository); var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = "******", }; var accountServiceModel = new SellAccountInputModel { ChampionsCount = 20, SkinsCount = 20, BlueEssence = 500, RiotPoints = 600, Username = "******", Password = "******", Region = Regions.EUNE, }; // Act await accountsService.CreateAsync(accountServiceModel, user); await accountsService.ApproveAccountAsync(accountServiceModel.Username); var approvedAccountsCount = approvedAccountsRepository.All().Count(); await approvedAccountsService.PurchaseAccountAsync(accountServiceModel.Region); var actualResult = approvedAccountsRepository.All().Count(); var expectedResult = approvedAccountsCount - 1; // Assert Assert.True(actualResult == expectedResult, errorMessage); }
public async Task AddProfilePictureByUrlOverwriteCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfRepository <ProfilePicture>(new ApplicationDbContext(options.Options)); var service = new ProfilePicturesService(repository); var url1 = "Resources\\test1.jpeg"; var userId = "123"; var url2 = "Resources\\test2.jpg"; await service.AddPictureAsync(url1, userId); var firstPictureId = repository.All().First().Id; await service.AddPictureAsync(url2, userId); Assert.Single(repository.All().Where(x => x.UserId == userId)); Assert.NotEqual(firstPictureId, repository.All().First().Id); }
public async Task FinishFirstOrderAsync_WithCorrectData_ShouldSuccessfullyDelete() { var errorMessage = "CoachingService FinishFirstOrderAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var coachOrdersRepository = new EfRepository <CoachOrder>(context); var userManager = this.GetUserManagerMock(); var coachingService = new CoachingService(userManager.Object, coachOrdersRepository); var buyerId = Guid.NewGuid().ToString(); var coach = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = "******", }; var coachOrderModel = new OrderInputModel { BuyerId = buyerId, CoachId = coach.Id, GameName = "want3d1337", Region = "EUW", DiscordTag = "1337#0000", Hours = 2, }; // Act await coachingService.AddAsync(coachOrderModel); var coachOrdersCount = coachOrdersRepository.All().Count(); await coachingService.FinishFirstOrderAsync(coach); var actualResult = coachOrdersRepository.All().Count(); var expectedResult = coachOrdersCount - 1; // Assert Assert.True(expectedResult == actualResult, errorMessage); }
public async Task CreateAsyncShouldSetPropertiesCorrectly() { ApplicationDbContext dbContext = this.GetNewDbContext(); Order order1 = dbContext.Orders.Add(new Order()).Entity; Order order2 = dbContext.Orders.Add(new Order()).Entity; await dbContext.SaveChangesAsync(); const string userId = "userId"; const string creditCompanyId = "ccId"; string[] orderIds = new string[] { order1.Id, order2.Id }; const decimal total = 100; const string creditCardNumber = "credit card"; const int months = 10; var contractRepository = new EfRepository <Contract>(dbContext); var orderRepository = new Mock <IRepository <Order> >(); var creditCompanyService = new Mock <ICreditCompanyService>(); var userService = new Mock <IUserService>(); orderRepository.Setup(or => or.All()) .Returns(new Order[] { order1, order2 }.AsQueryable); creditCompanyService.Setup(ccs => ccs.Exists(creditCompanyId)) .Returns(true); userService.Setup(us => us.ExistsAsync(userId)) .Returns(Task.FromResult(true)); IContractService contractService = new ContractService( contractRepository, orderRepository.Object, creditCompanyService.Object, userService.Object); string id = await contractService.CreateAsync( userId, creditCompanyId, orderIds, total, creditCardNumber, months); Contract contract = contractRepository.All() .Where(c => c.Id == id) .Include(c => c.Orders) .FirstOrDefault(); Assert.NotNull(contract); Assert.Equal(userId, contract.CustomerId); Assert.Equal(creditCompanyId, contract.CompanyId); Assert.True(orderIds.SequenceEqual <string>(contract.Orders.Select(o => o.Id))); Assert.Equal(creditCardNumber, contract.CreditCardNumber); Assert.Equal(total / months, contract.PricePerMonth); }
public async Task TestCalculateDiscountGiveCode() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var discountRepository = new EfRepository <Discount>(new ApplicationDbContext(options.Options)); var discountService = new DiscountService(discountRepository); var discountDeciaml = await discountService.CalculateDiscount(0.00M, 100.00M, "60e060b7-4e1e-4521-bd16-46434ddaa425"); Assert.True(discountRepository.All().Select(x => x.UserId == "60e060b7-4e1e-4521-bd16-46434ddaa425").FirstOrDefault()); }
public async Task SetVoteShouldChangeVoteValueCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var repository = new EfRepository <Vote>(dbContext); var clientRepository = new EfDeletableEntityRepository <Client>(dbContext); var client = new Client { Id = "clientId", Name = "random", Phone = "088", PositionPlayed = PositionName.Center, User = new ApplicationUser { Id = "clientuserId", Email = "*****@*****.**" }, UserId = "clientuserId", }; await dbContext.Clients.AddAsync(client); await dbContext.SaveChangesAsync(); var workoutslistRepository = new EfDeletableEntityRepository <WorkoutsList>(dbContext); var clientsService = new ClientsService(clientRepository, workoutslistRepository); var service = new VotesService(repository, clientsService); await service.SetVoteAsync("coachId", "clientuserId", 2); await service.SetVoteAsync("coachId", "clientuserId", 5); var count = repository.All(); var vote = await repository.All().FirstAsync(x => x.CoachId == "coachId"); Assert.Equal(1, await count.CountAsync()); Assert.Equal(5, vote.Value); }
public static void DeleteChilds(this IRepository<School> sc, int schoolId) { var studentsRepo = new EfRepository<Student>(new SchoolContext()); var studentsFromSchool = studentsRepo.All().Where(x => x.School.SchoolId == schoolId).ToList(); foreach (Student student in studentsFromSchool) { studentsRepo.DeleteChilds(student.School.SchoolId); studentsRepo.Delete(student.StudentId); } }