Beispiel #1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IRateService service = testServer.Host.Services.GetService(typeof(IRateService)) as IRateService;
            var          model   = new ApiRateServerRequestModel();

            model.SetProperties(2m, 1, 1);
            CreateResponse <ApiRateServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.RateDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiRateServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
        // POST api/Rates
        public IHttpActionResult Post([FromBody] RateVM value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <RateVM, KnowledgeRateDTO>()).CreateMapper();

            try
            {
                db.Create(mapper.Map <RateVM, KnowledgeRateDTO>(value));
                return(StatusCode(HttpStatusCode.Created));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Beispiel #3
0
 public RateResponseDto Post(int postId, [FromBody] RateRequestDto request)
 {
     return(_rateService.Create(postId, request));
 }