public void GetUserRatingTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_UserRating_from_database") .Options; var user = new UserProfile { Id = "userId" }; var rating = new Rating { Id = "agencyId" }; var agency = new AgencyProfile { Id = "agencyId", RatingId = rating.Id }; var expectedRating = new UserRating { RatingId = rating.Id, UserProfileId = user.Id }; UserRating actualRating; using (var db = new ApplicationDbContext(options)) { db.UsersRatings.Add(expectedRating); db.AgenciesProfiles.Add(agency); db.Ratings.Add(rating); db.UsersProfiles.Add(user); db.SaveChanges(); IProfileService service = new ProfileService(db); actualRating = service.GetUserRating(agency.Id); } Assert.Equal(expectedRating.RatingId, actualRating.RatingId); }
public void CreateAppointmentTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Create_Appointment") .Options; var appointment = new Appointment { Id = 1 }; var user = new UserProfile { Id = "userId" }; var agency = new AgencyProfile { Id = "agencyId" }; var ad = new Ad { Id = 2 }; var date = DateTime.UtcNow; int count; using (var db = new ApplicationDbContext(options)) { AppointmentService service = new AppointmentService(db); service.Create(ad, user, agency, date); count = db.Appointments.Count(); } Assert.Equal(1, count); }
public async Task CreateAdTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Create_Ad") .Options; IEnumerable <string> imgP = new List <string> { "aaaaa", "bbbbbb" }; var user = new AgencyProfile { Id = "agencyId", Username = "******" }; int count; using (var db = new ApplicationDbContext(options)) { db.AgenciesProfiles.Add(user); db.SaveChanges(); AdService service = new AdService(db); await service.CreateAd("Name", "Titleeeeeeeeeeeeee", "Description", imgP, "Residental", "65", "Location", "20", "A"); count = db.Ads.Count(); } Assert.Equal(1, count); }
public async Task CreateAgency(string username, string description, string name, string email, string address, string phoneNumber, string password) { var rating = new Rating(); var agencyProfile = new AgencyProfile { Username = username, Address = address, PhoneNumber = phoneNumber, Rating = rating, Name = name, Description = description, }; var account = new Account { AgencyProfileId = agencyProfile.Id, AgencyProfile = agencyProfile, UserName = username, Email = email, }; var result = await userManager.CreateAsync(account, password); if (result.Succeeded) { await CreateRole(GlobalConstants.agencyRoleName, account); agencyProfile.AccountId = account.Id; agencyProfile.Account = account; await db.SaveChangesAsync(); } }
public async Task Edit() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Edit_Ad") .Options; var user = new AgencyProfile { Id = "agencyId", Username = "******" }; var ad = new Ad { Id = 1, Title = "AAAAAAAA" }; var adTitle = ad.Title; int count; using (var db = new ApplicationDbContext(options)) { db.AgenciesProfiles.Add(user); db.Ads.Add(ad); db.SaveChanges(); AdService service = new AdService(db); await service.EditAd(1, "Titleeeeeeeeeeeeee", "Description", "Residental", "65", "Location", "20", "A"); count = db.Ads.Count(); } Assert.NotEqual(adTitle, ad.Title); }
public void Handle_SameLegalName_NoAliasAdded() { AgencyName agencyName = new AgencyName("TestAgencyName", "DisplayName", "BusinessName"); AgencyProfile agencyProfile = new AgencyProfile( new Mock <AgencyType> ().Object, agencyName, new DateRange(DateTime.Now.AddDays(-1), DateTime.Now), "url", new Mock <GeographicalRegion> ().Object, "note"); var aliasAdded = false; var agencyMock = new Mock <Agency>(); agencyMock.SetupGet(p => p.AgencyProfile).Returns(agencyProfile); agencyMock.Setup(a => a.AddAgencyAlias(It.IsAny <AgencyAlias>())).Callback(() => aliasAdded = true); var agencyProfileChangedEvent = new Mock <AgencyProfileChangedEvent>(); agencyProfileChangedEvent.SetupGet(p => p.Agency).Returns(agencyMock.Object); agencyProfileChangedEvent.SetupGet(p => p.OldAgencyProfile).Returns(agencyProfile); new AgencyProfileChangedEventHandler().Handle(agencyProfileChangedEvent.Object); Assert.IsFalse(aliasAdded); }
public void Handle_SameLegalName_NoAliasAdded() { AgencyName agencyName = new AgencyName("TestAgencyName", "DisplayName", "BusinessName"); AgencyProfile agencyProfile = new AgencyProfile ( new Mock<AgencyType> ().Object, agencyName, new DateRange ( DateTime.Now.AddDays ( -1 ), DateTime.Now ), "url", new Mock<GeographicalRegion> ().Object, "note" ); var aliasAdded = false; var agencyMock = new Mock<Agency>(); agencyMock.SetupGet(p => p.AgencyProfile).Returns(agencyProfile); agencyMock.Setup(a => a.AddAgencyAlias(It.IsAny<AgencyAlias>())).Callback(() => aliasAdded = true); var agencyProfileChangedEvent = new Mock<AgencyProfileChangedEvent>(); agencyProfileChangedEvent.SetupGet(p => p.Agency).Returns(agencyMock.Object); agencyProfileChangedEvent.SetupGet(p => p.OldAgencyProfile).Returns(agencyProfile); new AgencyProfileChangedEventHandler().Handle(agencyProfileChangedEvent.Object); Assert.IsFalse(aliasAdded); }
/// <summary> /// Creates the agency. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> /// <returns> /// An Agency. /// </returns> public Agency CreateAgency(AgencyProfile agencyProfile) { Check.IsNotNull(agencyProfile, "agencyProfile is required."); Agency agency = new AgencyBuilder().WithAgencyProfile(agencyProfile); _agencyRepository.MakePersistent(agency); return agency; }
public void Create(Ad ad, UserProfile userProfile, AgencyProfile agencyProfile, DateTime date) { Appointment appointment = new Appointment { AdId = ad.Id, Date = date, UserProfileId = userProfile.Id, AgencyProfileId = agencyProfile.Id, }; this.db.Appointments.Add(appointment); this.db.SaveChanges(); }
public void GetMyAppointmentTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_Appointment") .Options; var user = new UserProfile { Id = "userId" }; var ad = new Ad { Id = 2 }; var appointment = new Appointment { Id = 1, AgencyProfileId = "agencyId", AdId = ad.Id, UserProfileId = user.Id, }; var agency = new AgencyProfile { Id = "agencyId", Username = "******", }; agency.Appointments.Add(appointment); agency.Ads.Add(ad); List <Appointment> apps; using (var db = new ApplicationDbContext(options)) { db.Appointments.Add(appointment); db.AgenciesProfiles.Add(agency); db.SaveChanges(); AppointmentService service = new AppointmentService(db); apps = service.GetMyAppointments(agency.Username).ToList(); } Assert.Single(apps); }
public void Rate(UserProfile userProfile, AgencyProfile agencyProfile, decimal rateDigit) { agencyProfile.Rating.RatingSum += rateDigit; agencyProfile.Rating.CountOfVotes++; agencyProfile.Rating.AverageRating = agencyProfile.Rating.RatingSum / agencyProfile.Rating.CountOfVotes; var userRating = new UserRating { UserProfile = userProfile, UserProfileId = userProfile.Id, RatingId = agencyProfile.Rating.Id, Rating = agencyProfile.Rating, }; userProfile.Ratings.Add(userRating); agencyProfile.Rating.VotedUsers.Add(userRating); db.SaveChanges(); }
public void GetAgencyByIdTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_AgencyById_from_database") .Options; var agency = new AgencyProfile { Id = "agencyId", Username = "******" }; AgencyProfile expectedAgency; using (var db = new ApplicationDbContext(options)) { db.AgenciesProfiles.Add(agency); db.SaveChanges(); IProfileService service = new ProfileService(db); expectedAgency = service.GetAgencyById(agency.Id); } Assert.Equal(agency.Username, expectedAgency.Username); }
public void RateTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Rate_Agency") .Options; var userProfile = new UserProfile(); var profile = new AgencyProfile { Rating = new Rating { AverageRating = 0, RatingSum = 0, CountOfVotes = 0, } }; int countOfUsersRatings; using (var db = new ApplicationDbContext(options)) { db.AgenciesProfiles.Add(profile); db.UsersProfiles.Add(userProfile); db.SaveChanges(); IProfileService service = new ProfileService(db); service.Rate(userProfile, profile, 4); countOfUsersRatings = db.UsersRatings.Count(); } Assert.Equal(1, profile.Rating.CountOfVotes); Assert.Equal(4, profile.Rating.AverageRating); Assert.Equal(4, profile.Rating.RatingSum); Assert.Equal(1, countOfUsersRatings); }
public void GetAgenciesShouldReturnAgenciesCountNotNull() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_Agencies_from_database") .Options; var agency = new AgencyProfile { Id = "agencyId" }; int count; using (var db = new ApplicationDbContext(options)) { db.AgenciesProfiles.Add(agency); db.SaveChanges(); IProfileService service = new ProfileService(db); List <AgencyProfile> agencies = service.GetAgencies().ToList(); count = agencies.Count(); } Assert.Equal(1, count); }
/// <summary> /// Assigns the agency profile. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> /// <returns> /// An AgencyBuilder. /// </returns> public AgencyBuilder WithAgencyProfile(AgencyProfile agencyProfile) { this._agencyProfile = agencyProfile; return this; }
/// <summary> /// Initializes a new instance of the <see cref="Agency"/> class. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> /// <param name="parentAgency"> /// The parent agency. /// </param> protected internal Agency( AgencyProfile agencyProfile, Agency parentAgency ) : this() { Check.IsNotNull ( agencyProfile, () => AgencyProfile ); _agencyProfile = agencyProfile; _parentAgency = parentAgency; }
/// <summary> /// Assigns the agency profile. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> /// <returns> /// An AgencyBuilder. /// </returns> public AgencyBuilder WithAgencyProfile(AgencyProfile agencyProfile) { this._agencyProfile = agencyProfile; return(this); }
/// <summary> /// Creates the child agency. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> /// <param name="parentAgency"> /// The parent agency. /// </param> /// <returns> /// An Agency. /// </returns> public Agency CreateChildAgency(AgencyProfile agencyProfile, Agency parentAgency) { Check.IsNotNull(agencyProfile, "agencyProfile is required."); Check.IsNotNull(parentAgency, "parentAgency is required."); Agency agency = new AgencyBuilder().WithAgencyProfile(agencyProfile).WithPatentAgency(parentAgency); _agencyRepository.MakePersistent(agency); return agency; }
/// <summary> /// Revises the agency profile. /// </summary> /// <param name="agencyProfile"> /// The agency profile. /// </param> public virtual void ReviseAgencyProfile( AgencyProfile agencyProfile ) { Check.IsNotNull ( agencyProfile, () => AgencyProfile ); if ( AgencyProfile == agencyProfile ) { return; } AgencyProfile oldAgencyProfile = AgencyProfile; AgencyProfile = agencyProfile; DomainEvent.Raise ( new AgencyProfileChangedEvent { Agency = this, OldAgencyProfile = oldAgencyProfile } ); }