public async Task Post_Success(int rateValue, string comment) { // Arrange var dbContext = _fixture.Context; var mapper = MapperMock.Get(); var user = NewDatas.NewUser(); var product = NewDatas.NewProduct(); var rating = NewDatas.NewRating(); rating.User = user; rating.Product = product; dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); dbContext.Users.Add(user); await dbContext.SaveChangesAsync(); dbContext.Ratings.Add(rating); await dbContext.SaveChangesAsync(); var ratingsService = new RatingService(dbContext); var ratingsController = new RatingsController(ratingsService, mapper); // Act var result = await ratingsController.PostRating(user.Id, product.productId, rateValue, comment); // Assert var ratingResult = Assert.IsType <CreatedAtActionResult>(result.Result); Assert.NotNull(ratingResult.Value as Rating); }
public void TestMethodGetSave() { var controller = new RatingsController(new TestBankDBContext()); var item = GetSingleItem(); var result = controller.PostRating(item) as CreatedAtRouteNegotiatedContentResult <Rating>; Assert.IsNotNull(result); Assert.AreEqual(result.RouteName, "DefaultApi"); Assert.AreEqual(result.RouteValues["id"], result.Content.Id); Assert.AreEqual(result.Content.Description, item.Description); }
public void AddNotExistingRating_ReturnNoContent() { var options = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "AddRatingsDataBase") .Options; var context = new DataContext(options); RatingsController ratingsController = new RatingsController(context); string jwt = UserManagementMicroservice.JWT.CreateJWT(2, 1); var result = ratingsController.PostRating(new RequestRating() { MovieId = 1, Score = 4 }, jwt); Assert.IsType <NoContentResult>(result); }