public async Task POST_Create_Prestation_Return_Error_Duration_Equal_Zero() { #region Arrange var dbContext = DbContextMocker.GetElegantGlamourDbContext(nameof(POST_Create_Prestation_Return_Error_Duration_Equal_Zero)); var config = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); }); var mapper = new Mapper(config); var mockUnitOfWork = new UnitOfWork(dbContext); var mockPrestationService = new PrestationService(mockUnitOfWork); var mockLogger = Mock.Of <ILogger <PrestationsController> >(); var controller = new PrestationsController(mockPrestationService, mapper, mockLogger); #endregion var addPrestation = new AddPrestationDto() { Title = "Test", Description = "Test", Duration = 0, PrestationCategoryId = 89, Price = 50 }; #region Act var apiException = await Assert.ThrowsAsync <ApiException>(() => controller.CreatePrestation(addPrestation)); dbContext.Dispose(); #endregion #region Assert Assert.Equal(400, apiException.StatusCode); Assert.Contains(ErrorMessage.Err_Prestation_Duration_Not_Equal_To_0, apiException.CustomError.ToString()); #endregion }
public async Task POST_Create_Prestation_Return_Ok() { #region Arrange var dbContext = DbContextMocker.GetElegantGlamourDbContext(nameof(POST_Create_Prestation_Return_Ok)); var config = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); }); var mapper = new Mapper(config); var mockUnitOfWork = new UnitOfWork(dbContext); var mockPrestationService = new PrestationService(mockUnitOfWork); var mockLogger = Mock.Of <ILogger <PrestationsController> >(); var controller = new PrestationsController(mockPrestationService, mapper, mockLogger); #endregion var addPrestation = new AddPrestationDto() { Title = "TEST_PRESTATION", Description = "Ceci est un test prestation", Price = 10, Duration = 60, PrestationCategoryId = 1 }; #region Act var response = await controller.CreatePrestation(addPrestation); dbContext.Dispose(); #endregion #region Assert Assert.IsType <ApiResponse>(response); Assert.Equal(201, response.StatusCode); #endregion }