public async Task CreateSupplierAsyncShouldCreateSupplierSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var suppliersService = new SuppliersService(dbContext, mapper); var supplierModel = new SupplierAdminCreateViewModel { Name = SupplierName, PriceToHome = SupplierPriceToHome, PriceToOffice = SupplierPriceToOffice, }; await suppliersService.CreateSupplierAsync(supplierModel); var actual = await dbContext.Suppliers.FirstOrDefaultAsync(); Assert.Equal(supplierModel.Name, actual.Name); }
public async Task AddRatingAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var commentsService = new CommentsService(dbContext, null, usersService); var comment = new Comment { Id = CommentId, Text = CommentText, }; await dbContext.Comments.AddAsync(comment); await dbContext.SaveChangesAsync(); var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await commentsService.AddRatingAsync(comment.Id)); Assert.IsType <NullReferenceException>(exception); }
public async Task EditSupplierAsyncShouldThrowExceptionIfSupplierIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var suppliersService = new SuppliersService(dbContext, mapper); var supplierModel = new SupplierAdminEditViewModel { Name = SupplierName, PriceToHome = SupplierPriceToHome, PriceToOffice = SupplierPriceToOffice, }; var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await suppliersService.EditSupplierAsync(supplierModel)); Assert.IsType <ArgumentNullException>(exception); }
public async Task CreateMembershipAsyncShouldCreateMembershipSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var membershipsService = new MembershipsService(dbContext, mapper); var membershipModel = new MembershipAdminCreateViewModel { Name = MembershipName, YearlyPrice = MembershipYearlyPrice, }; await membershipsService.CreateMembershipAsync(membershipModel); var actual = await dbContext.Memberships.FirstOrDefaultAsync(); Assert.Equal(membershipModel.YearlyPrice, actual.YearlyPrice); }
public async Task GetCategoryByProgramIdAsyncShouldThrowExceptionIfProgramCategoryIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var categoriesService = new CategoriesService(dbContext, null); var programCategory = new ProgramCategory { Id = CategoryId, Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(programCategory); await dbContext.SaveChangesAsync(); var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await categoriesService.GetCategoryByProgramIdAsync(CategoryNullId)); Assert.IsType <ArgumentNullException>(exception); }
public async Task GetMembershipPriceByIdAsyncShouldReturnZeroIfMembershipPriceIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var membershipsService = new MembershipsService(dbContext, mapper); var membership = new Membership { Id = MembershipId, Name = MembershipName, }; await dbContext.Memberships.AddAsync(membership); await dbContext.SaveChangesAsync(); var expected = await membershipsService.GetMembershipPriceByIdAsync(MembershipId); Assert.Equal(0, expected); }
public async Task GetMembershipByIdAsyncShouldThrowExceptionIfMembershipIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var membershipsService = new MembershipsService(dbContext, mapper); var membership = new Membership { Name = MembershipName, }; await dbContext.Memberships.AddAsync(membership); await dbContext.SaveChangesAsync(); var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await membershipsService.GetMembershipByIdAsync(MembershipId)); Assert.IsType <ArgumentNullException>(exception); }
public async Task GetUserToEditAsyncShouldReturnUserSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var usersService = new UsersService(httpContextAccessor, dbContext, mapper); var user = new ApplicationUser { Id = UserId, FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var expected = await usersService.GetUserToEditAsync(UserId); Assert.Equal(expected.Id, user.Id); }
public async Task EditAddressAsyncShouldThrowExceptionIfCityIsNull() { var option = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new MyCalisthenicAppDbContext(option); var addressService = new AddressesService(dbContext, null); var city = new City { Id = Guid.NewGuid().ToString(), Name = CityName, PostCode = CityPostCode, }; await dbContext.Cities.AddAsync(city); await dbContext.SaveChangesAsync(); var addressViewModel = new AddressAdminEditViewModel { CityId = Guid.NewGuid().ToString(), }; var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await addressService.EditAddressAsync(addressViewModel)); Assert.IsType <ArgumentNullException>(exception); }
public async Task GetSupplierByIdAsyncShouldReturnSupplierSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var suppliersService = new SuppliersService(dbContext, mapper); var supplier = new Supplier { Name = SupplierName, PriceToHome = SupplierPriceToHome, PriceToOffice = SupplierPriceToOffice, }; await dbContext.Suppliers.AddAsync(supplier); await dbContext.SaveChangesAsync(); var expected = await suppliersService.GetSupplierByIdAsync(supplier.Id); Assert.Equal(expected.Id, supplier.Id); }
public async Task GetExercisesByCategoryIdAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService); var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await exercisesService.GetExercisesByCategoryIdAsync(ProgramCategoryId)); Assert.IsType <NullReferenceException>(exception); }
public async Task CreateProgramAsyncShouldThrowExceptionIfCategoryIsIncorrect() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService); var programModel = new ProgramAdminCreateViewModel { Title = ProgramTitle, Description = ProgramDescription, Rating = ProgramRating, CategoryId = null, }; var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await programsService.CreateProgramAsync(programModel)); Assert.IsType <ArgumentNullException>(exception); }
public async Task CreateOrderAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var ordersService = new OrdersService(dbContext, mapper, usersService); var product = new Product { Name = ProductName, Price = ProductPrice, Description = ProductDescription, CategoryId = CategoryId, }; var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await ordersService.CreateOrderAsync(product)); Assert.IsType <NullReferenceException>(exception); }
public async Task GetOrderByIdAsyncShouldThrowExceptionIfOrderIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var ordersService = new OrdersService(dbContext, mapper, usersService); var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await ordersService.GetOrderByIdAsync(OrderId)); Assert.IsType <ArgumentNullException>(exception); }
public async Task CreateOrderAsyncShouldReturnFalseIfProductIsSoldOut() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var ordersService = new OrdersService(dbContext, mapper, usersService); var product = new Product { Name = ProductName, Price = ProductPrice, Description = ProductDescription, IsSoldOut = true, CategoryId = CategoryId, }; var expected = await ordersService.CreateOrderAsync(product); Assert.False(expected); }
public async Task GetProgramsBySearchTextAsyncShouldReturnNullIfTextIsLessThanFourSymbols() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var searchesService = new SearchesService(dbContext, mapper); var searchModel = new SearchViewModel { Text = InvalidSearchText, }; var expected = await searchesService.GetProgramsBySearchTextAsync(searchModel); Assert.Null(expected); }
public async Task UserSubscribeAsyncShouldSubscribeUserSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var usersService = new UsersService(httpContextAccessor, dbContext, mapper); var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); await usersService.UserSubscribeAsync(user); var actual = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == user.Id); Assert.True(actual.HasSubscribe); }
public async Task GetCommentsByProductIdAsyncShouldThrowExceptionIfNoSuchProductId() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var commentsService = new CommentsService(dbContext, mapper, usersService); var expected = await commentsService.GetCommentsByProductIdAsync(ProductId); var counter = 0; foreach (var comment in expected) { counter++; } Assert.Equal(0, counter); }
public async Task CreateCommentAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var commentsService = new CommentsService(dbContext, mapper, usersService); var commentModel = new CommentInputViewModel { Text = CommentText, }; var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await commentsService.CreateCommentAsync(PostId, commentModel)); Assert.IsType <NullReferenceException>(exception); }
public async Task EditExerciseAsyncShouldEditExerciseSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService); var programCategory = new ProgramCategory { Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(programCategory); await dbContext.SaveChangesAsync(); var exrecise = new Exercise { Id = ExerciseId, Name = ExerciseName, Description = ExerciseDescription, VideoUrl = ExerciseVideoUrl, ProgramCategoryId = programCategory.Id, }; await dbContext.Exercises.AddAsync(exrecise); await dbContext.SaveChangesAsync(); var exerciseModel = new ExerciseAdminEditViewModel { Id = ExerciseId, Name = ExerciseName, Description = ExerciseEditDescription, VideoUrl = ExerciseVideoUrl, ProgramCategoryId = programCategory.Id, }; await exercisesService.EditExerciseAsync(exerciseModel); Assert.Equal(exrecise.Description, exerciseModel.Description); }
public async Task GetAllAddressesByUserIdAsyncShouldReturnAddressesSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var usersService = new UsersService(httpContextAccessor, dbContext, mapper); var user = new ApplicationUser { Id = UserId, FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var city = new City { Name = CityName, PostCode = CityPostCode, }; await dbContext.Cities.AddAsync(city); await dbContext.SaveChangesAsync(); for (int i = 0; i < 3; i++) { var address = new Address { Country = AddressCountry, Street = AddressStreet, CityId = city.Id, UserId = user.Id, }; await dbContext.Addresses.AddAsync(address); await dbContext.SaveChangesAsync(); } var expected = await usersService.GetAllAddressesByUserIdAsync(UserId); Assert.Equal(3, expected.Count); }
public async Task GetAllProgramsAsyncShouldReturnProgramsSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService); var category = new ProgramCategory { Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(category); await dbContext.SaveChangesAsync(); for (int i = 0; i < 3; i++) { var program = new Program { Title = ProgramTitle, Description = ProgramDescription, CategoryId = category.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); } var expected = await programsService.GetAllProgramsAsync(); var counter = 0; foreach (var program in expected) { counter++; } Assert.Equal(3, counter); }
public OrdersService( MyCalisthenicAppDbContext dbContext, IMapper mapper, IUsersService usersService) { this.dbContext = dbContext; this.mapper = mapper; this.usersService = usersService; }
public UsersService( IHttpContextAccessor httpContextAccessor, MyCalisthenicAppDbContext dbContext, IMapper mapper) { this.httpContextAccessor = httpContextAccessor; this.dbContext = dbContext; this.mapper = mapper; }
public async Task EditAddressAsyncShouldThrowExceptionIfCityIdDoesNotExists() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var addressService = new AddressesService(dbContext, null); var city = new City { Id = Guid.NewGuid().ToString(), Name = CityName, PostCode = CityPostCode, }; await dbContext.Cities.AddAsync(city); await dbContext.SaveChangesAsync(); var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var address = new Address { Country = AddressCountryName, Street = AddressStreet, CityId = city.Id, UserId = user.Id, }; await dbContext.Addresses.AddAsync(address); await dbContext.SaveChangesAsync(); var addressViewModel = new AddressAdminEditViewModel { Id = address.Id, CityId = CityId, Country = AddressEditCountryName, UserId = user.Id, }; var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await addressService.EditAddressAsync(addressViewModel)); Assert.IsType <ArgumentNullException>(exception); }
public async Task GetProgramsBySearchTextAsyncShouldReturnNullIfNoSuchPrograms() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var searchesService = new SearchesService(dbContext, mapper); var category = new ProgramCategory { Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(category); await dbContext.SaveChangesAsync(); for (int i = 0; i < 3; i++) { var program = new Program { Title = ProgramTitle, Description = ProgramDescription, CategoryId = category.Id, }; program.Images.Add(new Image { Url = ImageUrl, }); await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); } var searchModel = new SearchViewModel { Text = SearchText, }; var expected = await searchesService.GetProgramsBySearchTextAsync(searchModel); Assert.Null(expected); }
public async Task GetImagesByProductIdAsyncShouldReturnImagesSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var categoriesService = new CategoriesService(dbContext, mapper); var postsService = new PostsService(dbContext, mapper, usersService, categoriesService); var productsService = new ProductsService(dbContext, mapper, usersService, categoriesService); var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService); var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService); var imagesService = new ImagesService(dbContext, mapper, postsService, exercisesService, productsService, programsService); for (int i = 0; i < 4; i++) { var image = new Image { Url = ImageUrl, ProductId = ProductId, }; await dbContext.Images.AddAsync(image); await dbContext.SaveChangesAsync(); } var expected = await imagesService.GetImagesByProductIdAsync(ProductId); var counter = 0; foreach (var img in expected) { counter++; } Assert.Equal(4, counter); }
public async Task EditAddressAsyncShouldEditAddressSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var addressService = new AddressesService(dbContext, null); var city = new City { Id = Guid.NewGuid().ToString(), Name = CityName, PostCode = CityPostCode, }; await dbContext.Cities.AddAsync(city); await dbContext.SaveChangesAsync(); var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var address = new Address { Country = AddressCountryName, Street = AddressStreet, CityId = city.Id, UserId = user.Id, }; await dbContext.Addresses.AddAsync(address); await dbContext.SaveChangesAsync(); var addressViewModel = new AddressAdminEditViewModel { Id = address.Id, CityId = city.Id, Country = AddressEditCountryName, UserId = user.Id, }; await addressService.EditAddressAsync(addressViewModel); Assert.Equal(address.Country, addressViewModel.Country); }
public ProductsService( MyCalisthenicAppDbContext dbContext, IMapper mapper, IUsersService usersService, ICategoriesService categoriesService) { this.dbContext = dbContext; this.mapper = mapper; this.usersService = usersService; this.categoriesService = categoriesService; }
public async Task EditCommentAsyncShouldEditCommentSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var usersService = new UsersService(httpContextAccessor, dbContext, null); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var commentsService = new CommentsService(dbContext, mapper, usersService); var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var comment = new Comment { Id = CommentId, Text = CommentText, AuthorId = user.Id, }; await dbContext.Comments.AddAsync(comment); await dbContext.SaveChangesAsync(); var commentModel = new CommentAdminEditViewModel { Id = CommentId, Text = CommentText, AuthorId = user.Id, Rating = CommentRating, }; await commentsService.EditCommentAsync(commentModel); Assert.Equal(comment.Rating, commentModel.Rating); }