public void GetAvgRatingTest() { try { DbLocation dbLocation = new DbLocation(); DbRating dbRating = new DbRating(); Location location = new Location { Latitude = 1, Longitude = 1, LocationName = "AVGTEST", LocationDescription = "AVGDescription" }; int id = dbLocation.Create(location); Rating rating1 = new Rating { LocationId = id, Rate = 1, Comment = "RateTest1" }; Rating rating2 = new Rating { LocationId = id, Rate = 5, Comment = "RateTest2" }; rating1.RatingId = dbRating.Create(rating1); rating2.RatingId = dbRating.Create(rating2); double rate = dbRating.GetAverageRating(id); Assert.IsTrue(rate == 3); dbRating.Delete(rating1); dbRating.Delete(rating2); dbLocation.Delete(id); } catch (FaultException <System.Exception> ) { Assert.Fail(); } }
public void CreateRatingTest() { DbRating dbRating = new DbRating(); try { Rating rating = new Rating { Rate = 4, Comment = "Hej", LocationId = 5, User = new User { UserId = 2 } }; int ratingId = dbRating.Create(rating); Assert.IsTrue(ratingId > 0); } catch (FaultException <DbConnectionException> ) { Assert.Fail(); } }
/// <summary> /// Create a rating in database /// </summary> /// <param name="rating">Rating</param> /// <returns>int</returns> public int CreateRating(Rating rating) { return(_dbRating.Create(rating)); }
public async Task CreateAsync(Rating rating) { await _context.Ratings.AddAsync(DbRating.Create(rating)); await _context.SaveChangesAsync(); }