public void ProgramItemSortComparison() { Directory.CreateDirectory("Empty"); StartMenu s = new StartMenu("Empty"); ProgramCategory cat = new ProgramCategory(s); var l = new List <ProgramItem> { new ProgramItem(cat, "Z.lnk"), new ProgramItem(cat, "2.lnk"), new ProgramItem(cat, "B.lnk"), new ProgramItem(cat, "1.lnk"), new ProgramItem(cat, "A.lnk"), }; var lSorted = new List <ProgramItem> { new ProgramItem(cat, "1.lnk"), new ProgramItem(cat, "2.lnk"), new ProgramItem(cat, "A.lnk"), new ProgramItem(cat, "B.lnk"), new ProgramItem(cat, "Z.lnk"), }; Assert.IsFalse(l.SequenceEqual(lSorted)); l.Sort(); Assert.IsTrue(l.SequenceEqual(lSorted)); }
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 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 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 MoveProgramItemCommand(ProgramItem programItem, ProgramCategory newCategory, string matchedSelector) { this.ProgramItem = programItem; this.OldCategory = programItem.Category; this.NewCategory = newCategory; this.Name = string.Format("Move '{0}' to '{1}' because of '{2}'", Path.GetFileName(programItem.Name), newCategory.Name, matchedSelector); oldPaths = new List <string>(ProgramItem.Locations); }
public MoveProgramItemCommand(ProgramItem programItem, ProgramCategory newCategory, string matchedSelector) { this.ProgramItem = programItem; this.OldCategory = programItem.Category; this.NewCategory = newCategory; this.Name = string.Format("Move '{0}' to '{1}' because of '{2}'", Path.GetFileName(programItem.Name), newCategory.Name, matchedSelector); oldPaths = new List<string>(ProgramItem.Locations); }
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 void ProgramItemEquality() { Directory.CreateDirectory("Empty"); StartMenu s = new StartMenu("Empty"); ProgramCategory cat = new ProgramCategory(s); ProgramItem a = new ProgramItem(cat, "Hello.lnk"); ProgramItem b = new ProgramItem(cat, "Hello.lnk"); Assert.IsTrue(a == b, "Equality operator failed"); Assert.AreEqual(true, a.Equals(b), "Explicit call to IEquatable<T> method failed"); Assert.AreEqual(a, b, "Generic Assert.AreEqual call failed"); }
public async Task CreateProgramCategoryAsync(ProgramCategoryAdminCreateViewModel inputModel) { var programCategory = new ProgramCategory { Name = inputModel.Name, Description = inputModel.Description, }; await this.dbContext.ProgramCategories.AddAsync(programCategory); await this.dbContext.SaveChangesAsync(); }
public async Task GetAllExercisesForAdminAsyncShouldReturnAllExercises() { 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(); for (int i = 0; i < 4; i++) { var exrecise = new Exercise { Name = ExerciseName, Description = ExerciseDescription, VideoUrl = ExerciseVideoUrl, ProgramCategoryId = programCategory.Id, }; await dbContext.Exercises.AddAsync(exrecise); await dbContext.SaveChangesAsync(); } var expected = await exercisesService.GetAllExercisesForAdminAsync(); Assert.Equal(4, expected.Count); }
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 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(); var program = new Program { Id = ProgramId, Title = ProgramTitle, Description = ProgramDescription, CategoryId = category.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await programsService.AddRatingAsync(ProgramId)); Assert.IsType <NullReferenceException>(exception); }
public async Task GetProgramByIdShouldReturnTrueIfProgramExists() { 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(); var program = new Program { Id = ProgramId, Title = ProgramTitle, Description = ProgramDescription, CategoryId = category.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); var result = programsService.GetProgramById(ProgramId); Assert.True(result); }
/// <summary> /// Initializes a new instance of the <see cref="ProgramCharacteristics"/> class. /// </summary> /// <param name="ageGroup">The age group.</param> /// <param name="genderSpecification">The gender specification.</param> /// <param name="treatmentApproach">The treatment approach.</param> /// <param name="programCategory">The program category.</param> public ProgramCharacteristics(AgeGroup ageGroup, GenderSpecification genderSpecification, TreatmentApproach treatmentApproach, ProgramCategory programCategory) : this() { Check.IsNotNull(ageGroup, "Age Group is required."); Check.IsNotNull(genderSpecification, "Gender Specification is required."); Check.IsNotNull(treatmentApproach, "Treatment Approach is required."); Check.IsNotNull(programCategory, "Program Category is required."); _ageGroup = ageGroup; _genderSpecification = genderSpecification; _treatmentApproach = treatmentApproach; _programCategory = programCategory; }
public async Task CreateProgramAsyncShouldCreateProgramSuccessfully() { 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(); var programModel = new ProgramAdminCreateViewModel { Title = ProgramTitle, Description = ProgramDescription, Rating = ProgramRating, CategoryId = category.Id, }; await programsService.CreateProgramAsync(programModel); var actual = await dbContext.Programs.FirstOrDefaultAsync(); Assert.Equal(programModel.Title, actual.Title); }
public async Task CreateExerciseAsyncShouldThrowExptionIfProgramCategoryIsNull() { 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 exerciseModel = new ExerciseAdminCreateViewModel { Name = ExerciseName, Description = ExerciseDescription, VideoUrl = ExerciseVideoUrl, ProgramCategoryId = ProgramCategoryId, }; var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await exercisesService.CreateExerciseAsync(exerciseModel)); Assert.IsType <ArgumentNullException>(exception); }
public async Task GetCategoryByProgramIdAsyncShouldReturnCategoryByProgramIdSuccessfully() { 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 categoriesService = new CategoriesService(dbContext, mapper); var programCategory = new ProgramCategory { Id = CategoryId, Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(programCategory); await dbContext.SaveChangesAsync(); var program = new Program { Title = ProgramTitle, Description = ProgramDescription, CategoryId = programCategory.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); var expected = await categoriesService.GetCategoryByProgramIdAsync(program.Id); Assert.Equal(expected.Id, programCategory.Id); }
public async Task GetAllCommentsByUserIdAsyncShouldReturnCommentsSuccessfully() { 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 postCategory = new BlogCategory { Name = PostCategoryName, }; await dbContext.BlogCategories.AddAsync(postCategory); await dbContext.SaveChangesAsync(); var post = new Post { Title = PostTitle, Description = PostDescription, CategoryId = postCategory.Id, }; await dbContext.Post.AddAsync(post); await dbContext.SaveChangesAsync(); var productCategory = new ProductCategory { Name = ProductCategoryName, }; await dbContext.ProductCategories.AddAsync(productCategory); await dbContext.SaveChangesAsync(); var product = new Product { Name = ProductName, Description = ProductDescription, CategoryId = productCategory.Id, }; await dbContext.Products.AddAsync(product); await dbContext.SaveChangesAsync(); var programCategory = new ProgramCategory { Name = ProgramCategoryName, Description = ProgramDescription, }; await dbContext.ProgramCategories.AddAsync(programCategory); await dbContext.SaveChangesAsync(); var program = new Program { Title = ProgramTitle, Description = ProgramDescription, CategoryId = productCategory.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); var user = new ApplicationUser { Id = UserId, FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); for (int i = 0; i < 3; i++) { var comment = new Comment { Text = CommentText, Author = user, Post = post, Product = product, Program = program, }; await dbContext.Comments.AddAsync(comment); await dbContext.SaveChangesAsync(); } var expected = await usersService.GetAllCommentsByUserIdAsync(UserId); Assert.Equal(3, expected.Count); }
public void TestCreateGetParticipantExchangeVisitorsDTOQuery_CheckProperties() { var project = new Project { ProjectId = 100 }; var participant = new Participant { ParticipantId = 2, ProjectId = project.ProjectId, Project = project }; var fieldOfStudy = new FieldOfStudy { FieldOfStudyId = 3, Description = "field of study", }; var programCategory = new ProgramCategory { ProgramCategoryId = 3, Description = "program category", ProgramCategoryCode = "pccode" }; var position = new Position { PositionId = 4, Description = "position", PositionCode = "positioncode" }; var usGovAgency1 = new USGovernmentAgency { AgencyCode = "usgovcode1", AgencyId = 5, Description = "us gov agency1", }; var usGovAgency2 = new USGovernmentAgency { AgencyCode = "usgovcode2", AgencyId = 6, Description = "us gov agency2", }; var internationalOrg1 = new InternationalOrganization { Description = "int org 1", OrganizationCode = "int org 1 code", OrganizationId = 7, }; var internationalOrg2 = new InternationalOrganization { Description = "int org 2", OrganizationCode = "int org 2 code", OrganizationId = 8, }; var visitor = new ParticipantExchangeVisitor { ParticipantId = participant.ParticipantId, Participant = participant, FieldOfStudy = fieldOfStudy, FieldOfStudyId = fieldOfStudy.FieldOfStudyId, FundingGovtAgency1 = 2.0m, FundingGovtAgency2 = 3.0m, FundingIntlOrg1 = 4.0m, FundingIntlOrg2 = 5.0m, FundingOther = 6.0m, FundingPersonal = 7.0m, FundingSponsor = 8.0m, FundingTotal = 9.0m, FundingVisBNC = 10.0m, FundingVisGovt = 11.0m, GovtAgency1 = usGovAgency1, GovtAgency1Id = usGovAgency1.AgencyId, GovtAgency1OtherName = "other name", GovtAgency2 = usGovAgency2, GovtAgency2Id = usGovAgency2.AgencyId, GovtAgency2OtherName = "other other name", IntlOrg1 = internationalOrg1, IntlOrg1Id = internationalOrg1.OrganizationId, IntlOrg1OtherName = "other other other name", IntlOrg2 = internationalOrg2, IntlOrg2Id = internationalOrg2.OrganizationId, IntlOrg2OtherName = "other name 2", OtherName = "other name again", ProgramCategory = programCategory, ProgramCategoryId = programCategory.ProgramCategoryId, Position = position, PositionId = position.PositionId }; context.Projects.Add(project); context.Participants.Add(participant); context.FieldOfStudies.Add(fieldOfStudy); context.ProgramCategories.Add(programCategory); context.Positions.Add(position); context.ParticipantExchangeVisitors.Add(visitor); context.USGovernmentAgencies.Add(usGovAgency1); context.USGovernmentAgencies.Add(usGovAgency2); context.InternationalOrganizations.Add(internationalOrg1); context.InternationalOrganizations.Add(internationalOrg2); Action <ParticipantExchangeVisitorDTO> tester = (result) => { Assert.AreEqual(project.ProjectId, result.ProjectId); Assert.AreEqual(participant.ParticipantId, result.ParticipantId); Assert.AreEqual(visitor.FundingGovtAgency1, result.FundingGovtAgency1); Assert.AreEqual(visitor.FundingGovtAgency2, result.FundingGovtAgency2); Assert.AreEqual(visitor.FundingIntlOrg1, result.FundingIntlOrg1); Assert.AreEqual(visitor.FundingIntlOrg2, result.FundingIntlOrg2); Assert.AreEqual(visitor.FundingOther, result.FundingOther); Assert.AreEqual(visitor.FundingPersonal, result.FundingPersonal); Assert.AreEqual(visitor.FundingSponsor, result.FundingSponsor); Assert.AreEqual(visitor.FundingTotal, result.FundingTotal); Assert.AreEqual(visitor.FundingVisBNC, result.FundingVisBNC); Assert.AreEqual(visitor.FundingVisGovt, result.FundingVisGovt); Assert.AreEqual(visitor.GovtAgency1OtherName, result.GovtAgency1OtherName); Assert.AreEqual(visitor.GovtAgency2OtherName, result.GovtAgency2OtherName); Assert.AreEqual(visitor.IntlOrg1OtherName, result.IntlOrg1OtherName); Assert.AreEqual(visitor.IntlOrg2OtherName, result.IntlOrg2OtherName); Assert.AreEqual(visitor.OtherName, result.OtherName); Assert.AreEqual(visitor.FieldOfStudyId, result.FieldOfStudyId); Assert.AreEqual(fieldOfStudy.Description, result.FieldOfStudy); Assert.AreEqual(visitor.GovtAgency1Id, result.GovtAgency1Id); Assert.AreEqual(usGovAgency1.Description, result.GovtAgency1Name); Assert.AreEqual(visitor.GovtAgency2Id, result.GovtAgency2Id); Assert.AreEqual(usGovAgency2.Description, result.GovtAgency2Name); Assert.AreEqual(visitor.ProgramCategoryId, result.ProgramCategoryId); Assert.AreEqual(programCategory.Description, result.ProgramCategory); Assert.AreEqual(programCategory.ProgramCategoryCode, result.ProgramCategoryCode); Assert.AreEqual(visitor.IntlOrg1Id, result.IntlOrg1Id); Assert.AreEqual(internationalOrg1.Description, result.IntlOrg1Name); Assert.AreEqual(visitor.IntlOrg2Id, result.IntlOrg2Id); Assert.AreEqual(internationalOrg2.Description, result.IntlOrg2Name); Assert.AreEqual(visitor.PositionId, result.PositionId); Assert.AreEqual(visitor.Position.Description, result.Position); Assert.AreEqual(position.PositionCode, result.PositionCode); }; var queryResult = ParticipantExchangeVisitorQueries.CreateGetParticipantExchangeVisitorsDTOQuery(context).ToList(); Assert.AreEqual(1, queryResult.Count()); tester(queryResult.First()); }
public void ProgramItemSortComparison() { Directory.CreateDirectory("Empty"); StartMenu s = new StartMenu("Empty"); ProgramCategory cat = new ProgramCategory(s); var l = new List<ProgramItem> { new ProgramItem(cat, "Z.lnk"), new ProgramItem(cat, "2.lnk"), new ProgramItem(cat, "B.lnk"), new ProgramItem(cat, "1.lnk"), new ProgramItem(cat, "A.lnk"), }; var lSorted = new List<ProgramItem> { new ProgramItem(cat, "1.lnk"), new ProgramItem(cat, "2.lnk"), new ProgramItem(cat, "A.lnk"), new ProgramItem(cat, "B.lnk"), new ProgramItem(cat, "Z.lnk"), }; Assert.IsFalse(l.SequenceEqual(lSorted)); l.Sort(); Assert.IsTrue(l.SequenceEqual(lSorted)); }
public async Task GetCommentsByProgramIdAsyncShouldReturnCommentsSuccessfully() { 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 programCategory = new ProgramCategory { Name = CategoryName, Description = CategoryDescription, }; await dbContext.ProgramCategories.AddAsync(programCategory); await dbContext.SaveChangesAsync(); var program = new Program { Title = ProgramTitle, Description = ProgramDescription, CategoryId = programCategory.Id, }; await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var comment = new Comment { Text = CommentText, AuthorId = user.Id, ProgramId = program.Id, }; await dbContext.Comments.AddAsync(comment); await dbContext.SaveChangesAsync(); var expected = await commentsService.GetCommentsByProgramIdAsync(program.Id); var counter = 0; foreach (var comm in expected) { counter++; } Assert.Equal(1, counter); }
public async Task GetProgramDetailsByIdAsyncShouldReturnProgramSuccessfully() { 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, }; program.Images.Add(new Image { Url = ImageUrl, }); program.Comments.Add(new Comment { Text = CommentText, }); await dbContext.Programs.AddAsync(program); await dbContext.SaveChangesAsync(); } var programToReturn = new Program { Id = ProgramId, Title = ProgramTitle, Description = ProgramDescription, CategoryId = category.Id, }; await dbContext.Programs.AddAsync(programToReturn); await dbContext.SaveChangesAsync(); var expected = await programsService.GetProgramDetailsByIdAsync(ProgramId); Assert.Equal(expected.Id, programToReturn.Id); }